aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore11
-rw-r--r--LICENSE6
-rw-r--r--Makefile364
-rw-r--r--README36
-rw-r--r--config.mk29
-rw-r--r--include/CVS/Entries93
-rw-r--r--include/CVS/Repository1
-rw-r--r--include/CVS/Root1
-rw-r--r--include/Makefile163
-rw-r--r--include/a.out.h44
-rw-r--r--include/ar.h66
-rw-r--r--include/arpa/CVS/Entries6
-rw-r--r--include/arpa/CVS/Repository1
-rw-r--r--include/arpa/CVS/Root1
-rw-r--r--include/arpa/ftp.h108
-rw-r--r--include/arpa/inet.h147
-rw-r--r--include/arpa/nameser.h369
-rw-r--r--include/arpa/telnet.h339
-rw-r--r--include/arpa/tftp.h83
-rw-r--r--include/asr.h90
-rw-r--r--include/assert.h68
-rw-r--r--include/bitstring.h128
-rw-r--r--include/blf.h82
-rw-r--r--include/bsd_auth.h105
-rw-r--r--include/complex.h120
-rw-r--r--include/cpio.h59
-rw-r--r--include/ctype.h304
-rw-r--r--include/curses.h13
-rw-r--r--include/db.h161
-rw-r--r--include/dirent.h104
-rw-r--r--include/disktab.h60
-rw-r--r--include/dlfcn.h98
-rw-r--r--include/elf.h12
-rw-r--r--include/elf_abi.h33
-rw-r--r--include/err.h3
-rw-r--r--include/errno.h59
-rw-r--r--include/fenv.h60
-rw-r--r--include/float.h95
-rw-r--r--include/fnmatch.h57
-rw-r--r--include/fstab.h78
-rw-r--r--include/fts.h127
-rw-r--r--include/ftw.h60
-rw-r--r--include/getopt.h76
-rw-r--r--include/glob.h103
-rw-r--r--include/grp.h4
-rw-r--r--include/icdb.h44
-rw-r--r--include/ieeefp.h23
-rw-r--r--include/ifaddrs.h56
-rw-r--r--include/inttypes.h262
-rw-r--r--include/iso646.h26
-rw-r--r--include/kvm.h79
-rw-r--r--include/langinfo.h88
-rw-r--r--include/libgen.h29
-rw-r--r--include/limits.h117
-rw-r--r--include/link.h149
-rw-r--r--include/link_elf.h42
-rw-r--r--include/locale.h112
-rw-r--r--include/login_cap.h110
-rw-r--r--include/machine/endian.h1
-rw-r--r--include/math.h497
-rw-r--r--include/md5.h49
-rw-r--r--include/memory.h35
-rw-r--r--include/ndbm.h78
-rw-r--r--include/netdb.h329
-rw-r--r--include/netgroup.h67
-rw-r--r--include/netinet/ip.h9
-rw-r--r--include/nl_types.h91
-rw-r--r--include/nlist.h87
-rw-r--r--include/paths.h81
-rw-r--r--include/poll.h9
-rw-r--r--include/protocols/CVS/Entries6
-rw-r--r--include/protocols/CVS/Repository1
-rw-r--r--include/protocols/CVS/Root1
-rw-r--r--include/protocols/dumprestore.h159
-rw-r--r--include/protocols/routed.h152
-rw-r--r--include/protocols/rwhod.h67
-rw-r--r--include/protocols/talkd.h120
-rw-r--r--include/protocols/timed.h101
-rw-r--r--include/pthread.h315
-rw-r--r--include/pthread_np.h56
-rw-r--r--include/pwd.h4
-rw-r--r--include/ranlib.h49
-rw-r--r--include/readpassphrase.h40
-rw-r--r--include/regex.h104
-rw-r--r--include/resolv.h3
-rw-r--r--include/rmd160.h60
-rw-r--r--include/rpc/CVS/Entries14
-rw-r--r--include/rpc/CVS/Repository1
-rw-r--r--include/rpc/CVS/Root1
-rw-r--r--include/rpc/auth.h184
-rw-r--r--include/rpc/auth_unix.h84
-rw-r--r--include/rpc/clnt.h361
-rw-r--r--include/rpc/pmap_clnt.h85
-rw-r--r--include/rpc/pmap_prot.h106
-rw-r--r--include/rpc/pmap_rmt.h65
-rw-r--r--include/rpc/rpc.h108
-rw-r--r--include/rpc/rpc_des.h135
-rw-r--r--include/rpc/rpc_msg.h200
-rw-r--r--include/rpc/svc.h326
-rw-r--r--include/rpc/svc_auth.h1
-rw-r--r--include/rpc/types.h66
-rw-r--r--include/rpc/xdr.h316
-rw-r--r--include/rpcsvc/CVS/Entries3
-rw-r--r--include/rpcsvc/CVS/Repository1
-rw-r--r--include/rpcsvc/CVS/Root1
-rw-r--r--include/rpcsvc/yp_prot.h316
-rw-r--r--include/rpcsvc/ypclnt.h82
-rw-r--r--include/sched.h75
-rw-r--r--include/search.h57
-rw-r--r--include/semaphore.h62
-rw-r--r--include/setjmp.h67
-rw-r--r--include/sha1.h57
-rw-r--r--include/sha2.h156
-rw-r--r--include/signal.h140
-rw-r--r--include/siphash.h83
-rw-r--r--include/sndio.h205
-rw-r--r--include/spawn.h103
-rw-r--r--include/stdbool.h45
-rw-r--r--include/stddef.h84
-rw-r--r--include/stdio.h435
-rw-r--r--include/stdlib.h12
-rw-r--r--include/string.h5
-rw-r--r--include/strings.h83
-rw-r--r--include/sys/cdefs.h5
-rw-r--r--include/sys/param.h3
-rw-r--r--include/sys/time.h14
-rw-r--r--include/sysexits.h119
-rw-r--r--include/tar.h66
-rw-r--r--include/tgmath.h169
-rw-r--r--include/tib.h258
-rw-r--r--include/time.h191
-rw-r--r--include/ttyent.h73
-rw-r--r--include/unistd.h3
-rw-r--r--include/utime.h55
-rw-r--r--include/utmp.h69
-rw-r--r--include/uuid.h69
-rw-r--r--include/vis.h93
-rw-r--r--include/wchar.h239
-rw-r--r--include/wctype.h107
-rw-r--r--includedir/err.h3
-rw-r--r--includedir/grp.h4
-rw-r--r--includedir/machine/endian.h1
-rw-r--r--includedir/netinet/ip.h9
-rw-r--r--includedir/pwd.h4
-rw-r--r--includedir/readpassphrase.h40
-rw-r--r--includedir/resolv.h3
-rw-r--r--includedir/stdlib.h12
-rw-r--r--includedir/string.h5
-rw-r--r--includedir/sys/cdefs.h5
-rw-r--r--includedir/sys/compat.h59
-rw-r--r--includedir/sys/param.h3
-rw-r--r--includedir/sys/time.h14
-rw-r--r--includedir/unistd.h3
-rw-r--r--lib/libc/crypt/arc4random.c198
-rw-r--r--lib/libc/crypt/arc4random_uniform.c57
-rw-r--r--lib/libc/crypt/blowfish.c698
-rw-r--r--lib/libc/crypt/chacha_private.h222
-rw-r--r--lib/libc/gen/fts.c1053
-rw-r--r--lib/libc/gen/getprogname.c24
-rw-r--r--lib/libc/gen/pwcache.c433
-rw-r--r--lib/libc/gen/readpassphrase.c190
-rw-r--r--lib/libc/gen/setprogname.c31
-rw-r--r--lib/libc/gen/unvis.c286
-rw-r--r--lib/libc/gen/vis.c243
-rw-r--r--lib/libc/gen/vwarnc.c47
-rw-r--r--lib/libc/gen/warnc.c43
-rw-r--r--lib/libc/hash/helper.c118
-rw-r--r--lib/libc/hash/md5.c252
-rw-r--r--lib/libc/hash/rmd160.c375
-rw-r--r--lib/libc/hash/sha1.c179
-rw-r--r--lib/libc/hash/sha2.c977
-rw-r--r--lib/libc/net/base64.c315
-rw-r--r--lib/libc/stdlib/freezero.c32
-rw-r--r--lib/libc/stdlib/reallocarray.c39
-rw-r--r--lib/libc/stdlib/recallocarray.c81
-rw-r--r--lib/libc/stdlib/strtonum.c66
-rw-r--r--lib/libc/string/strmode.c141
-rw-r--r--lib/libc/string/timingsafe_bcmp.c30
-rw-r--r--lib/libc/string/timingsafe_memcmp.c47
-rw-r--r--lib/libcrypto/arc4random/arc4random_linux.h88
-rw-r--r--lib/libcrypto/md32_common.h345
-rw-r--r--lib/libcrypto/sha/sha256.c284
-rw-r--r--lib/libcrypto/sha/sha512.c547
-rw-r--r--lib/libutil/bcrypt_pbkdf.c176
-rw-r--r--lib/libutil/ohash.c328
-rw-r--r--lib/libutil/ohash.h74
-rw-r--r--lib/libutil/pidfile.c106
-rw-r--r--lib/libutil/util.h127
-rw-r--r--lib/libz/CVS/Entries30
-rw-r--r--lib/libz/CVS/Repository1
-rw-r--r--lib/libz/CVS/Root1
-rw-r--r--lib/libz/ChangeLog855
-rw-r--r--lib/libz/Makefile30
-rw-r--r--lib/libz/README125
-rw-r--r--lib/libz/adler32.c148
-rw-r--r--lib/libz/algorithm.doc209
-rw-r--r--lib/libz/compress.32810
-rw-r--r--lib/libz/compress.c79
-rw-r--r--lib/libz/compress.cat31556
-rw-r--r--lib/libz/crc32.c422
-rw-r--r--lib/libz/crc32.h441
-rw-r--r--lib/libz/deflate.c1734
-rw-r--r--lib/libz/deflate.h331
-rw-r--r--lib/libz/generate_pkgconfig.sh70
-rw-r--r--lib/libz/gzio.c1003
-rw-r--r--lib/libz/infback.c637
-rw-r--r--lib/libz/inffast.c331
-rw-r--r--lib/libz/inffast.h12
-rw-r--r--lib/libz/inffixed.h95
-rw-r--r--lib/libz/inflate.c1447
-rw-r--r--lib/libz/inflate.h115
-rw-r--r--lib/libz/inftrees.c328
-rw-r--r--lib/libz/inftrees.h56
-rw-r--r--lib/libz/shlib_version2
-rw-r--r--lib/libz/trees.c1219
-rw-r--r--lib/libz/trees.h129
-rw-r--r--lib/libz/uncompr.c61
-rw-r--r--lib/libz/zconf.h330
-rw-r--r--lib/libz/zlib.h1359
-rw-r--r--lib/libz/zutil.c319
-rw-r--r--lib/libz/zutil.h273
-rw-r--r--patches/0001-fts-Avoid-d_namlen.patch49
-rw-r--r--patches/0002-fts-Add-some-includes.patch46
-rw-r--r--patches/0003-pax-Set-listf-to-stderr-in-main.patch34
-rw-r--r--patches/0004-pax-Add-some-includes.patch86
-rw-r--r--patches/0005-tar-Default-to-stdin.patch25
-rw-r--r--patches/0006-yacc-Add-some-includes.patch24
-rw-r--r--patches/0007-diff-Add-missing-includes.patch37
-rw-r--r--patches/0008-patch-Add-missing-includes.patch24
-rw-r--r--patches/0009-patch-Avoid-d_namlen.patch25
-rw-r--r--patches/0010-patch-Fix-with-musl-s-basename-dirname.patch46
-rw-r--r--patches/0011-pax-Fix-GNU-long-name-handling-with-short-read.patch176
-rw-r--r--patches/0012-pax-Support-xz-compression-with-J-flag.patch90
-rw-r--r--patches/0013-setprogname-Explicitly-discard-const-qualifier.patch23
-rw-r--r--patches/0014-readpassphrase-Support-systems-without-VSTATUS-and-T.patch38
-rw-r--r--patches/0015-Remove-getpass-definition.patch36
-rw-r--r--patches/0016-doas-Port-to-linux-musl.patch435
-rw-r--r--patches/0017-pwcache-Don-t-use-fixed-buffer-sizes.patch92
-rw-r--r--patches/0018-yacc-Remove-__unused.patch27
-rw-r--r--patches/0019-Add-standalone-freezero.patch51
-rw-r--r--patches/0020-m4-Use-hand-written-lexer-to-avoid-cycle-in-bootstra.patch327
-rw-r--r--patches/0021-m4-Use-_Noreturn-instead-of-__dead.patch25
-rw-r--r--patches/0022-m4-Add-missing-includes.patch50
-rw-r--r--patches/0023-libutil-Add-missing-includes.patch24
-rw-r--r--patches/0024-acme-client-Add-missing-includes.patch25
-rw-r--r--patches/0025-rsync-Add-missing-includes.patch40
-rw-r--r--patches/0026-rsync-Use-standard-S_ISVTX-instead-of-S_ISTXT.patch34
-rw-r--r--patches/0027-rsync-Use-1-instead-of-INFTIM-for-poll-timeout.patch25
-rw-r--r--patches/0028-rsync-Avoid-pointer-arithmetic-on-void.patch148
-rw-r--r--patches/0029-Include-sys-sysmacros.h-if-necessary.patch73
-rw-r--r--patches/0030-nc-Portability-fixes-from-libressl-portable.patch194
-rw-r--r--patches/0031-pax-Ignore-EOPNOTSUPP-from-fchmodat.patch26
-rw-r--r--patches/0032-acme-client-Fix-build-with-old-bison-versions.patch24
-rw-r--r--patches/0033-rsync-Add-implementation-of-MD4.patch414
-rw-r--r--patches/0034-pax-Fix-some-incorrect-format-specifiers.patch48
-rw-r--r--patches/0035-pax-Use-memcpy-to-set-TMAGIC-and-TVERSION-to-avoid-w.patch27
-rw-r--r--patches/0036-rsync-Fix-some-incorrect-format-specifiers.patch25
-rw-r--r--patches/0037-m4-Declare-dopaste-only-when-it-s-used.patch26
-rw-r--r--patches/0038-sha2-add-missing-include.patch11
-rw-r--r--patches/0039-bcrypt-add-cdefs.patch10
-rw-r--r--patches/0040-mandoc-port-to-musl.patch159
-rw-r--r--patches/0041-pidfile-add-cdefs.patch10
-rw-r--r--patches/0042-doas-define-gnu-source.patch13
-rw-r--r--patches/0043-signify-add-headers.patch34
-rw-r--r--patches/0044-fix-hash-objects.patch40
-rw-r--r--patches/0045-md5-add-headers.patch19
-rw-r--r--sys/sys/CVS/Entries139
-rw-r--r--sys/sys/CVS/Repository1
-rw-r--r--sys/sys/CVS/Root1
-rw-r--r--sys/sys/_endian.h179
-rw-r--r--sys/sys/_lock.h70
-rw-r--r--sys/sys/_null.h18
-rw-r--r--sys/sys/_time.h64
-rw-r--r--sys/sys/_types.h78
-rw-r--r--sys/sys/acct.h79
-rw-r--r--sys/sys/ataio.h48
-rw-r--r--sys/sys/atomic.h258
-rw-r--r--sys/sys/audioio.h231
-rw-r--r--sys/sys/buf.h374
-rw-r--r--sys/sys/cdefs.h413
-rw-r--r--sys/sys/cdio.h435
-rw-r--r--sys/sys/chio.h176
-rw-r--r--sys/sys/conf.h633
-rw-r--r--sys/sys/core.h99
-rw-r--r--sys/sys/ctf.h186
-rw-r--r--sys/sys/device.h224
-rw-r--r--sys/sys/dir.h65
-rw-r--r--sys/sys/dirent.h100
-rw-r--r--sys/sys/disk.h160
-rw-r--r--sys/sys/disklabel.h533
-rw-r--r--sys/sys/dkio.h80
-rw-r--r--sys/sys/domain.h78
-rw-r--r--sys/sys/endian.h124
-rw-r--r--sys/sys/errno.h182
-rw-r--r--sys/sys/evcount.h50
-rw-r--r--sys/sys/event.h224
-rw-r--r--sys/sys/eventvar.h64
-rw-r--r--sys/sys/exec.h386
-rw-r--r--sys/sys/exec_elf.h785
-rw-r--r--sys/sys/exec_script.h43
-rw-r--r--sys/sys/extent.h130
-rw-r--r--sys/sys/fcntl.h220
-rw-r--r--sys/sys/file.h136
-rw-r--r--sys/sys/filedesc.h157
-rw-r--r--sys/sys/filio.h54
-rw-r--r--sys/sys/fusebuf.h148
-rw-r--r--sys/sys/futex.h41
-rw-r--r--sys/sys/gmon.h175
-rw-r--r--sys/sys/gpio.h80
-rw-r--r--sys/sys/hibernate.h159
-rw-r--r--sys/sys/hotplug.h40
-rw-r--r--sys/sys/ioccom.h68
-rw-r--r--sys/sys/ioctl.h55
-rw-r--r--sys/sys/ipc.h95
-rw-r--r--sys/sys/kcore.h65
-rw-r--r--sys/sys/kcov.h40
-rw-r--r--sys/sys/kernel.h65
-rw-r--r--sys/sys/kthread.h50
-rw-r--r--sys/sys/ktrace.h254
-rw-r--r--sys/sys/limits.h125
-rw-r--r--sys/sys/lock.h55
-rw-r--r--sys/sys/lockf.h45
-rw-r--r--sys/sys/malloc.h406
-rw-r--r--sys/sys/mbuf.h550
-rw-r--r--sys/sys/memrange.h97
-rw-r--r--sys/sys/mman.h165
-rw-r--r--sys/sys/mount.h637
-rw-r--r--sys/sys/mplock.h75
-rw-r--r--sys/sys/msg.h177
-rw-r--r--sys/sys/msgbuf.h53
-rw-r--r--sys/sys/mtio.h147
-rw-r--r--sys/sys/mutex.h165
-rw-r--r--sys/sys/namei.h279
-rw-r--r--sys/sys/param.h223
-rw-r--r--sys/sys/pciio.h78
-rw-r--r--sys/sys/percpu.h198
-rw-r--r--sys/sys/pipe.h96
-rw-r--r--sys/sys/pledge.h147
-rw-r--r--sys/sys/poll.h89
-rw-r--r--sys/sys/pool.h295
-rw-r--r--sys/sys/proc.h655
-rw-r--r--sys/sys/protosw.h237
-rw-r--r--sys/sys/ptrace.h137
-rw-r--r--sys/sys/queue.h536
-rw-r--r--sys/sys/radioio.h76
-rw-r--r--sys/sys/reboot.h106
-rw-r--r--sys/sys/refcnt.h38
-rw-r--r--sys/sys/resource.h128
-rw-r--r--sys/sys/resourcevar.h107
-rw-r--r--sys/sys/rwlock.h191
-rw-r--r--sys/sys/sched.h244
-rw-r--r--sys/sys/scsiio.h74
-rw-r--r--sys/sys/select.h137
-rw-r--r--sys/sys/selinfo.h57
-rw-r--r--sys/sys/sem.h198
-rw-r--r--sys/sys/sensors.h177
-rw-r--r--sys/sys/shm.h151
-rw-r--r--sys/sys/siginfo.h199
-rw-r--r--sys/sys/sigio.h95
-rw-r--r--sys/sys/signal.h202
-rw-r--r--sys/sys/signalvar.h144
-rw-r--r--sys/sys/smr.h440
-rw-r--r--sys/sys/socket.h572
-rw-r--r--sys/sys/socketvar.h365
-rw-r--r--sys/sys/sockio.h230
-rw-r--r--sys/sys/specdev.h113
-rw-r--r--sys/sys/srp.h190
-rw-r--r--sys/sys/stacktrace.h40
-rw-r--r--sys/sys/stat.h222
-rw-r--r--sys/sys/statvfs.h48
-rw-r--r--sys/sys/stdarg.h51
-rw-r--r--sys/sys/stdint.h231
-rw-r--r--sys/sys/swap.h62
-rw-r--r--sys/sys/syscall.h708
-rw-r--r--sys/sys/syscall_mi.h191
-rw-r--r--sys/sys/syscallargs.h1362
-rw-r--r--sys/sys/sysctl.h1061
-rw-r--r--sys/sys/syslimits.h77
-rw-r--r--sys/sys/syslog.h221
-rw-r--r--sys/sys/systm.h409
-rw-r--r--sys/sys/task.h60
-rw-r--r--sys/sys/termios.h299
-rw-r--r--sys/sys/time.h418
-rw-r--r--sys/sys/timeout.h137
-rw-r--r--sys/sys/times.h63
-rw-r--r--sys/sys/timetc.h107
-rw-r--r--sys/sys/tprintf.h41
-rw-r--r--sys/sys/tracepoint.h36
-rw-r--r--sys/sys/tree.h1006
-rw-r--r--sys/sys/tty.h336
-rw-r--r--sys/sys/ttycom.h151
-rw-r--r--sys/sys/ttydefaults.h95
-rw-r--r--sys/sys/types.h261
-rw-r--r--sys/sys/ucred.h84
-rw-r--r--sys/sys/uio.h108
-rw-r--r--sys/sys/un.h65
-rw-r--r--sys/sys/unistd.h106
-rw-r--r--sys/sys/unpcb.h111
-rw-r--r--sys/sys/user.h48
-rw-r--r--sys/sys/utsname.h59
-rw-r--r--sys/sys/uuid.h75
-rw-r--r--sys/sys/varargs.h56
-rw-r--r--sys/sys/videoio.h3372
-rw-r--r--sys/sys/vmmeter.h97
-rw-r--r--sys/sys/vnode.h665
-rw-r--r--sys/sys/wait.h103
-rw-r--r--sys/sys/witness.h156
407 files changed, 72894 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..5bacaf8
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,11 @@
+*.a
+*.o
+diff
+doas
+m4
+mandoc
+md5
+nc
+patch
+pax
+signify
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..0d615e0
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,6 @@
+bin/ include/ lib/ sys/ usr.bin/ come from OpenBSD with the modifications from
+ patches folder.
+includedir/ patches/00[01-37]-* come from OasisLinux
+includedir/sys/compat.h taken from https://github.com/aperezdc/signify
+
+The Makefile, config.mk and other patches are on the public domain.
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..246d9f1
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,364 @@
+include config.mk
+BIN = \
+ diff \
+ doas \
+ m4 \
+ mandoc \
+ md5 \
+ nc \
+ patch \
+ pax \
+ signify
+
+LIB = lib/libbsd.a
+LIBOBJ = \
+ lib/libc/crypt/arc4random.o \
+ lib/libc/crypt/arc4random_uniform.o \
+ lib/libc/crypt/blowfish.o \
+ lib/libc/gen/fts.o \
+ lib/libc/gen/getprogname.o \
+ lib/libc/gen/pwcache.o \
+ lib/libc/gen/readpassphrase.o \
+ lib/libc/gen/setprogname.o \
+ lib/libc/gen/unvis.o \
+ lib/libc/gen/vis.o \
+ lib/libc/gen/vwarnc.o \
+ lib/libc/gen/warnc.o \
+ lib/libc/hash/md5.o \
+ lib/libc/hash/md5hl.o \
+ lib/libc/hash/rmd160.o \
+ lib/libc/hash/rmd160hl.o \
+ lib/libc/hash/sha1.o \
+ lib/libc/hash/sha2.o \
+ lib/libc/hash/sha1hl.o \
+ lib/libc/hash/sha224hl.o \
+ lib/libc/hash/sha256hl.o \
+ lib/libc/hash/sha384hl.o \
+ lib/libc/hash/sha512_256hl.o \
+ lib/libc/hash/sha512hl.o \
+ lib/libc/net/base64.o \
+ lib/libc/stdlib/freezero.o \
+ lib/libc/stdlib/reallocarray.o \
+ lib/libc/stdlib/recallocarray.o \
+ lib/libc/stdlib/strtonum.o \
+ lib/libc/string/strmode.o \
+ lib/libc/string/timingsafe_bcmp.o \
+ lib/libc/string/timingsafe_memcmp.o \
+ lib/libcrypto/sha/sha256.o \
+ lib/libcrypto/sha/sha512.o \
+ lib/libutil/bcrypt_pbkdf.o \
+ lib/libutil/ohash.o \
+ lib/libutil/pidfile.o
+
+
+MAN = \
+ usr.bin/diff/diff.1 \
+ usr.bin/doas/doas.1 \
+ usr.bin/doas/doas.conf.5 \
+ usr.bin/mandoc/apropos.1 \
+ usr.bin/mandoc/makewhatis.8 \
+ usr.bin/mandoc/man.1 \
+ usr.bin/mandoc/man.conf.5 \
+ usr.bin/mandoc/mandoc.1 \
+ usr.bin/m4/m4.1 \
+ usr.bin/nc/nc.1 \
+ usr.bin/patch/patch.1 \
+ bin/md5/md5.1 \
+ bin/md5/cksum.1 \
+ bin/pax/cpio.1 \
+ bin/pax/pax.1 \
+ bin/pax/tar.1 \
+ usr.bin/signify/signify.1
+
+.y.c:
+ ${YACC} -o $@ $<
+.c.o:
+ ${CC} ${CFLAGS} -c -o $@ $<
+
+.o: ${LIB}
+
+all: ${BIN}
+${BINOBJ}: ${LIB}
+
+# ------------------------------------------------------------------------------
+# diff
+DIFFOBJ = \
+ usr.bin/diff/diff.o \
+ usr.bin/diff/diffdir.o \
+ usr.bin/diff/diffreg.o \
+ usr.bin/diff/xmalloc.o
+BINOBJ += ${DIFFOBJ}
+diff: ${DIFFOBJ} ${LIB}
+ ${CC} ${LDFLAGS} -o $@ ${DIFFOBJ} ${LIB}
+
+# ------------------------------------------------------------------------------
+# doas
+DOASOBJ = \
+ usr.bin/doas/parse.o \
+ usr.bin/doas/doas.o \
+ usr.bin/doas/env.o \
+ usr.bin/doas/persist.o
+
+BINOBJ += ${DOASOBJ} parse.c
+${DOASOBJ}: usr.bin/doas/parse.tab.h
+usr.bin/doas/parse.c usr.bin/doas/parse.tab.h: usr.bin/doas/parse.y
+ ${YACC} -o usr.bin/doas/parse.c -dH usr.bin/doas/parse.tab.h $<
+usr.bin/doas/env.o: usr.bin/doas/env.c
+ ${CC} ${CFLAGS} -include sys/sys/tree.h -c -o $@ $<
+doas: ${DOASOBJ} ${LIB}
+ ${CC} ${LDFLAGS} -o $@ ${DOASOBJ} ${LIB}
+
+
+# ------------------------------------------------------------------------------
+# m4
+M4OBJ = \
+ usr.bin/m4/eval.o \
+ usr.bin/m4/expr.o \
+ usr.bin/m4/look.o \
+ usr.bin/m4/main.o \
+ usr.bin/m4/misc.o \
+ usr.bin/m4/gnum4.o \
+ usr.bin/m4/trace.o \
+ usr.bin/m4/tokenizer.o \
+ usr.bin/m4/parser.o
+BINOBJ += ${M4OBJ} parser.c
+
+usr.bin/m4/parser.c usr.bin/m4/parser.tab.h: usr.bin/m4/parser.y
+ ${YACC} -o usr.bin/m4/parser.c -dH usr.bin/m4/parser.tab.h $<
+usr.bin/m4/tokenizer.o: usr.bin/m4/tokenizer.c usr.bin/m4/parser.tab.h
+ ${CC} ${CFLAGS} -I${PWD}/usr.bin/m4 -include usr.bin/m4/parser.tab.h \
+ -c -o $@ usr.bin/m4/tokenizer.c
+
+m4: ${M4OBJ} ${LIB}
+ ${CC} ${LDFLAGS} -o $@ ${M4OBJ} ${LIB}
+
+# ------------------------------------------------------------------------------
+# mandoc
+MANDOCLINK = makewhatis whatis apropos man
+MANDOCOBJ = \
+ usr.bin/mandoc/arch.o \
+ usr.bin/mandoc/att.o \
+ usr.bin/mandoc/chars.o \
+ usr.bin/mandoc/dba.o \
+ usr.bin/mandoc/dba_array.o \
+ usr.bin/mandoc/dba_read.o \
+ usr.bin/mandoc/dba_write.o \
+ usr.bin/mandoc/dbm.o \
+ usr.bin/mandoc/dbm_map.o \
+ usr.bin/mandoc/eqn.o \
+ usr.bin/mandoc/eqn_html.o \
+ usr.bin/mandoc/eqn_term.o \
+ usr.bin/mandoc/html.o \
+ usr.bin/mandoc/main.o \
+ usr.bin/mandoc/man.o \
+ usr.bin/mandoc/man_html.o \
+ usr.bin/mandoc/man_macro.o \
+ usr.bin/mandoc/man_term.o \
+ usr.bin/mandoc/man_validate.o \
+ usr.bin/mandoc/mandoc.o \
+ usr.bin/mandoc/mandoc_aux.o \
+ usr.bin/mandoc/mandoc_msg.o \
+ usr.bin/mandoc/mandoc_ohash.o \
+ usr.bin/mandoc/mandoc_xr.o \
+ usr.bin/mandoc/mandocdb.o \
+ usr.bin/mandoc/manpath.o \
+ usr.bin/mandoc/mansearch.o \
+ usr.bin/mandoc/mdoc.o \
+ usr.bin/mandoc/mdoc_argv.o \
+ usr.bin/mandoc/mdoc_html.o \
+ usr.bin/mandoc/mdoc_macro.o \
+ usr.bin/mandoc/mdoc_man.o \
+ usr.bin/mandoc/mdoc_markdown.o \
+ usr.bin/mandoc/mdoc_state.o \
+ usr.bin/mandoc/mdoc_term.o \
+ usr.bin/mandoc/mdoc_validate.o \
+ usr.bin/mandoc/msec.o \
+ usr.bin/mandoc/out.o \
+ usr.bin/mandoc/preconv.o \
+ usr.bin/mandoc/read.o \
+ usr.bin/mandoc/roff.o \
+ usr.bin/mandoc/roff_html.o \
+ usr.bin/mandoc/roff_term.o \
+ usr.bin/mandoc/roff_validate.o \
+ usr.bin/mandoc/st.o \
+ usr.bin/mandoc/tag.o \
+ usr.bin/mandoc/tbl.o \
+ usr.bin/mandoc/tbl_data.o \
+ usr.bin/mandoc/tbl_html.o \
+ usr.bin/mandoc/tbl_layout.o \
+ usr.bin/mandoc/tbl_opts.o \
+ usr.bin/mandoc/tbl_term.o \
+ usr.bin/mandoc/term.o \
+ usr.bin/mandoc/term_ascii.o \
+ usr.bin/mandoc/term_ps.o \
+ usr.bin/mandoc/term_tab.o \
+ usr.bin/mandoc/term_tag.o \
+ usr.bin/mandoc/tree.o
+BINOBJ += ${MANDOCOBJ}
+mandoc: ${MANDOCOBJ} ${LIB}
+ ${CC} ${LDFLAGS} -o $@ ${MANDOCOBJ} ${LIB} ${ZLIB}
+
+# ------------------------------------------------------------------------------
+# md5
+MD5LINK = sha1 sha224 sha256 sha384 sha512 rmd160 cksum
+MD5MAN = sha1.1 sha224.1 sha256.1 sha384.1 sha512.1 rmd160.1
+MD5OBJ = \
+ bin/md5/crc.o \
+ bin/md5/md5.o
+BINOBJ += ${MD5OBJ}
+md5: ${MD5OBJ} ${LIB}
+ ${CC} ${LDFLAGS} -o $@ ${MD5OBJ} ${LIB}
+
+# ------------------------------------------------------------------------------
+# nc
+NCOBJ = \
+ usr.bin/nc/atomicio.o \
+ usr.bin/nc/netcat.o \
+ usr.bin/nc/socks.o
+BINOBJ += ${NCOBJ}
+usr.bin/nc/netcat.o: usr.bin/nc/netcat.c
+ ${CC} ${CFLAGS} -include /usr/include/tls.h -c -o $@ $<
+nc: ${NCOBJ} ${LIB}
+ ${CC} ${LDFLAGS} -o $@ ${NCOBJ} ${LIB} ${TLSLIB}
+
+# ------------------------------------------------------------------------------
+# pax
+PAXOBJ = \
+ bin/pax/ar_io.o \
+ bin/pax/ar_subs.o \
+ bin/pax/buf_subs.o \
+ bin/pax/cpio.o \
+ bin/pax/file_subs.o \
+ bin/pax/ftree.o \
+ bin/pax/gen_subs.o \
+ bin/pax/getoldopt.o \
+ bin/pax/options.o \
+ bin/pax/pat_rep.o \
+ bin/pax/pax.o \
+ bin/pax/sel_subs.o \
+ bin/pax/tables.o \
+ bin/pax/tar.o \
+ bin/pax/tty_subs.o
+BINOBJ += ${PAXOBJ}
+pax: ${PAXOBJ} ${LIB}
+ ${CC} ${LDFLAGS} -o $@ ${PAXOBJ} ${LIB}
+
+# ------------------------------------------------------------------------------
+# patch
+PATCHOBJ = \
+ usr.bin/patch/patch.o \
+ usr.bin/patch/pch.o \
+ usr.bin/patch/inp.o \
+ usr.bin/patch/util.o \
+ usr.bin/patch/backupfile.o \
+ usr.bin/patch/mkpath.o \
+ usr.bin/patch/ed.o
+BINOBJ += ${PATCHOBJ}
+patch: ${PATCHOBJ} ${LIB}
+ ${CC} ${LDFLAGS} -o $@ ${PATCHOBJ} ${LIB}
+
+# -----------------------------------------------------------------------------
+# signify
+SIGNIFYOBJ = \
+ usr.bin/signify/signify.o \
+ usr.bin/signify/zsig.o \
+ usr.bin/signify/fe25519.o \
+ usr.bin/signify/sc25519.o \
+ usr.bin/signify/mod_ed25519.o \
+ usr.bin/signify/mod_ge25519.o \
+ usr.bin/signify/crypto_api.o
+BINOBJ += ${SIGNIFYOBJ}
+signify: ${SIGNIFYOBJ} ${LIB}
+ ${CC} ${LDFLAGS} -o $@ ${SIGNIFYOBJ} ${LIB}
+
+# ------------------------------------------------------------------------------
+# hash helpers
+HELPER = lib/libc/hash/helper.c
+HASHOBJ = \
+ lib/libc/hash/md5hl.c \
+ lib/libc/hash/rmd160hl.c \
+ lib/libc/hash/sha1hl.c \
+ lib/libc/hash/sha224hl.c \
+ lib/libc/hash/sha256hl.c \
+ lib/libc/hash/sha384hl.c \
+ lib/libc/hash/sha512hl.c \
+ lib/libc/hash/sha512_256hl.c
+BINOBJ += ${HASHOBJ}
+${HASHOBJ}: ${HELPER}
+lib/libc/hash/md5hl.c:
+ sed 's|HASH|MD5|g;s|hashinc|md5.h|' < ${HELPER} > $@
+lib/libc/hash/rmd160hl.c:
+ sed 's|HASH|RMD160|g;s|hashinc|rmd160.h|' < ${HELPER} > $@
+lib/libc/hash/sha1hl.c:
+ sed 's|HASH|SHA1|g;s|hashinc|sha1.h|' < ${HELPER} > $@
+lib/libc/hash/sha224hl.c:
+ sed 's|HASH|SHA224|g;s|hashinc|sha2.h|' < ${HELPER} | sed 's,SHA224_CTX,SHA2_CTX,g' > $@
+lib/libc/hash/sha256hl.c:
+ sed 's|HASH|SHA256|g;s|hashinc|sha2.h|' < ${HELPER} | sed 's,SHA256_CTX,SHA2_CTX,g' > $@
+lib/libc/hash/sha384hl.c:
+ sed 's|HASH|SHA384|g;s|hashinc|sha2.h|' < ${HELPER} | sed 's,SHA384_CTX,SHA2_CTX,g' > $@
+lib/libc/hash/sha512hl.c:
+ sed 's|HASH|SHA512|g;s|hashinc|sha2.h|' < ${HELPER} | sed 's,SHA512_CTX,SHA2_CTX,g' > $@
+lib/libc/hash/sha512_256hl.c:
+ sed 's|HASH|SHA512_256|g;s|hashinc|sha2.h|' < ${HELPER} | sed 's,SHA512_256_CTX,SHA2_CTX,g' > $@
+
+# ------------------------------------------------------------------------------
+# libz
+LIBZOBJ = \
+ lib/libz/adler32.o \
+ lib/libz/compress.o \
+ lib/libz/crc32.o \
+ lib/libz/deflate.o \
+ lib/libz/gzio.o \
+ lib/libz/infback.o \
+ lib/libz/inffast.o \
+ lib/libz/inflate.o \
+ lib/libz/inftrees.o \
+ lib/libz/trees.o \
+ lib/libz/uncompr.o \
+ lib/libz/zutil.o
+BINOBJ += ${LIBZOBJ}
+lib/libz/libz.a: ${LIBZOBJ}
+ ${AR} rc $@ $?
+ ${RANLIB} $@
+
+# ------------------------------------------------------------------------------
+# libbsd
+
+lib/libc/crypt/arc4random.o: lib/libc/crypt/arc4random.c lib/libcrypto/arc4random/arc4random_linux.h
+ mkdir -p arc4random
+ cp lib/libc/crypt/arc4random.c arc4random
+ cp lib/libcrypto/arc4random/arc4random_linux.h arc4random/arc4random.h
+ cp lib/libc/crypt/chacha_private.h arc4random
+ ${CC} ${CFLAGS} -c -o $@ arc4random/arc4random.c
+ ${RM} -r -- arc4random
+
+lib/libbsd.a: ${LIBOBJ}
+ ${AR} rc $@ $?
+ ${RANLIB} $@
+
+
+getobj:
+ @printf '%s\n' ${LIBOBJ}
+
+install:
+ mkdir -p ${DESTDIR}${BINDIR}
+ for bin in ${BIN}; do \
+ cp $${bin} ${DESTDIR}${BINDIR}; \
+ chmod 755 ${DESTDIR}${BINDIR}/$${bin##*/}; done
+ chmod u+x ${DESTDIR}${BINDIR}/doas
+ for bin in ${MANDOCLINK}; do \
+ ln -s mandoc ${DESTDIR}${BINDIR}/$${bin}; done
+ for bin in ${MD5LINK}; do \
+ ln -s md5 ${DESTDIR}${BINDIR}/$${bin}; done
+ for man in ${MAN}; do \
+ mkdir -p ${DESTDIR}${MANPREFIX}/man$${man##*.}; \
+ cp $${man} ${DESTDIR}${MANPREFIX}/man$${man##*.}; \
+ chmod 644 ${DESTDIR}${MANPREFIX}/man$${man##*.}/$${man##*/}; done
+ for man in ${MD5MAN}; do \
+ ln -s md5.1 ${DESTDIR}${MANPREFIX}/man1/$${man}; done
+
+clean:
+ ${RM} ${LIBOBJ} ${LIB} ${BIN} ${BINOBJ} lib/libz/libz.a
+
+.PHONY: all clean
diff --git a/README b/README
new file mode 100644
index 0000000..b8515eb
--- /dev/null
+++ b/README
@@ -0,0 +1,36 @@
+otools
+------
+
+Some OpenBSD userland utilities meant to be included in Carbs Linux base.
+
+Currently includes the following software:
+- diff
+- doas
+- m4
+- mandoc
+- md5
+- nc
+- patch
+- pax
+- signify
+
+You can build software individually by calling 'make <program>', and the
+program will be built to the root directory of the source. The Makefile
+is bsdmake compatible.
+
+requirements
+------------
+
+In order to build 'mandoc', you need to either have zlib installed, or edit
+config.mk to use the in-source zlib.
+
+In order to build 'nc', you need to have a libtls implementation. Carbs Linux
+uses libtls-bearssl by default.
+
+
+patch directory
+---------------
+
+The patch directory doesn't serve any function but to keep track of the applied
+patches under revision control. The sources here are already patched.
+
diff --git a/config.mk b/config.mk
new file mode 100644
index 0000000..c064088
--- /dev/null
+++ b/config.mk
@@ -0,0 +1,29 @@
+PREFIX = /usr/local
+BINDIR = ${PREFIX}/bin
+MANPREFIX = ${PREFIX}/share/man
+
+AR = ar
+CC = cc
+RANLIB = ranlib
+RM = rm -f
+YACC = yacc
+
+
+# You can uncomment the latter if you aren't using libtls-bearssl. If you
+# aren't linking statically, '-ltls' should be suffice.
+TLSLIB = -ltls -lbearssl
+#TLSLIB = `pkgconf --static --libs libtls`
+
+# You can replace the following to 'lib/libz/libz.a' in order to build with the
+# in-source zlib.
+ZLIB = -lz
+
+CFLAGS = -Wall -Wno-pointer-sign -Wno-maybe-uninitialized \
+ -Wno-attributes -I${PWD}/includedir \
+ -D 'DEF_WEAK(n)=_Static_assert(1, "")' \
+ -idirafter ${PWD}/include \
+ -idirafter ${PWD}/sys \
+ -idirafter ${PWD}/lib/libutil \
+ -idirafter ${PWD}/lib/libcrypto
+
+LDFLAGS = -static
diff --git a/include/CVS/Entries b/include/CVS/Entries
new file mode 100644
index 0000000..97f2910
--- /dev/null
+++ b/include/CVS/Entries
@@ -0,0 +1,93 @@
+/Makefile/1.226/Thu Nov 14 21:14:53 2019//
+/a.out.h/1.3/Mon Jun 2 19:34:12 2003//
+/ar.h/1.3/Mon Jun 2 19:34:12 2003//
+/asr.h/1.2/Thu Oct 24 05:57:41 2019//
+/assert.h/1.13/Sun Jun 26 21:11:41 2011//
+/bitstring.h/1.5/Mon Jun 2 19:34:12 2003//
+/blf.h/1.7/Wed Mar 14 17:59:41 2007//
+/bsd_auth.h/1.11/Thu Mar 9 10:13:03 2017//
+/complex.h/1.5/Sun Mar 16 18:38:30 2014//
+/cpio.h/1.3/Thu Jun 26 05:42:04 2008//
+/ctype.h/1.25/Tue Sep 5 03:16:13 2017//
+/curses.h/1.5/Fri Jan 25 00:19:25 2019//
+/db.h/1.12/Sat Oct 17 21:48:42 2015//
+/dirent.h/1.34/Fri Sep 9 18:12:37 2016//
+/disktab.h/1.3/Mon Jun 2 19:34:12 2003//
+/dlfcn.h/1.14/Tue Nov 28 17:19:47 2017//
+/elf.h/1.1/Tue Oct 17 09:34:52 2017//
+/elf_abi.h/1.4/Wed May 22 07:46:22 1996//
+/err.h/1.13/Mon Aug 31 02:53:56 2015//
+/errno.h/1.3/Thu Aug 10 13:34:46 2017//
+/fenv.h/1.2/Wed May 25 21:46:49 2011//
+/float.h/1.1/Tue Jun 26 16:16:16 2012//
+/fnmatch.h/1.8/Tue Dec 13 00:35:22 2005//
+/fstab.h/1.5/Mon Jun 2 19:34:12 2003//
+/fts.h/1.14/Wed Dec 5 23:19:57 2012//
+/ftw.h/1.2/Fri Jan 25 00:19:25 2019//
+/getopt.h/1.3/Fri Nov 22 21:32:49 2013//
+/glob.h/1.14/Mon Feb 4 16:45:40 2019//
+/grp.h/1.13/Thu Sep 13 12:31:15 2018//
+/icdb.h/1.4/Sun Sep 4 14:51:39 2016//
+/ieeefp.h/1.4/Sun Sep 27 21:23:55 2009//
+/ifaddrs.h/1.4/Thu Jan 22 21:48:02 2004//
+/inttypes.h/1.13/Fri Jan 25 00:19:25 2019//
+/iso646.h/1.3/Thu Oct 11 00:05:21 2001//
+/kvm.h/1.18/Tue Oct 22 16:40:25 2013//
+/langinfo.h/1.8/Tue Sep 5 03:16:13 2017//
+/libgen.h/1.9/Fri Jan 25 00:19:25 2019//
+/limits.h/1.19/Tue Jan 20 22:09:50 2015//
+/link.h/1.15/Sat Oct 19 09:00:18 2013//
+/link_elf.h/1.7/Tue Sep 20 18:24:55 2016//
+/locale.h/1.11/Tue Sep 5 03:16:13 2017//
+/login_cap.h/1.16/Sun Jul 29 19:40:41 2018//
+/math.h/1.36/Sat Mar 10 20:52:58 2018//
+/md5.h/1.17/Wed Dec 5 23:19:57 2012//
+/memory.h/1.3/Mon Jun 2 19:34:12 2003//
+/ndbm.h/1.6/Mon May 3 17:27:50 2004//
+/netdb.h/1.33/Sun Jan 18 20:29:31 2015//
+/netgroup.h/1.8/Thu Sep 10 18:59:34 2015//
+/nl_types.h/1.8/Thu Jun 26 05:42:04 2008//
+/nlist.h/1.4/Mon Jun 2 19:34:12 2003//
+/paths.h/1.26/Thu Jul 11 03:54:17 2019//
+/poll.h/1.3/Wed Oct 29 16:41:13 2003//
+/pthread.h/1.4/Mon Mar 5 01:15:26 2018//
+/pthread_np.h/1.3/Tue May 28 10:33:03 2019//
+/pwd.h/1.26/Thu Sep 13 12:31:15 2018//
+/ranlib.h/1.3/Mon Jun 2 19:34:12 2003//
+/readpassphrase.h/1.6/Fri Jan 25 00:19:25 2019//
+/regex.h/1.7/Wed Dec 5 23:19:57 2012//
+/resolv.h/1.22/Mon Jan 14 06:23:06 2019//
+/rmd160.h/1.17/Wed Dec 5 23:19:57 2012//
+/sched.h/1.1/Sun Oct 15 23:40:33 2017//
+/search.h/1.10/Fri Jul 18 04:16:09 2014//
+/semaphore.h/1.1/Sun Oct 15 23:40:33 2017//
+/setjmp.h/1.7/Mon May 23 00:18:56 2016//
+/sha1.h/1.24/Wed Dec 5 23:19:57 2012//
+/sha2.h/1.10/Sat Sep 3 17:00:29 2016//
+/signal.h/1.26/Wed May 30 13:20:38 2018//
+/siphash.h/1.3/Fri Feb 20 11:51:03 2015//
+/sndio.h/1.10/Wed Feb 26 13:53:58 2020//
+/spawn.h/1.3/Wed May 20 22:50:07 2015//
+/stdbool.h/1.7/Fri Sep 4 23:47:09 2015//
+/stddef.h/1.14/Fri Jan 6 14:36:50 2017//
+/stdio.h/1.53/Fri Sep 9 18:12:37 2016//
+/stdlib.h/1.76/Fri May 10 15:03:24 2019//
+/string.h/1.32/Tue Sep 5 03:16:13 2017//
+/strings.h/1.6/Sun Sep 10 21:50:36 2017//
+/sysexits.h/1.5/Mon Jun 2 19:34:12 2003//
+/tar.h/1.3/Thu Jun 26 05:42:04 2008//
+/tgmath.h/1.1/Fri Jul 8 19:28:06 2011//
+/tib.h/1.7/Fri May 10 13:29:21 2019//
+/time.h/1.31/Tue Oct 30 16:28:42 2018//
+/ttyent.h/1.4/Mon Jun 2 19:34:12 2003//
+/unistd.h/1.106/Fri Jul 13 09:25:22 2018//
+/utime.h/1.7/Tue Apr 2 05:16:14 2013//
+/utmp.h/1.6/Wed Jan 8 06:50:57 2014//
+/uuid.h/1.1/Sun Aug 31 09:36:36 2014//
+/vis.h/1.15/Mon Jul 20 01:52:27 2015//
+/wchar.h/1.31/Tue Sep 5 03:16:13 2017//
+/wctype.h/1.6/Tue Sep 5 03:16:13 2017//
+D/arpa////
+D/protocols////
+D/rpc////
+D/rpcsvc////
diff --git a/include/CVS/Repository b/include/CVS/Repository
new file mode 100644
index 0000000..e4484e2
--- /dev/null
+++ b/include/CVS/Repository
@@ -0,0 +1 @@
+src/include
diff --git a/include/CVS/Root b/include/CVS/Root
new file mode 100644
index 0000000..3811072
--- /dev/null
+++ b/include/CVS/Root
@@ -0,0 +1 @@
+/cvs
diff --git a/include/Makefile b/include/Makefile
new file mode 100644
index 0000000..30d4f65
--- /dev/null
+++ b/include/Makefile
@@ -0,0 +1,163 @@
+# $OpenBSD: Makefile,v 1.226 2019/11/14 21:14:53 djm Exp $
+# $NetBSD: Makefile,v 1.59 1996/05/15 21:36:43 jtc Exp $
+
+# @(#)Makefile 5.45.1.1 (Berkeley) 5/6/91
+
+# The ``rm -rf''s used below are safe because rm doesn't follow symbolic
+# links.
+
+
+.include <bsd.own.mk>
+
+FILES= a.out.h ar.h asr.h assert.h \
+ bitstring.h blf.h bsd_auth.h \
+ complex.h cpio.h ctype.h curses.h \
+ db.h dirent.h disktab.h dlfcn.h \
+ elf.h elf_abi.h err.h errno.h \
+ fenv.h float.h fnmatch.h fstab.h fts.h ftw.h \
+ getopt.h glob.h grp.h \
+ icdb.h ieeefp.h ifaddrs.h inttypes.h iso646.h \
+ kvm.h \
+ langinfo.h libgen.h limits.h link.h link_elf.h locale.h login_cap.h \
+ math.h md5.h memory.h \
+ ndbm.h netdb.h netgroup.h nlist.h nl_types.h \
+ paths.h poll.h pthread.h pthread_np.h pwd.h \
+ ranlib.h readpassphrase.h regex.h resolv.h rmd160.h \
+ sched.h search.h setjmp.h semaphore.h sha1.h sha2.h \
+ signal.h siphash.h sndio.h spawn.h stdbool.h stddef.h \
+ stdio.h stdlib.h string.h strings.h sysexits.h \
+ tar.h tgmath.h tib.h time.h ttyent.h \
+ unistd.h utime.h utmp.h uuid.h \
+ vis.h \
+ wchar.h wctype.h
+
+MFILES= frame.h
+LFILES= endian.h fcntl.h syslog.h termios.h stdarg.h stdint.h varargs.h
+
+DIRS= arpa protocols rpc rpcsvc
+LDIRS= crypto ddb dev isofs miscfs msdosfs net netinet netinet6 \
+ netmpls net80211 nfs ntfs scsi sys ufs uvm
+
+# Places that need a prerequisite target met before includes
+PRDIRS= ../lib/libcrypto ../lib/librpcsvc
+
+# Directories with an includes target
+RDIRS= ../lib/libcbor ../lib/libcurses ../lib/libedit ../lib/libelf \
+ ../lib/libevent ../lib/libexpat ../lib/libfido2 ../lib/libform \
+ ../lib/libfuse ../lib/libkeynote ../lib/libmenu \
+ ../lib/libossaudio ../lib/libpanel ../lib/libpcap \
+ ../lib/libradius \
+ ../lib/libskey ../lib/libssl ../lib/libtls \
+ ../lib/libusbhid ../lib/libutil ../lib/libz \
+ ../usr.bin/lex ../gnu/lib/libreadline \
+ ../sys/arch/${MACHINE}
+
+.if ${BUILD_GCC3:L} == "yes"
+RDIRS+= ../gnu/usr.bin/gcc
+PRDIRS+= ../gnu/lib/libstdc++
+.endif
+.if ${BUILD_GCC4:L} == "yes"
+PRDIRS+= ../gnu/lib/libstdc++-v3 ../gnu/usr.bin/cc/include
+.endif
+.if ${BUILD_CLANG:L} == "yes"
+RDIRS+= ../lib/libcxxabi ../lib/libcxx \
+ ../gnu/usr.bin/clang/libLLVM
+.endif
+
+# prereq implies includes
+RDIRS += ${PRDIRS}
+
+NOOBJ= noobj
+
+# Change SYS_INCLUDE in bsd.own.mk to "symlinks" if you don't want copies
+SYS_INCLUDE?= copies
+
+RUN_MAKE = if test -f Makefile.bsd-wrapper; then ${MAKE} -f Makefile.bsd-wrapper $@; else ${MAKE} $@; fi
+
+prereq:
+ @for i in ${PRDIRS}; do \
+ echo preparing in ${.CURDIR}/$$i; \
+ cd ${.CURDIR}/$$i && ${RUN_MAKE}; \
+ done
+
+includes:
+ @echo installing ${FILES}
+ @for i in ${FILES}; do \
+ cmp -s $$i ${DESTDIR}/usr/include/$$i || \
+ ${INSTALL} ${INSTALL_COPY} -m 444 $$i ${DESTDIR}/usr/include/$$i; \
+ done
+ @echo installing ${DIRS}
+ @for i in ${DIRS}; do \
+ ${INSTALL} -d -o ${BINOWN} -g ${BINGRP} -m 755 \
+ ${DESTDIR}/usr/include/$$i; \
+ cd ${.CURDIR}/$$i && for j in *.[ih]; do \
+ cmp -s $$j ${DESTDIR}/usr/include/$$i/$$j || \
+ ${INSTALL} ${INSTALL_COPY} -m 444 $$j ${DESTDIR}/usr/include/$$i/$$j; \
+ done; \
+ done
+ @echo installing ${LFILES}
+ @for i in ${LFILES}; do \
+ rm -f ${DESTDIR}/usr/include/$$i && \
+ ln -s sys/$$i ${DESTDIR}/usr/include/$$i; \
+ done
+ @echo installing ${MFILES}
+ @for i in ${MFILES}; do \
+ rm -f ${DESTDIR}/usr/include/$$i && \
+ ln -s machine/$$i ${DESTDIR}/usr/include/$$i; \
+ done
+ @for i in ${RDIRS}; do \
+ echo installing in ${.CURDIR}/$$i; \
+ cd ${.CURDIR}/$$i && ${RUN_MAKE}; \
+ done
+ chown -RP ${BINOWN}:${BINGRP} ${DESTDIR}/usr/include
+ find ${DESTDIR}/usr/include \
+ -type f -exec chmod a=r {} + -o \
+ \( -type d -o -type l \) -exec chmod -h u=rwx,go=rx {} +
+
+copies:
+ @echo copies: ${LDIRS}
+ @for i in ${LDIRS}; do \
+ rm -rf ${DESTDIR}/usr/include/$$i && \
+ ${INSTALL} -d -o ${BINOWN} -g ${BINGRP} -m 755 \
+ ${DESTDIR}/usr/include/$$i ; \
+ done
+ cd ../sys; \
+ pax -rw -pa -L \
+ `find ${LDIRS} -follow -type f -name '*.h' '!' \
+ '(' -path 'dev/microcode/*' -or -path 'dev/pci/drm/*' ')' \
+ -print` ${DESTDIR}/usr/include
+ cd ${DESTDIR}/usr/include && rm -rf ${MACHINE} ${MACHINE_CPU} machine
+ ${INSTALL} -d -o ${BINOWN} -g ${BINGRP} -m 755 \
+ ${DESTDIR}/usr/include/${MACHINE}
+ pax -rw -pa -s "|\.\./sys/arch/${MACHINE}/include||" \
+ ../sys/arch/${MACHINE}/include/*.h \
+ ${DESTDIR}/usr/include/${MACHINE}
+ if test ${MACHINE} != ${MACHINE_CPU} -a \
+ -d ../sys/arch/${MACHINE_CPU}/include; then \
+ ${INSTALL} -d -o ${BINOWN} -g ${BINGRP} -m 755 \
+ ${DESTDIR}/usr/include/${MACHINE_CPU}; \
+ pax -rw -pa -s "|\.\./sys/arch/${MACHINE_CPU}/include||" \
+ ../sys/arch/${MACHINE_CPU}/include/*.h \
+ ${DESTDIR}/usr/include/${MACHINE_CPU}; \
+ fi
+ ln -sf ${MACHINE} ${DESTDIR}/usr/include/machine; \
+
+symlinks:
+ @echo symlinks: ${LDIRS}
+ @for i in ${LDIRS}; do \
+ rm -rf ${DESTDIR}/usr/include/$$i && \
+ ln -s /sys/$$i ${DESTDIR}/usr/include/$$i; \
+ done
+ cd ${DESTDIR}/usr/include && rm -rf ${MACHINE} ${MACHINE_CPU} machine
+ ln -s /sys/arch/${MACHINE}/include ${DESTDIR}/usr/include/${MACHINE}
+ if test ${MACHINE} != ${MACHINE_CPU} -a \
+ -d ../sys/arch/${MACHINE_CPU}/include ; then \
+ ln -s /sys/arch/${MACHINE_CPU}/include \
+ ${DESTDIR}/usr/include/${MACHINE_CPU} ; \
+ fi
+ ln -sf ${MACHINE} ${DESTDIR}/usr/include/machine
+
+includes: ${SYS_INCLUDE}
+
+.PHONY: prereq includes copies symlink
+.include <bsd.prog.mk>
diff --git a/include/a.out.h b/include/a.out.h
new file mode 100644
index 0000000..8191d17
--- /dev/null
+++ b/include/a.out.h
@@ -0,0 +1,44 @@
+/* $OpenBSD: a.out.h,v 1.3 2003/06/02 19:34:12 millert Exp $ */
+/* $NetBSD: a.out.h,v 1.15 1994/10/26 00:55:42 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1993 Theo de Raadt
+ * Copyright (c) 1991 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.
+ *
+ * @(#)a.out.h 5.6 (Berkeley) 4/30/91
+ */
+
+#ifndef _AOUT_H_
+#define _AOUT_H_
+
+#include <sys/exec.h>
+
+#define _AOUT_INCLUDE_
+#include <nlist.h>
+
+#endif /* !_AOUT_H_ */
diff --git a/include/ar.h b/include/ar.h
new file mode 100644
index 0000000..835290b
--- /dev/null
+++ b/include/ar.h
@@ -0,0 +1,66 @@
+/* $OpenBSD: ar.h,v 1.3 2003/06/02 19:34:12 millert Exp $ */
+/* $NetBSD: ar.h,v 1.4 1994/10/26 00:55:43 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Hugh Smith at The University of Guelph.
+ *
+ * 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.
+ *
+ * @(#)ar.h 8.2 (Berkeley) 1/21/94
+ */
+
+#ifndef _AR_H_
+#define _AR_H_
+
+/* Pre-4BSD archives had these magic numbers in them. */
+#define OARMAG1 0177555
+#define OARMAG2 0177545
+
+#define ARMAG "!<arch>\n" /* ar "magic number" */
+#define SARMAG 8 /* strlen(ARMAG); */
+
+#define AR_EFMT1 "#1/" /* extended format #1 */
+
+struct ar_hdr {
+ char ar_name[16]; /* name */
+ char ar_date[12]; /* modification time */
+ char ar_uid[6]; /* user id */
+ char ar_gid[6]; /* group id */
+ char ar_mode[8]; /* octal file permissions */
+ char ar_size[10]; /* size in bytes */
+#define ARFMAG "`\n"
+ char ar_fmag[2]; /* consistency check */
+};
+
+#endif /* !_AR_H_ */
diff --git a/include/arpa/CVS/Entries b/include/arpa/CVS/Entries
new file mode 100644
index 0000000..386f7f7
--- /dev/null
+++ b/include/arpa/CVS/Entries
@@ -0,0 +1,6 @@
+/ftp.h/1.3/Mon Jun 2 19:34:12 2003//
+/inet.h/1.21/Sat Feb 4 19:16:25 2017//
+/nameser.h/1.14/Fri Mar 16 12:31:09 2018//
+/telnet.h/1.7/Mon Jun 2 19:34:12 2003//
+/tftp.h/1.8/Wed Jul 26 16:43:30 2006//
+D
diff --git a/include/arpa/CVS/Repository b/include/arpa/CVS/Repository
new file mode 100644
index 0000000..f62618c
--- /dev/null
+++ b/include/arpa/CVS/Repository
@@ -0,0 +1 @@
+src/include/arpa
diff --git a/include/arpa/CVS/Root b/include/arpa/CVS/Root
new file mode 100644
index 0000000..3811072
--- /dev/null
+++ b/include/arpa/CVS/Root
@@ -0,0 +1 @@
+/cvs
diff --git a/include/arpa/ftp.h b/include/arpa/ftp.h
new file mode 100644
index 0000000..90703ba
--- /dev/null
+++ b/include/arpa/ftp.h
@@ -0,0 +1,108 @@
+/* $OpenBSD: ftp.h,v 1.3 2003/06/02 19:34:12 millert Exp $ */
+/* $NetBSD: ftp.h,v 1.3 1994/10/26 00:56:43 cgd Exp $ */
+
+/*
+ * Copyright (c) 1983, 1989 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.
+ *
+ * @(#)ftp.h 5.6 (Berkeley) 4/3/91
+ */
+
+#ifndef _FTP_H_
+#define _FTP_H_
+
+/* Definitions for FTP; see RFC-765. */
+
+/*
+ * Reply codes.
+ */
+#define PRELIM 1 /* positive preliminary */
+#define COMPLETE 2 /* positive completion */
+#define CONTINUE 3 /* positive intermediate */
+#define TRANSIENT 4 /* transient negative completion */
+#define ERROR 5 /* permanent negative completion */
+
+/*
+ * Type codes
+ */
+#define TYPE_A 1 /* ASCII */
+#define TYPE_E 2 /* EBCDIC */
+#define TYPE_I 3 /* image */
+#define TYPE_L 4 /* local byte size */
+
+#ifdef FTP_NAMES
+char *typenames[] = {"0", "ASCII", "EBCDIC", "Image", "Local" };
+#endif
+
+/*
+ * Form codes
+ */
+#define FORM_N 1 /* non-print */
+#define FORM_T 2 /* telnet format effectors */
+#define FORM_C 3 /* carriage control (ASA) */
+#ifdef FTP_NAMES
+char *formnames[] = {"0", "Nonprint", "Telnet", "Carriage-control" };
+#endif
+
+/*
+ * Structure codes
+ */
+#define STRU_F 1 /* file (no record structure) */
+#define STRU_R 2 /* record structure */
+#define STRU_P 3 /* page structure */
+#ifdef FTP_NAMES
+char *strunames[] = {"0", "File", "Record", "Page" };
+#endif
+
+/*
+ * Mode types
+ */
+#define MODE_S 1 /* stream */
+#define MODE_B 2 /* block */
+#define MODE_C 3 /* compressed */
+#ifdef FTP_NAMES
+char *modenames[] = {"0", "Stream", "Block", "Compressed" };
+#endif
+
+/*
+ * Record Tokens
+ */
+#define REC_ESC '\377' /* Record-mode Escape */
+#define REC_EOR '\001' /* Record-mode End-of-Record */
+#define REC_EOF '\002' /* Record-mode End-of-File */
+
+/*
+ * Block Header
+ */
+#define BLK_EOR 0x80 /* Block is End-of-Record */
+#define BLK_EOF 0x40 /* Block is End-of-File */
+#define BLK_ERRORS 0x20 /* Block is suspected of containing errors */
+#define BLK_RESTART 0x10 /* Block is Restart Marker */
+
+#define BLK_BYTECOUNT 2 /* Bytes in this block */
+
+#endif /* !_FTP_H_ */
diff --git a/include/arpa/inet.h b/include/arpa/inet.h
new file mode 100644
index 0000000..8d6ac63
--- /dev/null
+++ b/include/arpa/inet.h
@@ -0,0 +1,147 @@
+/* $OpenBSD: inet.h,v 1.21 2017/02/04 19:16:25 guenther Exp $ */
+
+/*
+ * ++Copyright++ 1983, 1993
+ * -
+ * Copyright (c) 1983, 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.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * 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, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION 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.
+ * -
+ * --Copyright--
+ */
+
+/*
+ * @(#)inet.h 8.1 (Berkeley) 6/2/93
+ * $From: inet.h,v 8.6 1996/08/08 06:54:29 vixie Exp $
+ */
+
+#ifndef _INET_H_
+#define _INET_H_
+
+/* External definitions for functions in inet(3) */
+
+#include <sys/cdefs.h>
+#include <sys/_endian.h>
+
+#ifndef htons
+#define htons(x) __htobe16(x)
+#define htonl(x) __htobe32(x)
+#define ntohs(x) __htobe16(x)
+#define ntohl(x) __htobe32(x)
+#endif
+
+#ifndef _UINT16_T_DEFINED_
+#define _UINT16_T_DEFINED_
+typedef __uint16_t uint16_t;
+#endif
+
+#ifndef _UINT32_T_DEFINED_
+#define _UINT32_T_DEFINED_
+typedef __uint32_t uint32_t;
+#endif
+
+#ifndef _SOCKLEN_T_DEFINED_
+#define _SOCKLEN_T_DEFINED_
+typedef __socklen_t socklen_t; /* length type for network syscalls */
+#endif
+
+#ifndef _IN_TYPES_DEFINED_
+#define _IN_TYPES_DEFINED_
+typedef __in_addr_t in_addr_t; /* base type for internet address */
+typedef __in_port_t in_port_t; /* IP port type */
+#endif
+
+/*
+ * Buffer lengths for strings containing printable IP addresses
+ */
+#ifndef INET_ADDRSTRLEN
+#define INET_ADDRSTRLEN 16
+#endif
+#ifndef INET6_ADDRSTRLEN
+#define INET6_ADDRSTRLEN 46
+#endif
+
+#ifndef _IN_ADDR_DECLARED
+#define _IN_ADDR_DECLARED
+/*
+ * IP Version 4 Internet address (a structure for historical reasons)
+ */
+struct in_addr {
+ in_addr_t s_addr;
+};
+#endif
+
+
+#if __BSD_VISIBLE
+/* need this for the non-standard stuff */
+#ifndef _SIZE_T_DEFINED_
+#define _SIZE_T_DEFINED_
+typedef __size_t size_t;
+#endif
+#endif
+
+
+__BEGIN_DECLS
+in_addr_t inet_addr(const char *);
+char *inet_ntoa(struct in_addr);
+const char *inet_ntop(int, const void *__restrict, char *__restrict,
+ socklen_t) __attribute__ ((__bounded__(__string__,3,4)));
+int inet_pton(int, const char *__restrict, void *__restrict);
+
+#if __BSD_VISIBLE
+int inet_aton(const char *, struct in_addr *);
+in_addr_t inet_lnaof(struct in_addr);
+struct in_addr inet_makeaddr(in_addr_t , in_addr_t);
+char * inet_neta(in_addr_t, char *, size_t)
+ __attribute__((__bounded__(__string__,2,3)));
+in_addr_t inet_netof(struct in_addr);
+in_addr_t inet_network(const char *);
+char *inet_net_ntop(int, const void *, int, char *, size_t)
+ __attribute__((__bounded__(__string__,4,5)));
+int inet_net_pton(int, const char *, void *, size_t)
+ __attribute__((__bounded__(__string__,3,4)));
+#endif /* __BSD_VISIBLE */
+__END_DECLS
+
+#endif /* !_INET_H_ */
diff --git a/include/arpa/nameser.h b/include/arpa/nameser.h
new file mode 100644
index 0000000..ead11b7
--- /dev/null
+++ b/include/arpa/nameser.h
@@ -0,0 +1,369 @@
+/* $OpenBSD: nameser.h,v 1.14 2018/03/16 12:31:09 mpi Exp $ */
+
+/*
+ * ++Copyright++ 1983, 1989, 1993
+ * -
+ * Copyright (c) 1983, 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.
+ * 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.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * 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, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION 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.
+ * -
+ * Portions Copyright (c) 1995 by International Business Machines, Inc.
+ *
+ * International Business Machines, Inc. (hereinafter called IBM) grants
+ * permission under its copyrights to use, copy, modify, and distribute this
+ * Software with or without fee, provided that the above copyright notice and
+ * all paragraphs of this notice appear in all copies, and that the name of IBM
+ * not be used in connection with the marketing of any product incorporating
+ * the Software or modifications thereof, without specific, written prior
+ * permission.
+ *
+ * To the extent it has a right to do so, IBM grants an immunity from suit
+ * under its patents, if any, for the use, sale or manufacture of products to
+ * the extent that such products are used for performing Domain Name System
+ * dynamic updates in TCP/IP networks by means of the Software. No immunity is
+ * granted for any product per se or for any other function of any product.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
+ * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
+ * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ * --Copyright--
+ */
+
+/*
+ * @(#)nameser.h 8.1 (Berkeley) 6/2/93
+ * $From: nameser.h,v 8.11 1996/10/08 04:51:02 vixie Exp $
+ */
+
+#ifndef _NAMESER_H_
+#define _NAMESER_H_
+
+#include <sys/types.h>
+
+/*
+ * revision information. this is the release date in YYYYMMDD format.
+ * it can change every day so the right thing to do with it is use it
+ * in preprocessor commands such as "#if (__BIND > 19931104)". do not
+ * compare for equality; rather, use it to determine whether your resolver
+ * is new enough to contain a certain feature.
+ */
+
+#define __BIND 19960801 /* interface version stamp */
+
+/*
+ * Define constants based on rfc883
+ */
+#define PACKETSZ 512 /* maximum packet size */
+#define MAXDNAME 1025 /* maximum presentation domain name */
+#define MAXCDNAME 255 /* maximum compressed domain name */
+#define MAXLABEL 63 /* maximum length of domain label */
+#define HFIXEDSZ 12 /* #/bytes of fixed data in header */
+#define QFIXEDSZ 4 /* #/bytes of fixed data in query */
+#define RRFIXEDSZ 10 /* #/bytes of fixed data in r record */
+#define INT32SZ 4 /* for systems without 32-bit ints */
+#define INT16SZ 2 /* for systems without 16-bit ints */
+#define INADDRSZ 4 /* IPv4 T_A */
+#define IN6ADDRSZ 16 /* IPv6 T_AAAA */
+
+/*
+ * Internet nameserver port number
+ */
+#define NAMESERVER_PORT 53
+
+/*
+ * Currently defined opcodes
+ */
+#define QUERY 0x0 /* standard query */
+#define IQUERY 0x1 /* inverse query */
+#define STATUS 0x2 /* nameserver status query */
+/*#define xxx 0x3*/ /* 0x3 reserved */
+#define NS_NOTIFY_OP 0x4 /* notify secondary of SOA change */
+/*
+ * Currently defined response codes
+ */
+#define NOERROR 0 /* no error */
+#define FORMERR 1 /* format error */
+#define SERVFAIL 2 /* server failure */
+#define NXDOMAIN 3 /* non existent domain */
+#define NOTIMP 4 /* not implemented */
+#define REFUSED 5 /* query refused */
+
+/*
+ * Type values for resources and queries
+ */
+#define T_A 1 /* host address */
+#define T_NS 2 /* authoritative server */
+#define T_MD 3 /* mail destination */
+#define T_MF 4 /* mail forwarder */
+#define T_CNAME 5 /* canonical name */
+#define T_SOA 6 /* start of authority zone */
+#define T_MB 7 /* mailbox domain name */
+#define T_MG 8 /* mail group member */
+#define T_MR 9 /* mail rename name */
+#define T_NULL 10 /* null resource record */
+#define T_WKS 11 /* well known service */
+#define T_PTR 12 /* domain name pointer */
+#define T_HINFO 13 /* host information */
+#define T_MINFO 14 /* mailbox information */
+#define T_MX 15 /* mail routing information */
+#define T_TXT 16 /* text strings */
+#define T_RP 17 /* responsible person */
+#define T_AFSDB 18 /* AFS cell database */
+#define T_X25 19 /* X_25 calling address */
+#define T_ISDN 20 /* ISDN calling address */
+#define T_RT 21 /* router */
+#define T_NSAP 22 /* NSAP address */
+#define T_NSAP_PTR 23 /* reverse NSAP lookup (deprecated) */
+#define T_SIG 24 /* security signature */
+#define T_KEY 25 /* security key */
+#define T_PX 26 /* X.400 mail mapping */
+#define T_GPOS 27 /* geographical position (withdrawn) */
+#define T_AAAA 28 /* IP6 Address */
+#define T_LOC 29 /* Location Information */
+#define T_NXT 30 /* Next Valid Name in Zone */
+#define T_EID 31 /* Endpoint identifier */
+#define T_NIMLOC 32 /* Nimrod locator */
+#define T_SRV 33 /* Server selection */
+#define T_ATMA 34 /* ATM Address */
+#define T_NAPTR 35 /* Naming Authority PoinTeR */
+#define T_KX 36 /* Key Exchanger */
+#define T_CERT 37 /* CERT */
+#define T_A6 38 /* A6 */
+#define T_DNAME 39 /* DNAME */
+#define T_SINK 40 /* SINK */
+#define T_OPT 41 /* OPT pseudo-RR, RFC2671 */
+#define T_APL 42 /* APL */
+#define T_DS 43 /* Delegation Signer */
+#define T_SSHFP 44 /* SSH Key Fingerprint */
+#define T_RRSIG 46 /* RRSIG */
+#define T_NSEC 47 /* NSEC */
+#define T_DNSKEY 48 /* DNSKEY */
+ /* non standard */
+#define T_UINFO 100 /* user (finger) information */
+#define T_UID 101 /* user ID */
+#define T_GID 102 /* group ID */
+#define T_UNSPEC 103 /* Unspecified format (binary data) */
+ /* Query type values which do not appear in resource records */
+#define T_TKEY 249 /* Transaction Key */
+#define T_TSIG 250 /* Transaction Signature */
+#define T_IXFR 251 /* incremental zone transfer */
+#define T_AXFR 252 /* transfer zone of authority */
+#define T_MAILB 253 /* transfer mailbox records */
+#define T_MAILA 254 /* transfer mail agent records */
+#define T_ANY 255 /* wildcard match */
+
+/*
+ * Values for class field
+ */
+
+#define C_IN 1 /* the arpa internet */
+#define C_CHAOS 3 /* for chaos net (MIT) */
+#define C_HS 4 /* for Hesiod name server (MIT) (XXX) */
+ /* Query class values which do not appear in resource records */
+#define C_ANY 255 /* wildcard match */
+
+/*
+ * Flags field of the KEY RR rdata
+ */
+#define KEYFLAG_TYPEMASK 0xC000 /* Mask for "type" bits */
+#define KEYFLAG_TYPE_AUTH_CONF 0x0000 /* Key usable for both */
+#define KEYFLAG_TYPE_CONF_ONLY 0x8000 /* Key usable for confidentiality */
+#define KEYFLAG_TYPE_AUTH_ONLY 0x4000 /* Key usable for authentication */
+#define KEYFLAG_TYPE_NO_KEY 0xC000 /* No key usable for either; no key */
+/* The type bits can also be interpreted independently, as single bits: */
+#define KEYFLAG_NO_AUTH 0x8000 /* Key not usable for authentication */
+#define KEYFLAG_NO_CONF 0x4000 /* Key not usable for confidentiality */
+
+#define KEYFLAG_EXPERIMENTAL 0x2000 /* Security is *mandatory* if bit=0 */
+#define KEYFLAG_RESERVED3 0x1000 /* reserved - must be zero */
+#define KEYFLAG_RESERVED4 0x0800 /* reserved - must be zero */
+#define KEYFLAG_USERACCOUNT 0x0400 /* key is assoc. with a user acct */
+#define KEYFLAG_ENTITY 0x0200 /* key is assoc. with entity eg host */
+#define KEYFLAG_ZONEKEY 0x0100 /* key is zone key for the zone named */
+#define KEYFLAG_IPSEC 0x0080 /* key is for IPsec use (host or user)*/
+#define KEYFLAG_EMAIL 0x0040 /* key is for email (MIME security) */
+#define KEYFLAG_RESERVED10 0x0020 /* reserved - must be zero */
+#define KEYFLAG_RESERVED11 0x0010 /* reserved - must be zero */
+#define KEYFLAG_SIGNATORYMASK 0x000F /* key can sign DNS RR's of same name */
+
+#define KEYFLAG_RESERVED_BITMASK ( KEYFLAG_RESERVED3 | \
+ KEYFLAG_RESERVED4 | \
+ KEYFLAG_RESERVED10| KEYFLAG_RESERVED11)
+
+/* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */
+#define ALGORITHM_MD5RSA 1 /* MD5 with RSA */
+#define ALGORITHM_EXPIRE_ONLY 253 /* No alg, no security */
+#define ALGORITHM_PRIVATE_OID 254 /* Key begins with OID indicating alg */
+
+/* Signatures */
+ /* Size of a mod or exp in bits */
+#define MIN_MD5RSA_KEY_PART_BITS 512
+#define MAX_MD5RSA_KEY_PART_BITS 2552
+ /* Total of binary mod and exp, bytes */
+#define MAX_MD5RSA_KEY_BYTES ((MAX_MD5RSA_KEY_PART_BITS+7/8)*2+3)
+ /* Max length of text sig block */
+#define MAX_KEY_BASE64 (((MAX_MD5RSA_KEY_BYTES+2)/3)*4)
+
+/*
+ * EDNS0 Z-field extended flags
+ */
+#define DNS_MESSAGEEXTFLAG_DO 0x8000U
+
+/*
+ * Status return codes for T_UNSPEC conversion routines
+ */
+#define CONV_SUCCESS 0
+#define CONV_OVERFLOW (-1)
+#define CONV_BADFMT (-2)
+#define CONV_BADCKSUM (-3)
+#define CONV_BADBUFLEN (-4)
+
+#if !defined(_BYTE_ORDER) || \
+ (_BYTE_ORDER != _BIG_ENDIAN && _BYTE_ORDER != _LITTLE_ENDIAN && \
+ _BYTE_ORDER != _PDP_ENDIAN)
+ /* you must determine what the correct bit order is for
+ * your compiler - the next line is an intentional error
+ * which will force your compiles to bomb until you fix
+ * the above macros.
+ */
+#error "Undefined or invalid _BYTE_ORDER";
+#endif
+
+/*
+ * Structure for query header. The order of the fields is machine- and
+ * compiler-dependent, depending on the byte/bit order and the layout
+ * of bit fields. We use bit fields only in int variables, as this
+ * is all ANSI requires. This requires a somewhat confusing rearrangement.
+ */
+
+typedef struct {
+ unsigned id :16; /* query identification number */
+#if _BYTE_ORDER == _BIG_ENDIAN
+ /* fields in third byte */
+ unsigned qr: 1; /* response flag */
+ unsigned opcode: 4; /* purpose of message */
+ unsigned aa: 1; /* authoritive answer */
+ unsigned tc: 1; /* truncated message */
+ unsigned rd: 1; /* recursion desired */
+ /* fields in fourth byte */
+ unsigned ra: 1; /* recursion available */
+ unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */
+ unsigned ad: 1; /* authentic data from named */
+ unsigned cd: 1; /* checking disabled by resolver */
+ unsigned rcode :4; /* response code */
+#endif
+#if _BYTE_ORDER == _LITTLE_ENDIAN || _BYTE_ORDER == _PDP_ENDIAN
+ /* fields in third byte */
+ unsigned rd :1; /* recursion desired */
+ unsigned tc :1; /* truncated message */
+ unsigned aa :1; /* authoritive answer */
+ unsigned opcode :4; /* purpose of message */
+ unsigned qr :1; /* response flag */
+ /* fields in fourth byte */
+ unsigned rcode :4; /* response code */
+ unsigned cd: 1; /* checking disabled by resolver */
+ unsigned ad: 1; /* authentic data from named */
+ unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */
+ unsigned ra :1; /* recursion available */
+#endif
+ /* remaining bytes */
+ unsigned qdcount :16; /* number of question entries */
+ unsigned ancount :16; /* number of answer entries */
+ unsigned nscount :16; /* number of authority entries */
+ unsigned arcount :16; /* number of resource entries */
+} HEADER;
+
+/*
+ * Defines for handling compressed domain names
+ */
+#define INDIR_MASK 0xc0
+
+extern u_int16_t _getshort(const unsigned char *);
+extern u_int32_t _getlong(const unsigned char *);
+
+/*
+ * Inline versions of get/put short/long. Pointer is advanced.
+ *
+ * These macros demonstrate the property of C whereby it can be
+ * portable or it can be elegant but rarely both.
+ */
+#define GETSHORT(s, cp) { \
+ unsigned char *t_cp = (unsigned char *)(cp); \
+ (s) = ((u_int16_t)t_cp[0] << 8) \
+ | ((u_int16_t)t_cp[1]) \
+ ; \
+ (cp) += INT16SZ; \
+}
+
+#define GETLONG(l, cp) { \
+ unsigned char *t_cp = (unsigned char *)(cp); \
+ (l) = ((u_int32_t)t_cp[0] << 24) \
+ | ((u_int32_t)t_cp[1] << 16) \
+ | ((u_int32_t)t_cp[2] << 8) \
+ | ((u_int32_t)t_cp[3]) \
+ ; \
+ (cp) += INT32SZ; \
+}
+
+#define PUTSHORT(s, cp) { \
+ u_int16_t t_s = (u_int16_t)(s); \
+ unsigned char *t_cp = (unsigned char *)(cp); \
+ *t_cp++ = t_s >> 8; \
+ *t_cp = t_s; \
+ (cp) += INT16SZ; \
+}
+
+#define PUTLONG(l, cp) { \
+ u_int32_t t_l = (u_int32_t)(l); \
+ unsigned char *t_cp = (unsigned char *)(cp); \
+ *t_cp++ = t_l >> 24; \
+ *t_cp++ = t_l >> 16; \
+ *t_cp++ = t_l >> 8; \
+ *t_cp = t_l; \
+ (cp) += INT32SZ; \
+}
+
+#endif /* !_NAMESER_H_ */
diff --git a/include/arpa/telnet.h b/include/arpa/telnet.h
new file mode 100644
index 0000000..f8c0cf4
--- /dev/null
+++ b/include/arpa/telnet.h
@@ -0,0 +1,339 @@
+/* $OpenBSD: telnet.h,v 1.7 2003/06/02 19:34:12 millert Exp $ */
+/* $NetBSD: telnet.h,v 1.4 1994/10/26 00:56:46 cgd Exp $ */
+
+/*
+ * Copyright (c) 1983, 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.
+ *
+ * @(#)telnet.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _TELNET_H_
+#define _TELNET_H_
+
+/*
+ * Definitions for the TELNET protocol.
+ */
+#define IAC 255 /* interpret as command: */
+#define DONT 254 /* you are not to use option */
+#define DO 253 /* please, you use option */
+#define WONT 252 /* I won't use option */
+#define WILL 251 /* I will use option */
+#define SB 250 /* interpret as subnegotiation */
+#define GA 249 /* you may reverse the line */
+#define EL 248 /* erase the current line */
+#define EC 247 /* erase the current character */
+#define AYT 246 /* are you there */
+#define AO 245 /* abort output--but let prog finish */
+#define IP 244 /* interrupt process--permanently */
+#define BREAK 243 /* break */
+#define DM 242 /* data mark--for connect. cleaning */
+#define NOP 241 /* nop */
+#define SE 240 /* end sub negotiation */
+#define EOR 239 /* end of record (transparent mode) */
+#define ABORT 238 /* Abort process */
+#define SUSP 237 /* Suspend process */
+#define xEOF 236 /* End of file: EOF is already used... */
+
+#define SYNCH 242 /* for telfunc calls */
+
+#ifdef TELCMDS
+char *telcmds[] = {
+ "EOF", "SUSP", "ABORT", "EOR",
+ "SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC",
+ "EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC",
+ 0
+};
+#else
+extern char *telcmds[];
+#endif
+
+#define TELCMD_FIRST xEOF
+#define TELCMD_LAST IAC
+#define TELCMD_OK(x) ((unsigned int)(x) <= TELCMD_LAST && \
+ (unsigned int)(x) >= TELCMD_FIRST)
+#define TELCMD(x) telcmds[(x)-TELCMD_FIRST]
+
+/* telnet options */
+#define TELOPT_BINARY 0 /* 8-bit data path */
+#define TELOPT_ECHO 1 /* echo */
+#define TELOPT_RCP 2 /* prepare to reconnect */
+#define TELOPT_SGA 3 /* suppress go ahead */
+#define TELOPT_NAMS 4 /* approximate message size */
+#define TELOPT_STATUS 5 /* give status */
+#define TELOPT_TM 6 /* timing mark */
+#define TELOPT_RCTE 7 /* remote controlled transmission and echo */
+#define TELOPT_NAOL 8 /* negotiate about output line width */
+#define TELOPT_NAOP 9 /* negotiate about output page size */
+#define TELOPT_NAOCRD 10 /* negotiate about CR disposition */
+#define TELOPT_NAOHTS 11 /* negotiate about horizontal tabstops */
+#define TELOPT_NAOHTD 12 /* negotiate about horizontal tab disposition */
+#define TELOPT_NAOFFD 13 /* negotiate about formfeed disposition */
+#define TELOPT_NAOVTS 14 /* negotiate about vertical tab stops */
+#define TELOPT_NAOVTD 15 /* negotiate about vertical tab disposition */
+#define TELOPT_NAOLFD 16 /* negotiate about output LF disposition */
+#define TELOPT_XASCII 17 /* extended ascic character set */
+#define TELOPT_LOGOUT 18 /* force logout */
+#define TELOPT_BM 19 /* byte macro */
+#define TELOPT_DET 20 /* data entry terminal */
+#define TELOPT_SUPDUP 21 /* supdup protocol */
+#define TELOPT_SUPDUPOUTPUT 22 /* supdup output */
+#define TELOPT_SNDLOC 23 /* send location */
+#define TELOPT_TTYPE 24 /* terminal type */
+#define TELOPT_EOR 25 /* end or record */
+#define TELOPT_TUID 26 /* TACACS user identification */
+#define TELOPT_OUTMRK 27 /* output marking */
+#define TELOPT_TTYLOC 28 /* terminal location number */
+#define TELOPT_3270REGIME 29 /* 3270 regime */
+#define TELOPT_X3PAD 30 /* X.3 PAD */
+#define TELOPT_NAWS 31 /* window size */
+#define TELOPT_TSPEED 32 /* terminal speed */
+#define TELOPT_LFLOW 33 /* remote flow control */
+#define TELOPT_LINEMODE 34 /* Linemode option */
+#define TELOPT_XDISPLOC 35 /* X Display Location */
+#define TELOPT_OLD_ENVIRON 36 /* Old - Environment variables */
+#define TELOPT_AUTHENTICATION 37/* Authenticate */
+#define TELOPT_ENCRYPT 38 /* Encryption option */
+#define TELOPT_NEW_ENVIRON 39 /* New - Environment variables */
+#define TELOPT_EXOPL 255 /* extended-options-list */
+
+
+#define NTELOPTS (1+TELOPT_NEW_ENVIRON)
+#ifdef TELOPTS
+char *telopts[NTELOPTS+1] = {
+ "BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME",
+ "STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP",
+ "NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS",
+ "NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO",
+ "DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT",
+ "SEND LOCATION", "TERMINAL TYPE", "END OF RECORD",
+ "TACACS UID", "OUTPUT MARKING", "TTYLOC",
+ "3270 REGIME", "X.3 PAD", "NAWS", "TSPEED", "LFLOW",
+ "LINEMODE", "XDISPLOC", "OLD-ENVIRON", "AUTHENTICATION",
+ "ENCRYPT", "NEW-ENVIRON",
+ 0
+};
+#define TELOPT_FIRST TELOPT_BINARY
+#define TELOPT_LAST TELOPT_NEW_ENVIRON
+#define TELOPT_OK(x) ((unsigned int)(x) <= TELOPT_LAST)
+#define TELOPT(x) telopts[(x)-TELOPT_FIRST]
+#endif
+
+/* sub-option qualifiers */
+#define TELQUAL_IS 0 /* option is... */
+#define TELQUAL_SEND 1 /* send option */
+#define TELQUAL_INFO 2 /* ENVIRON: informational version of IS */
+#define TELQUAL_REPLY 2 /* AUTHENTICATION: client version of IS */
+#define TELQUAL_NAME 3 /* AUTHENTICATION: client version of IS */
+
+#define LFLOW_OFF 0 /* Disable remote flow control */
+#define LFLOW_ON 1 /* Enable remote flow control */
+#define LFLOW_RESTART_ANY 2 /* Restart output on any char */
+#define LFLOW_RESTART_XON 3 /* Restart output only on XON */
+
+/*
+ * LINEMODE suboptions
+ */
+
+#define LM_MODE 1
+#define LM_FORWARDMASK 2
+#define LM_SLC 3
+
+#define MODE_EDIT 0x01
+#define MODE_TRAPSIG 0x02
+#define MODE_ACK 0x04
+#define MODE_SOFT_TAB 0x08
+#define MODE_LIT_ECHO 0x10
+
+#define MODE_MASK 0x1f
+
+/* Not part of protocol, but needed to simplify things... */
+#define MODE_FLOW 0x0100
+#define MODE_ECHO 0x0200
+#define MODE_INBIN 0x0400
+#define MODE_OUTBIN 0x0800
+#define MODE_FORCE 0x1000
+
+#define SLC_SYNCH 1
+#define SLC_BRK 2
+#define SLC_IP 3
+#define SLC_AO 4
+#define SLC_AYT 5
+#define SLC_EOR 6
+#define SLC_ABORT 7
+#define SLC_EOF 8
+#define SLC_SUSP 9
+#define SLC_EC 10
+#define SLC_EL 11
+#define SLC_EW 12
+#define SLC_RP 13
+#define SLC_LNEXT 14
+#define SLC_XON 15
+#define SLC_XOFF 16
+#define SLC_FORW1 17
+#define SLC_FORW2 18
+#define SLC_MCL 19
+#define SLC_MCR 20
+#define SLC_MCWL 21
+#define SLC_MCWR 22
+#define SLC_MCBOL 23
+#define SLC_MCEOL 24
+#define SLC_INSRT 25
+#define SLC_OVER 26
+#define SLC_ECR 27
+#define SLC_EWR 28
+#define SLC_EBOL 29
+#define SLC_EEOL 30
+
+#define NSLC 30
+
+/*
+ * For backwards compatibility, we define SLC_NAMES to be the
+ * list of names if SLC_NAMES is not defined.
+ */
+#define SLC_NAMELIST "0", "SYNCH", "BRK", "IP", "AO", "AYT", "EOR", \
+ "ABORT", "EOF", "SUSP", "EC", "EL", "EW", "RP", \
+ "LNEXT", "XON", "XOFF", "FORW1", "FORW2", \
+ "MCL", "MCR", "MCWL", "MCWR", "MCBOL", \
+ "MCEOL", "INSRT", "OVER", "ECR", "EWR", \
+ "EBOL", "EEOL", \
+ 0
+
+#ifdef SLC_NAMES
+char *slc_names[] = {
+ SLC_NAMELIST
+};
+#else
+extern char *slc_names[];
+#define SLC_NAMES SLC_NAMELIST
+#endif
+
+#define SLC_NAME_OK(x) ((unsigned)(x) > 0 && (unsigned)(x) <= NSLC)
+#define SLC_NAME(x) slc_names[x]
+
+#define SLC_NOSUPPORT 0
+#define SLC_CANTCHANGE 1
+#define SLC_VARIABLE 2
+#define SLC_DEFAULT 3
+#define SLC_LEVELBITS 0x03
+
+#define SLC_FUNC 0
+#define SLC_FLAGS 1
+#define SLC_VALUE 2
+
+#define SLC_ACK 0x80
+#define SLC_FLUSHIN 0x40
+#define SLC_FLUSHOUT 0x20
+
+#define OLD_ENV_VAR 1
+#define OLD_ENV_VALUE 0
+#define NEW_ENV_VAR 0
+#define NEW_ENV_VALUE 1
+#define ENV_ESC 2
+#define ENV_USERVAR 3
+
+/*
+ * AUTHENTICATION suboptions
+ */
+
+/*
+ * Who is authenticating who ...
+ */
+#define AUTH_WHO_CLIENT 0 /* Client authenticating server */
+#define AUTH_WHO_SERVER 1 /* Server authenticating client */
+#define AUTH_WHO_MASK 1
+
+/*
+ * amount of authentication done
+ */
+#define AUTH_HOW_ONE_WAY 0
+#define AUTH_HOW_MUTUAL 2
+#define AUTH_HOW_MASK 2
+
+#define AUTHTYPE_NULL 0
+#define AUTHTYPE_KERBEROS_V4 1
+#define AUTHTYPE_KERBEROS_V5 2
+#define AUTHTYPE_SPX 3
+#define AUTHTYPE_MINK 4
+#define AUTHTYPE_CNT 5
+
+#define AUTHTYPE_TEST 99
+
+#ifdef AUTH_NAMES
+char *authtype_names[] = {
+ "NULL", "KERBEROS_V4", "KERBEROS_V5", "SPX", "MINK",
+ 0
+};
+#else
+extern char *authtype_names[];
+#endif
+
+#define AUTHTYPE_NAME_OK(x) ((unsigned int)(x) < AUTHTYPE_CNT)
+#define AUTHTYPE_NAME(x) authtype_names[x]
+
+/*
+ * ENCRYPTion suboptions
+ */
+#define ENCRYPT_IS 0 /* I pick encryption type ... */
+#define ENCRYPT_SUPPORT 1 /* I support encryption types ... */
+#define ENCRYPT_REPLY 2 /* Initial setup response */
+#define ENCRYPT_START 3 /* Am starting to send encrypted */
+#define ENCRYPT_END 4 /* Am ending encrypted */
+#define ENCRYPT_REQSTART 5 /* Request you start encrypting */
+#define ENCRYPT_REQEND 6 /* Request you end encrypting */
+#define ENCRYPT_ENC_KEYID 7
+#define ENCRYPT_DEC_KEYID 8
+#define ENCRYPT_CNT 9
+
+#define ENCTYPE_ANY 0
+#define ENCTYPE_DES_CFB64 1
+#define ENCTYPE_DES_OFB64 2
+#define ENCTYPE_CNT 3
+
+#ifdef ENCRYPT_NAMES
+char *encrypt_names[] = {
+ "IS", "SUPPORT", "REPLY", "START", "END",
+ "REQUEST-START", "REQUEST-END", "ENC-KEYID", "DEC-KEYID",
+ 0
+};
+char *enctype_names[] = {
+ "ANY", "DES_CFB64", "DES_OFB64",
+ 0
+};
+#else
+extern char *encrypt_names[];
+extern char *enctype_names[];
+#endif
+
+
+#define ENCRYPT_NAME_OK(x) ((unsigned int)(x) < ENCRYPT_CNT)
+#define ENCRYPT_NAME(x) encrypt_names[x]
+
+#define ENCTYPE_NAME_OK(x) ((unsigned int)(x) < ENCTYPE_CNT)
+#define ENCTYPE_NAME(x) enctype_names[x]
+
+#endif /* !_TELNET_H_ */
diff --git a/include/arpa/tftp.h b/include/arpa/tftp.h
new file mode 100644
index 0000000..c1e6b7e
--- /dev/null
+++ b/include/arpa/tftp.h
@@ -0,0 +1,83 @@
+/* $OpenBSD: tftp.h,v 1.8 2006/07/26 16:43:30 deraadt Exp $ */
+/* $NetBSD: tftp.h,v 1.3 1994/10/26 00:56:48 cgd Exp $ */
+
+/*
+ * Copyright (c) 1983 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.
+ *
+ * @(#)tftp.h 5.4 (Berkeley) 4/3/91
+ */
+
+#ifndef _TFTP_H_
+#define _TFTP_H_
+
+/*
+ * Trivial File Transfer Protocol (IEN-133)
+ */
+#define SEGSIZE 512 /* data segment size */
+#define SEGSIZE_MIN 8 /* minimal data segment size */
+#define SEGSIZE_MAX 65464 /* maximal data segment size */
+
+/*
+ * Packet types.
+ */
+#define RRQ 01 /* read request */
+#define WRQ 02 /* write request */
+#define DATA 03 /* data packet */
+#define ACK 04 /* acknowledgement */
+#define ERROR 05 /* error code */
+#define OACK 06 /* option acknowledgement */
+
+struct tftphdr {
+ u_int16_t th_opcode; /* packet type */
+ union {
+ u_int16_t tu_block; /* block # */
+ u_int16_t tu_code; /* error code */
+ char tu_stuff[1]; /* request packet stuff */
+ } th_u;
+ char th_data[1]; /* data or error string */
+};
+
+#define th_block th_u.tu_block
+#define th_code th_u.tu_code
+#define th_stuff th_u.tu_stuff
+#define th_msg th_data
+
+/*
+ * Error codes.
+ */
+#define EUNDEF 0 /* not defined */
+#define ENOTFOUND 1 /* file not found */
+#define EACCESS 2 /* access violation */
+#define ENOSPACE 3 /* disk full or allocation exceeded */
+#define EBADOP 4 /* illegal TFTP operation */
+#define EBADID 5 /* unknown transfer ID */
+#define EEXISTS 6 /* file already exists */
+#define ENOUSER 7 /* no such user */
+#define EOPTNEG 8 /* option negotiation failed */
+
+#endif /* !_TFTP_H_ */
diff --git a/include/asr.h b/include/asr.h
new file mode 100644
index 0000000..0e38d55
--- /dev/null
+++ b/include/asr.h
@@ -0,0 +1,90 @@
+/* $OpenBSD: asr.h,v 1.2 2019/10/24 05:57:41 otto Exp $ */
+/*
+ * Copyright (c) 2012-2014 Eric Faurot <eric@openbsd.org>
+ *
+ * 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.
+ */
+
+/*
+ * Expected fd conditions
+ */
+#define ASR_WANT_READ 1
+#define ASR_WANT_WRITE 2
+
+/*
+ * Structure through which asynchronous query results are returned when
+ * calling asr_run().
+ */
+struct asr_result {
+ /* Fields set if the query is not done yet (asr_run returns 0) */
+ int ar_cond; /* ASR_WANT_READ or ASR_WANT_WRITE */
+ int ar_fd; /* the fd waiting for io condition */
+ int ar_timeout; /* time to wait for in milliseconds */
+
+ /* Error fields. Depends on the query type. */
+ int ar_errno;
+ int ar_h_errno;
+ int ar_gai_errno;
+ int ar_rrset_errno;
+
+ /* Result for res_*_async() calls */
+ int ar_count; /* number of answers in the dns reply */
+ int ar_rcode; /* response code in the dns reply */
+ void *ar_data; /* raw reply packet (must be freed) */
+ int ar_datalen; /* reply packet length */
+ struct sockaddr_storage ar_ns; /* nameserver that responded */
+
+ /* Result for other calls. Must be freed properly. */
+ struct addrinfo *ar_addrinfo;
+ struct rrsetinfo *ar_rrsetinfo;
+ struct hostent *ar_hostent;
+ struct netent *ar_netent;
+};
+
+/*
+ * Asynchronous query management.
+ */
+
+/* Forward declaration. The API uses opaque pointers as query handles. */
+struct asr_query;
+
+void *asr_resolver_from_string(const char *);
+void asr_resolver_free(void *);
+int asr_run(struct asr_query *, struct asr_result *);
+int asr_run_sync(struct asr_query *, struct asr_result *);
+void asr_abort(struct asr_query *);
+
+/*
+ * Asynchronous version of the resolver functions. Similar prototypes, with
+ * an extra context parameter at the end which must currently be set to NULL.
+ * All functions return a handle suitable for use with the management functions
+ * above.
+ */
+struct asr_query *res_send_async(const unsigned char *, int, void *);
+struct asr_query *res_query_async(const char *, int, int, void *);
+struct asr_query *res_search_async(const char *, int, int, void *);
+
+struct asr_query *getrrsetbyname_async(const char *, unsigned int, unsigned int,
+ unsigned int, void *);
+
+struct asr_query *gethostbyname_async(const char *, void *);
+struct asr_query *gethostbyname2_async(const char *, int, void *);
+struct asr_query *gethostbyaddr_async(const void *, socklen_t, int, void *);
+
+struct asr_query *getnetbyname_async(const char *, void *);
+struct asr_query *getnetbyaddr_async(in_addr_t, int, void *);
+
+struct asr_query *getaddrinfo_async(const char *, const char *,
+ const struct addrinfo *, void *);
+struct asr_query *getnameinfo_async(const struct sockaddr *, socklen_t, char *,
+ size_t, char *, size_t, int, void *);
diff --git a/include/assert.h b/include/assert.h
new file mode 100644
index 0000000..c885a13
--- /dev/null
+++ b/include/assert.h
@@ -0,0 +1,68 @@
+/* $OpenBSD: assert.h,v 1.13 2011/06/26 21:11:41 espie Exp $ */
+/* $NetBSD: assert.h,v 1.6 1994/10/26 00:55:44 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)assert.h 8.2 (Berkeley) 1/21/94
+ */
+
+/*
+ * Unlike other ANSI header files, <assert.h> may usefully be included
+ * multiple times, with and without NDEBUG defined.
+ */
+
+#include <sys/cdefs.h>
+
+#undef assert
+#undef _assert
+
+#ifdef NDEBUG
+# define assert(e) ((void)0)
+# define _assert(e) ((void)0)
+#else
+# define _assert(e) assert(e)
+# if __ISO_C_VISIBLE >= 1999
+# define assert(e) ((e) ? (void)0 : __assert2(__FILE__, __LINE__, __func__, #e))
+# else
+# define assert(e) ((e) ? (void)0 : __assert(__FILE__, __LINE__, #e))
+# endif
+#endif
+
+#ifndef _ASSERT_H_
+#define _ASSERT_H_
+__BEGIN_DECLS
+__dead void __assert(const char *, int, const char *);
+__dead void __assert2(const char *, int, const char *, const char *);
+__END_DECLS
+#endif
diff --git a/include/bitstring.h b/include/bitstring.h
new file mode 100644
index 0000000..8fc3423
--- /dev/null
+++ b/include/bitstring.h
@@ -0,0 +1,128 @@
+/* $OpenBSD: bitstring.h,v 1.5 2003/06/02 19:34:12 millert Exp $ */
+/* $NetBSD: bitstring.h,v 1.5 1997/05/14 15:49:55 pk Exp $ */
+
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Paul Vixie.
+ *
+ * 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.
+ *
+ * @(#)bitstring.h 8.1 (Berkeley) 7/19/93
+ */
+
+#ifndef _BITSTRING_H_
+#define _BITSTRING_H_
+
+/* modified for SV/AT and bitstring bugfix by M.R.Murphy, 11oct91
+ * bitstr_size changed gratuitously, but shorter
+ * bit_alloc spelling error fixed
+ * the following were efficient, but didn't work, they've been made to
+ * work, but are no longer as efficient :-)
+ * bit_nclear, bit_nset, bit_ffc, bit_ffs
+ */
+typedef unsigned char bitstr_t;
+
+/* internal macros */
+ /* byte of the bitstring bit is in */
+#define _bit_byte(bit) \
+ ((bit) >> 3)
+
+ /* mask for the bit within its byte */
+#define _bit_mask(bit) \
+ (1 << ((bit)&0x7))
+
+/* external macros */
+ /* bytes in a bitstring of nbits bits */
+#define bitstr_size(nbits) \
+ (((nbits) + 7) >> 3)
+
+ /* allocate a bitstring */
+#define bit_alloc(nbits) \
+ (bitstr_t *)calloc((size_t)bitstr_size(nbits), sizeof(bitstr_t))
+
+ /* allocate a bitstring on the stack */
+#define bit_decl(name, nbits) \
+ ((name)[bitstr_size(nbits)])
+
+ /* is bit N of bitstring name set? */
+#define bit_test(name, bit) \
+ ((name)[_bit_byte(bit)] & _bit_mask(bit))
+
+ /* set bit N of bitstring name */
+#define bit_set(name, bit) \
+ ((name)[_bit_byte(bit)] |= _bit_mask(bit))
+
+ /* clear bit N of bitstring name */
+#define bit_clear(name, bit) \
+ ((name)[_bit_byte(bit)] &= ~_bit_mask(bit))
+
+ /* clear bits start ... stop in bitstring */
+#define bit_nclear(name, start, stop) do { \
+ register bitstr_t *_name = name; \
+ register int _start = start, _stop = stop; \
+ while (_start <= _stop) { \
+ bit_clear(_name, _start); \
+ _start++; \
+ } \
+} while(0)
+
+ /* set bits start ... stop in bitstring */
+#define bit_nset(name, start, stop) do { \
+ register bitstr_t *_name = name; \
+ register int _start = start, _stop = stop; \
+ while (_start <= _stop) { \
+ bit_set(_name, _start); \
+ _start++; \
+ } \
+} while(0)
+
+ /* find first bit clear in name */
+#define bit_ffc(name, nbits, value) do { \
+ register bitstr_t *_name = name; \
+ register int _bit, _nbits = nbits, _value = -1; \
+ for (_bit = 0; _bit < _nbits; ++_bit) \
+ if (!bit_test(_name, _bit)) { \
+ _value = _bit; \
+ break; \
+ } \
+ *(value) = _value; \
+} while(0)
+
+ /* find first bit set in name */
+#define bit_ffs(name, nbits, value) do { \
+ register bitstr_t *_name = name; \
+ register int _bit, _nbits = nbits, _value = -1; \
+ for (_bit = 0; _bit < _nbits; ++_bit) \
+ if (bit_test(_name, _bit)) { \
+ _value = _bit; \
+ break; \
+ } \
+ *(value) = _value; \
+} while(0)
+
+#endif /* !_BITSTRING_H_ */
diff --git a/include/blf.h b/include/blf.h
new file mode 100644
index 0000000..ec42b41
--- /dev/null
+++ b/include/blf.h
@@ -0,0 +1,82 @@
+/* $OpenBSD: blf.h,v 1.7 2007/03/14 17:59:41 grunk Exp $ */
+/*
+ * Blowfish - a fast block cipher designed by Bruce Schneier
+ *
+ * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Niels Provos.
+ * 4. 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.
+ */
+
+#ifndef _BLF_H_
+#define _BLF_H_
+
+/* Schneier specifies a maximum key length of 56 bytes.
+ * This ensures that every key bit affects every cipher
+ * bit. However, the subkeys can hold up to 72 bytes.
+ * Warning: For normal blowfish encryption only 56 bytes
+ * of the key affect all cipherbits.
+ */
+
+#define BLF_N 16 /* Number of Subkeys */
+#define BLF_MAXKEYLEN ((BLF_N-2)*4) /* 448 bits */
+#define BLF_MAXUTILIZED ((BLF_N+2)*4) /* 576 bits */
+
+/* Blowfish context */
+typedef struct BlowfishContext {
+ u_int32_t S[4][256]; /* S-Boxes */
+ u_int32_t P[BLF_N + 2]; /* Subkeys */
+} blf_ctx;
+
+/* Raw access to customized Blowfish
+ * blf_key is just:
+ * Blowfish_initstate( state )
+ * Blowfish_expand0state( state, key, keylen )
+ */
+
+void Blowfish_encipher(blf_ctx *, u_int32_t *, u_int32_t *);
+void Blowfish_decipher(blf_ctx *, u_int32_t *, u_int32_t *);
+void Blowfish_initstate(blf_ctx *);
+void Blowfish_expand0state(blf_ctx *, const u_int8_t *, u_int16_t);
+void Blowfish_expandstate
+(blf_ctx *, const u_int8_t *, u_int16_t, const u_int8_t *, u_int16_t);
+
+/* Standard Blowfish */
+
+void blf_key(blf_ctx *, const u_int8_t *, u_int16_t);
+void blf_enc(blf_ctx *, u_int32_t *, u_int16_t);
+void blf_dec(blf_ctx *, u_int32_t *, u_int16_t);
+
+void blf_ecb_encrypt(blf_ctx *, u_int8_t *, u_int32_t);
+void blf_ecb_decrypt(blf_ctx *, u_int8_t *, u_int32_t);
+
+void blf_cbc_encrypt(blf_ctx *, u_int8_t *, u_int8_t *, u_int32_t);
+void blf_cbc_decrypt(blf_ctx *, u_int8_t *, u_int8_t *, u_int32_t);
+
+/* Converts u_int8_t to u_int32_t */
+u_int32_t Blowfish_stream2word(const u_int8_t *, u_int16_t , u_int16_t *);
+
+#endif
diff --git a/include/bsd_auth.h b/include/bsd_auth.h
new file mode 100644
index 0000000..19c5fbc
--- /dev/null
+++ b/include/bsd_auth.h
@@ -0,0 +1,105 @@
+/* $OpenBSD: bsd_auth.h,v 1.11 2017/03/09 10:13:03 fcambus Exp $ */
+
+/*-
+ * Copyright (c) 1997 Berkeley Software Design, 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Berkeley Software Design,
+ * Inc.
+ * 4. The name of Berkeley Software Design, Inc. may not be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN, 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 BERKELEY SOFTWARE DESIGN, INC. 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.
+ *
+ * BSDI $From: bsd_auth.h,v 2.3 1999/09/08 22:13:08 prb Exp $
+ */
+
+#ifndef _BSD_AUTH_H_
+#define _BSD_AUTH_H_
+
+#include <machine/_types.h> /* for __va_list */
+
+typedef struct auth_session_t auth_session_t;
+
+typedef enum {
+ AUTHV_ALL,
+ AUTHV_CHALLENGE,
+ AUTHV_CLASS,
+ AUTHV_NAME,
+ AUTHV_SERVICE,
+ AUTHV_STYLE,
+ AUTHV_INTERACTIVE
+} auth_item_t;
+
+#include <sys/cdefs.h>
+__BEGIN_DECLS
+struct passwd;
+struct login_cap;
+
+char *auth_getitem(auth_session_t *, auth_item_t);
+int auth_setitem(auth_session_t *, auth_item_t, char *);
+
+auth_session_t *auth_open(void);
+auth_session_t *auth_verify(auth_session_t *, char *, char *, ...)
+ __attribute__((__sentinel__));
+
+auth_session_t *auth_userchallenge(char *, char *, char *, char **);
+auth_session_t *auth_usercheck(char *, char *, char *, char *);
+
+int auth_userresponse(auth_session_t *, char *, int);
+int auth_userokay(char *, char *, char *, char *);
+int auth_approval(auth_session_t *, struct login_cap *, char *, char *);
+
+int auth_close(auth_session_t *);
+void auth_clean(auth_session_t *);
+
+char *auth_getvalue(auth_session_t *, char *);
+int auth_getstate(auth_session_t *);
+char *auth_challenge(auth_session_t *);
+void auth_setenv(auth_session_t *);
+void auth_clrenv(auth_session_t *);
+
+void auth_setstate(auth_session_t *, int);
+int auth_call(auth_session_t *, char *, ...)
+ __attribute__((__sentinel__));
+
+int auth_setdata(auth_session_t *, void *, size_t);
+int auth_setoption(auth_session_t *, char *, char *);
+int auth_setpwd(auth_session_t *, struct passwd *);
+void auth_set_va_list(auth_session_t *, __va_list);
+
+struct passwd *auth_getpwd(auth_session_t *);
+
+quad_t auth_check_expire(auth_session_t *);
+quad_t auth_check_change(auth_session_t *);
+
+void auth_clroptions(auth_session_t *);
+void auth_clroption(auth_session_t *, char *);
+
+char *auth_mkvalue(char *);
+void auth_checknologin(struct login_cap *);
+int auth_cat(char *);
+
+__END_DECLS
+
+#endif /* _BSD_AUTH_H_ */
diff --git a/include/complex.h b/include/complex.h
new file mode 100644
index 0000000..b29f5a7
--- /dev/null
+++ b/include/complex.h
@@ -0,0 +1,120 @@
+/* $OpenBSD: complex.h,v 1.5 2014/03/16 18:38:30 guenther Exp $ */
+/*
+ * Copyright (c) 2008 Martynas Venckus <martynas@openbsd.org>
+ *
+ * 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.
+ */
+
+#ifndef _COMPLEX_H_
+#define _COMPLEX_H_
+
+#include <sys/cdefs.h>
+
+/*
+ * C99
+ */
+#ifdef __GNUC__
+#if __STDC_VERSION__ < 199901
+#define _Complex __complex__
+#endif
+#define _Complex_I 1.0fi
+#endif
+
+#define complex _Complex
+
+/* XXX switch to _Imaginary_I */
+#undef I
+#define I _Complex_I
+
+__BEGIN_DECLS
+/*
+ * Double versions of C99 functions
+ */
+double complex cacos(double complex);
+double complex casin(double complex);
+double complex catan(double complex);
+double complex ccos(double complex);
+double complex csin(double complex);
+double complex ctan(double complex);
+double complex cacosh(double complex);
+double complex casinh(double complex);
+double complex catanh(double complex);
+double complex ccosh(double complex);
+double complex csinh(double complex);
+double complex ctanh(double complex);
+double complex cexp(double complex);
+double complex clog(double complex);
+double cabs(double complex);
+double complex cpow(double complex, double complex);
+double complex csqrt(double complex);
+double carg(double complex);
+double cimag(double complex);
+double complex conj(double complex);
+double complex cproj(double complex);
+double creal(double complex);
+
+/*
+ * Float versions of C99 functions
+ */
+float complex cacosf(float complex);
+float complex casinf(float complex);
+float complex catanf(float complex);
+float complex ccosf(float complex);
+float complex csinf(float complex);
+float complex ctanf(float complex);
+float complex cacoshf(float complex);
+float complex casinhf(float complex);
+float complex catanhf(float complex);
+float complex ccoshf(float complex);
+float complex csinhf(float complex);
+float complex ctanhf(float complex);
+float complex cexpf(float complex);
+float complex clogf(float complex);
+float cabsf(float complex);
+float complex cpowf(float complex, float complex);
+float complex csqrtf(float complex);
+float cargf(float complex);
+float cimagf(float complex);
+float complex conjf(float complex);
+float complex cprojf(float complex);
+float crealf(float complex);
+
+/*
+ * Long double versions of C99 functions
+ */
+long double complex cacosl(long double complex);
+long double complex casinl(long double complex);
+long double complex catanl(long double complex);
+long double complex ccosl(long double complex);
+long double complex csinl(long double complex);
+long double complex ctanl(long double complex);
+long double complex cacoshl(long double complex);
+long double complex casinhl(long double complex);
+long double complex catanhl(long double complex);
+long double complex ccoshl(long double complex);
+long double complex csinhl(long double complex);
+long double complex ctanhl(long double complex);
+long double complex cexpl(long double complex);
+long double complex clogl(long double complex);
+long double cabsl(long double complex);
+long double complex cpowl(long double complex,
+ long double complex);
+long double complex csqrtl(long double complex);
+long double cargl(long double complex);
+long double cimagl(long double complex);
+long double complex conjl(long double complex);
+long double complex cprojl(long double complex);
+long double creall(long double complex);
+__END_DECLS
+
+#endif /* !_COMPLEX_H_ */
diff --git a/include/cpio.h b/include/cpio.h
new file mode 100644
index 0000000..c38d59f
--- /dev/null
+++ b/include/cpio.h
@@ -0,0 +1,59 @@
+/* $OpenBSD: cpio.h,v 1.3 2008/06/26 05:42:04 ray Exp $ */
+/* $NetBSD: cpio.h,v 1.1 1996/02/05 22:34:11 jtc Exp $ */
+
+/*-
+ * Copyright (c) 1996 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by J.T. Conklin.
+ *
+ * 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 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 _CPIO_H_
+#define _CPIO_H_
+
+#define C_IRUSR 0000400
+#define C_IWUSR 0000200
+#define C_IXUSR 0000100
+#define C_IRGRP 0000040
+#define C_IWGRP 0000020
+#define C_IXGRP 0000010
+#define C_IROTH 0000004
+#define C_IWOTH 0000002
+#define C_IXOTH 0000001
+#define C_ISUID 0004000
+#define C_ISGID 0002000
+#define C_ISVTX 0001000
+#define C_ISDIR 0040000
+#define C_ISFIFO 0010000
+#define C_ISREG 0100000
+#define C_ISBLK 0060000
+#define C_ISCHR 0020000
+#define C_ISCTG 0110000
+#define C_ISLNK 0120000
+#define C_ISSOCK 0140000
+
+#define MAGIC "070707"
+
+#endif /* _CPIO_H_ */
diff --git a/include/ctype.h b/include/ctype.h
new file mode 100644
index 0000000..e90d375
--- /dev/null
+++ b/include/ctype.h
@@ -0,0 +1,304 @@
+/* $OpenBSD: ctype.h,v 1.25 2017/09/05 03:16:13 schwarze Exp $ */
+/* $NetBSD: ctype.h,v 1.14 1994/10/26 00:55:47 cgd Exp $ */
+
+/*
+ * Copyright (c) 1989 The Regents of the University of California.
+ * All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)ctype.h 5.3 (Berkeley) 4/3/91
+ */
+
+#ifndef _CTYPE_H_
+#define _CTYPE_H_
+
+#include <sys/cdefs.h>
+
+#define _U 0x01
+#define _L 0x02
+#define _N 0x04
+#define _S 0x08
+#define _P 0x10
+#define _C 0x20
+#define _X 0x40
+#define _B 0x80
+
+#if __POSIX_VISIBLE >= 200809
+#ifndef _LOCALE_T_DEFINED_
+#define _LOCALE_T_DEFINED_
+typedef void *locale_t;
+#endif
+#endif
+
+__BEGIN_DECLS
+
+extern const char *_ctype_;
+extern const short *_tolower_tab_;
+extern const short *_toupper_tab_;
+
+#if defined(__GNUC__) || defined(_ANSI_LIBRARY)
+int isalnum(int);
+int isalpha(int);
+int iscntrl(int);
+int isdigit(int);
+int isgraph(int);
+int islower(int);
+int isprint(int);
+int ispunct(int);
+int isspace(int);
+int isupper(int);
+int isxdigit(int);
+int tolower(int);
+int toupper(int);
+
+#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE > 200112 \
+ || __XPG_VISIBLE > 600
+int isblank(int);
+#endif
+
+#if __BSD_VISIBLE || __XPG_VISIBLE
+int isascii(int);
+int toascii(int);
+int _tolower(int);
+int _toupper(int);
+#endif /* __BSD_VISIBLE || __XPG_VISIBLE */
+
+#if __POSIX_VISIBLE >= 200809
+int isalnum_l(int, locale_t);
+int isalpha_l(int, locale_t);
+int isblank_l(int, locale_t);
+int iscntrl_l(int, locale_t);
+int isdigit_l(int, locale_t);
+int isgraph_l(int, locale_t);
+int islower_l(int, locale_t);
+int isprint_l(int, locale_t);
+int ispunct_l(int, locale_t);
+int isspace_l(int, locale_t);
+int isupper_l(int, locale_t);
+int isxdigit_l(int, locale_t);
+int tolower_l(int, locale_t);
+int toupper_l(int, locale_t);
+#endif
+
+#endif /* __GNUC__ || _ANSI_LIBRARY */
+
+#if !defined(_ANSI_LIBRARY) && !defined(__cplusplus)
+
+__only_inline int isalnum(int _c)
+{
+ return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & (_U|_L|_N)));
+}
+
+__only_inline int isalpha(int _c)
+{
+ return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & (_U|_L)));
+}
+
+__only_inline int iscntrl(int _c)
+{
+ return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _C));
+}
+
+__only_inline int isdigit(int _c)
+{
+ return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _N));
+}
+
+__only_inline int isgraph(int _c)
+{
+ return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & (_P|_U|_L|_N)));
+}
+
+__only_inline int islower(int _c)
+{
+ return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _L));
+}
+
+__only_inline int isprint(int _c)
+{
+ return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & (_P|_U|_L|_N|_B)));
+}
+
+__only_inline int ispunct(int _c)
+{
+ return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _P));
+}
+
+__only_inline int isspace(int _c)
+{
+ return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _S));
+}
+
+__only_inline int isupper(int _c)
+{
+ return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & _U));
+}
+
+__only_inline int isxdigit(int _c)
+{
+ return (_c == -1 ? 0 : ((_ctype_ + 1)[(unsigned char)_c] & (_N|_X)));
+}
+
+__only_inline int tolower(int _c)
+{
+ if ((unsigned int)_c > 255)
+ return (_c);
+ return ((_tolower_tab_ + 1)[_c]);
+}
+
+__only_inline int toupper(int _c)
+{
+ if ((unsigned int)_c > 255)
+ return (_c);
+ return ((_toupper_tab_ + 1)[_c]);
+}
+
+#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __POSIX_VISIBLE > 200112 \
+ || __XPG_VISIBLE > 600
+__only_inline int isblank(int _c)
+{
+ return (_c == ' ' || _c == '\t');
+}
+#endif
+
+#if __BSD_VISIBLE || __XPG_VISIBLE
+__only_inline int isascii(int _c)
+{
+ return ((unsigned int)_c <= 0177);
+}
+
+__only_inline int toascii(int _c)
+{
+ return (_c & 0177);
+}
+
+__only_inline int _tolower(int _c)
+{
+ return (_c - 'A' + 'a');
+}
+
+__only_inline int _toupper(int _c)
+{
+ return (_c - 'a' + 'A');
+}
+#endif /* __BSD_VISIBLE || __XPG_VISIBLE */
+
+#if __POSIX_VISIBLE >= 200809
+__only_inline int
+isalnum_l(int _c, locale_t _l __attribute__((__unused__)))
+{
+ return isalnum(_c);
+}
+
+__only_inline int
+isalpha_l(int _c, locale_t _l __attribute__((__unused__)))
+{
+ return isalpha(_c);
+}
+
+__only_inline int
+isblank_l(int _c, locale_t _l __attribute__((__unused__)))
+{
+ return isblank(_c);
+}
+
+__only_inline int
+iscntrl_l(int _c, locale_t _l __attribute__((__unused__)))
+{
+ return iscntrl(_c);
+}
+
+__only_inline int
+isdigit_l(int _c, locale_t _l __attribute__((__unused__)))
+{
+ return isdigit(_c);
+}
+
+__only_inline int
+isgraph_l(int _c, locale_t _l __attribute__((__unused__)))
+{
+ return isgraph(_c);
+}
+
+__only_inline int
+islower_l(int _c, locale_t _l __attribute__((__unused__)))
+{
+ return islower(_c);
+}
+
+__only_inline int
+isprint_l(int _c, locale_t _l __attribute__((__unused__)))
+{
+ return isprint(_c);
+}
+
+__only_inline int
+ispunct_l(int _c, locale_t _l __attribute__((__unused__)))
+{
+ return ispunct(_c);
+}
+
+__only_inline int
+isspace_l(int _c, locale_t _l __attribute__((__unused__)))
+{
+ return isspace(_c);
+}
+
+__only_inline int
+isupper_l(int _c, locale_t _l __attribute__((__unused__)))
+{
+ return isupper(_c);
+}
+
+__only_inline int
+isxdigit_l(int _c, locale_t _l __attribute__((__unused__)))
+{
+ return isxdigit(_c);
+}
+
+__only_inline int
+tolower_l(int _c, locale_t _l __attribute__((__unused__)))
+{
+ return tolower(_c);
+}
+
+__only_inline int
+toupper_l(int _c, locale_t _l __attribute__((__unused__)))
+{
+ return toupper(_c);
+}
+#endif /* __POSIX_VISIBLE >= 200809 */
+
+#endif /* !_ANSI_LIBRARY */
+
+__END_DECLS
+
+#endif /* !_CTYPE_H_ */
diff --git a/include/curses.h b/include/curses.h
new file mode 100644
index 0000000..8105fb7
--- /dev/null
+++ b/include/curses.h
@@ -0,0 +1,13 @@
+/* $OpenBSD: curses.h,v 1.5 2019/01/25 00:19:25 millert Exp $ */
+
+/*
+ * Placed in the public domain by Todd C. Miller <millert@openbsd.org>
+ * on June 17, 2003.
+ */
+
+#ifndef _CURSES_H_
+#define _CURSES_H_
+
+#include <ncurses.h>
+
+#endif /* _CURSES_H_ */
diff --git a/include/db.h b/include/db.h
new file mode 100644
index 0000000..4381efe
--- /dev/null
+++ b/include/db.h
@@ -0,0 +1,161 @@
+/* $OpenBSD: db.h,v 1.12 2015/10/17 21:48:42 guenther Exp $ */
+/* $NetBSD: db.h,v 1.13 1994/10/26 00:55:48 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993, 1994
+ * 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.
+ *
+ * @(#)db.h 8.7 (Berkeley) 6/16/94
+ */
+
+#ifndef _DB_H_
+#define _DB_H_
+
+#include <sys/types.h>
+
+#include <limits.h>
+
+#define RET_ERROR -1 /* Return values. */
+#define RET_SUCCESS 0
+#define RET_SPECIAL 1
+
+#define MAX_PAGE_NUMBER 0xffffffff /* >= # of pages in a file */
+typedef u_int32_t pgno_t;
+#define MAX_PAGE_OFFSET 65535 /* >= # of bytes in a page */
+typedef u_int16_t indx_t;
+#define MAX_REC_NUMBER 0xffffffff /* >= # of records in a tree */
+typedef u_int32_t recno_t;
+
+/* Key/data structure -- a Data-Base Thang. */
+typedef struct {
+ void *data; /* data */
+ size_t size; /* data length */
+} DBT;
+
+/* Routine flags. */
+#define R_CURSOR 1 /* del, put, seq */
+#define __R_UNUSED 2 /* UNUSED */
+#define R_FIRST 3 /* seq */
+#define R_IAFTER 4 /* put (RECNO) */
+#define R_IBEFORE 5 /* put (RECNO) */
+#define R_LAST 6 /* seq (BTREE, RECNO) */
+#define R_NEXT 7 /* seq */
+#define R_NOOVERWRITE 8 /* put */
+#define R_PREV 9 /* seq (BTREE, RECNO) */
+#define R_SETCURSOR 10 /* put (RECNO) */
+#define R_RECNOSYNC 11 /* sync (RECNO) */
+
+typedef enum { DB_BTREE, DB_HASH, DB_RECNO } DBTYPE;
+
+/*
+ * !!!
+ * The following flags are included in the dbopen(3) call as part of the
+ * open(2) flags. In order to avoid conflicts with the open flags, start
+ * at the top of the 16 or 32-bit number space and work our way down. If
+ * the open flags were significantly expanded in the future, it could be
+ * a problem. Wish I'd left another flags word in the dbopen call.
+ *
+ * !!!
+ * None of this stuff is implemented yet. The only reason that it's here
+ * is so that the access methods can skip copying the key/data pair when
+ * the DB_LOCK flag isn't set.
+ */
+#if UINT_MAX > 65535
+#define DB_LOCK 0x20000000 /* Do locking. */
+#define DB_SHMEM 0x40000000 /* Use shared memory. */
+#define DB_TXN 0x80000000 /* Do transactions. */
+#else
+#define DB_LOCK 0x2000 /* Do locking. */
+#define DB_SHMEM 0x4000 /* Use shared memory. */
+#define DB_TXN 0x8000 /* Do transactions. */
+#endif
+
+/* Access method description structure. */
+typedef struct __db {
+ DBTYPE type; /* Underlying db type. */
+ int (*close)(struct __db *);
+ int (*del)(const struct __db *, const DBT *, unsigned int);
+ int (*get)(const struct __db *, const DBT *, DBT *, unsigned int);
+ int (*put)(const struct __db *, DBT *, const DBT *, unsigned int);
+ int (*seq)(const struct __db *, DBT *, DBT *, unsigned int);
+ int (*sync)(const struct __db *, unsigned int);
+ void *internal; /* Access method private. */
+ int (*fd)(const struct __db *);
+} DB;
+
+#define BTREEMAGIC 0x053162
+#define BTREEVERSION 3
+
+/* Structure used to pass parameters to the btree routines. */
+typedef struct {
+#define R_DUP 0x01 /* duplicate keys */
+ unsigned long flags;
+ unsigned int cachesize; /* bytes to cache */
+ int maxkeypage; /* maximum keys per page */
+ int minkeypage; /* minimum keys per page */
+ unsigned int psize; /* page size */
+ int (*compare) /* comparison function */
+ (const DBT *, const DBT *);
+ size_t (*prefix) /* prefix function */
+ (const DBT *, const DBT *);
+ int lorder; /* byte order */
+} BTREEINFO;
+
+#define HASHMAGIC 0x061561
+#define HASHVERSION 2
+
+/* Structure used to pass parameters to the hashing routines. */
+typedef struct {
+ unsigned int bsize; /* bucket size */
+ unsigned int ffactor; /* fill factor */
+ unsigned int nelem; /* number of elements */
+ unsigned int cachesize; /* bytes to cache */
+ u_int32_t /* hash function */
+ (*hash)(const void *, size_t);
+ int lorder; /* byte order */
+} HASHINFO;
+
+/* Structure used to pass parameters to the record routines. */
+typedef struct {
+#define R_FIXEDLEN 0x01 /* fixed-length records */
+#define R_NOKEY 0x02 /* key not required */
+#define R_SNAPSHOT 0x04 /* snapshot the input */
+ unsigned long flags;
+ unsigned int cachesize; /* bytes to cache */
+ unsigned int psize; /* page size */
+ int lorder; /* byte order */
+ size_t reclen; /* record length
+ (fixed-length records) */
+ unsigned char bval; /* delimiting byte
+ (variable-length records) */
+ char *bfname; /* btree file name */
+} RECNOINFO;
+
+__BEGIN_DECLS
+DB *dbopen(const char *, int, int, DBTYPE, const void *);
+__END_DECLS
+#endif /* !_DB_H_ */
diff --git a/include/dirent.h b/include/dirent.h
new file mode 100644
index 0000000..61a5e01
--- /dev/null
+++ b/include/dirent.h
@@ -0,0 +1,104 @@
+/* $OpenBSD: dirent.h,v 1.34 2016/09/09 18:12:37 millert Exp $ */
+/* $NetBSD: dirent.h,v 1.9 1995/03/26 20:13:37 jtc Exp $ */
+
+/*-
+ * 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.
+ * 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.
+ *
+ * @(#)dirent.h 8.2 (Berkeley) 7/28/94
+ */
+
+#ifndef _DIRENT_H_
+#define _DIRENT_H_
+
+#include <sys/cdefs.h>
+
+/*
+ * POSIX doesn't mandate this, but X/Open XPG 4.2 does.
+ */
+#if __BSD_VISIBLE || __XPG_VISIBLE >= 400
+#include <sys/types.h>
+#else
+#include <sys/_types.h>
+#endif
+
+/*
+ * The kernel defines the format of directory entries returned by
+ * the getdents(2) system call.
+ */
+#include <sys/dirent.h>
+
+#if __BSD_VISIBLE || __XPG_VISIBLE
+#define d_ino d_fileno /* backward compatibility */
+#endif
+
+typedef struct _dirdesc DIR;
+
+#if __BSD_VISIBLE
+
+/* definitions for library routines operating on directories. */
+#define DIRBLKSIZ 1024
+
+#include <sys/_null.h>
+
+#endif /* __BSD_VISIBLE */
+
+__BEGIN_DECLS
+DIR *opendir(const char *);
+#if __POSIX_VISIBLE >= 200809
+DIR *fdopendir(int);
+#endif
+struct dirent *readdir(DIR *);
+void rewinddir(DIR *);
+int closedir(DIR *);
+#if __BSD_VISIBLE
+int getdents(int, void *, size_t)
+ __attribute__ ((__bounded__(__string__,2,3)));
+#endif /* __BSD_VISIBLE */
+#if __XPG_VISIBLE
+long telldir(DIR *);
+void seekdir(DIR *, long);
+#endif
+#if __POSIX_VISIBLE >= 199506 || __XPG_VISIBLE >= 500
+int readdir_r(DIR *__restrict, struct dirent *__restrict,
+ struct dirent **__restrict);
+#endif
+#if __POSIX_VISIBLE >= 200809
+int scandir(const char *, struct dirent ***, int (*)(const struct dirent *),
+ int (*)(const struct dirent **, const struct dirent **));
+int alphasort(const struct dirent **, const struct dirent **);
+#elif __BSD_VISIBLE
+int scandir(const char *, struct dirent ***, int (*)(struct dirent *),
+ int (*)(const void *, const void *));
+int alphasort(const void *, const void *);
+#endif
+#if __POSIX_VISIBLE >= 200809 || __XPG_VISIBLE > 600
+int dirfd(DIR *);
+#endif
+__END_DECLS
+
+#endif /* !_DIRENT_H_ */
diff --git a/include/disktab.h b/include/disktab.h
new file mode 100644
index 0000000..4a1b8ec
--- /dev/null
+++ b/include/disktab.h
@@ -0,0 +1,60 @@
+/* $OpenBSD: disktab.h,v 1.3 2003/06/02 19:34:12 millert Exp $ */
+/* $NetBSD: disktab.h,v 1.3 1994/10/26 00:55:51 cgd Exp $ */
+
+/*
+ * Copyright (c) 1983 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.
+ *
+ * @(#)disktab.h 5.6 (Berkeley) 4/20/91
+ */
+
+#ifndef _DISKTAB_H_
+#define _DISKTAB_H_
+
+/*
+ * Disk description table, see disktab(5)
+ */
+#define DISKTAB "/etc/disktab"
+
+struct disktab {
+ char *d_name; /* drive name */
+ char *d_type; /* drive type */
+ int d_secsize; /* sector size in bytes */
+ int d_ntracks; /* # tracks/cylinder */
+ int d_nsectors; /* # sectors/track */
+ int d_ncylinders; /* # cylinders */
+ int d_rpm; /* revolutions/minute */
+ int d_badsectforw; /* supports DEC bad144 std */
+ int d_sectoffset; /* use sect rather than cyl offsets */
+ struct partition {
+ int p_size; /* #sectors in partition */
+ short p_bsize; /* block size in bytes */
+ short p_fsize; /* frag size in bytes */
+ } d_partitions[8];
+};
+
+#endif /* !_DISKTAB_H_ */
diff --git a/include/dlfcn.h b/include/dlfcn.h
new file mode 100644
index 0000000..431065f
--- /dev/null
+++ b/include/dlfcn.h
@@ -0,0 +1,98 @@
+/* $OpenBSD: dlfcn.h,v 1.14 2017/11/28 17:19:47 kettenis Exp $ */
+/* $NetBSD: dlfcn.h,v 1.2 1995/06/05 19:38:00 pk Exp $ */
+
+/*
+ * Copyright (c) 1995 Paul Kranenburg
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Paul Kranenburg.
+ * 4. 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.
+ */
+
+#ifndef _DLFCN_H_
+#define _DLFCN_H_
+
+#include <sys/cdefs.h>
+
+/* Values for dlopen `mode'. */
+#define RTLD_LAZY 1
+#define RTLD_NOW 2
+#define RTLD_GLOBAL 0x100
+#define RTLD_LOCAL 0x000
+#define RTLD_TRACE 0x200
+
+/*
+ * Special handle arguments for dlsym().
+ */
+#define RTLD_NEXT ((void *) -1) /* Search subsequent objects. */
+#define RTLD_DEFAULT ((void *) -2) /* Use default search algorithm. */
+#define RTLD_SELF ((void *) -3) /* Search the caller itself. */
+
+#if __BSD_VISIBLE
+
+/*
+ * Structure filled in by dladdr().
+ */
+typedef struct dl_info {
+ const char *dli_fname; /* Pathname of shared object. */
+ void *dli_fbase; /* Base address of shared object. */
+ const char *dli_sname; /* Name of nearest symbol. */
+ void *dli_saddr; /* Address of nearest symbol. */
+} Dl_info;
+
+/*
+ * dlctl() commands
+ */
+#define DL_GETERRNO 1
+#define DL_SETSRCHPATH x
+#define DL_GETLIST x
+#define DL_GETREFCNT x
+#define DL_GETLOADADDR x
+#define DL_SETTHREADLCK 2
+#define DL_SETBINDLCK 3
+#define DL_REFERENCE 4
+
+#define DL_LAZY RTLD_LAZY /* Compat */
+
+#endif /* __BSD_VISIBLE */
+
+
+/*
+ * User interface to the run-time linker.
+ */
+__BEGIN_DECLS
+void *dlopen(const char *, int);
+int dlclose(void *);
+void *dlsym(void *__restrict, const char *__restrict);
+char *dlerror(void);
+
+#if __BSD_VISIBLE
+int dladdr(const void *, Dl_info *);
+int dlctl(void *, int, void *);
+#endif /* __BSD_VISIBLE */
+
+__END_DECLS
+
+#endif /* _DLFCN_H_ */
diff --git a/include/elf.h b/include/elf.h
new file mode 100644
index 0000000..8b1273e
--- /dev/null
+++ b/include/elf.h
@@ -0,0 +1,12 @@
+/* $OpenBSD: elf.h,v 1.1 2017/10/17 09:34:52 mpi Exp $ */
+
+/*
+ * Public domain.
+ */
+
+#ifndef _ELF_H_
+#define _ELF_H_
+
+#include <sys/exec_elf.h>
+
+#endif /* _ELF_H_ */
diff --git a/include/elf_abi.h b/include/elf_abi.h
new file mode 100644
index 0000000..489869b
--- /dev/null
+++ b/include/elf_abi.h
@@ -0,0 +1,33 @@
+/* $OpenBSD: elf_abi.h,v 1.4 1996/05/22 07:46:22 etheisen Exp $ */
+/*
+ * Copyright (c) 1996 Erik Theisen
+ * 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.
+ */
+#ifndef _ELF_ABI_H_
+#define _ELF_ABI_H_
+
+#include <sys/exec_elf.h>
+
+#endif /* _ELF_ABI_H_ */
diff --git a/include/err.h b/include/err.h
new file mode 100644
index 0000000..c537811
--- /dev/null
+++ b/include/err.h
@@ -0,0 +1,3 @@
+#include_next <err.h>
+void warnc(int, const char *, ...) __attribute__((__format__ (printf, 2, 3)));
+void vwarnc(int, const char *, va_list) __attribute__((__format__ (printf, 2, 0)));
diff --git a/include/errno.h b/include/errno.h
new file mode 100644
index 0000000..7694025
--- /dev/null
+++ b/include/errno.h
@@ -0,0 +1,59 @@
+/* $OpenBSD: errno.h,v 1.3 2017/08/10 13:34:46 guenther Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)errno.h 8.5 (Berkeley) 1/21/94
+ */
+
+#ifndef _ERRNO_H_
+#define _ERRNO_H_
+
+#include <sys/errno.h>
+
+__BEGIN_DECLS
+#if __BSD_VISIBLE
+#ifndef __SYS_ERRLIST
+#define __SYS_ERRLIST
+extern int sys_nerr;
+extern char *sys_errlist[];
+#endif /* __SYS_ERRLIST */
+#endif /* __BSD_VISIBLE */
+
+#ifndef errno
+int *__errno(void);
+#define errno (*__errno())
+#endif /* errno */
+__END_DECLS
+
+#endif /* _ERRNO_H_ */
diff --git a/include/fenv.h b/include/fenv.h
new file mode 100644
index 0000000..1368ab3
--- /dev/null
+++ b/include/fenv.h
@@ -0,0 +1,60 @@
+/* $OpenBSD: fenv.h,v 1.2 2011/05/25 21:46:49 martynas Exp $ */
+/* $NetBSD: fenv.h,v 1.2.4.1 2011/02/08 16:18:55 bouyer Exp $ */
+
+/*
+ * Copyright (c) 2010 The NetBSD Foundation, 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 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.
+ */
+
+#ifndef _FENV_H_
+#define _FENV_H_
+
+#include <sys/cdefs.h>
+#include <machine/fenv.h>
+
+__BEGIN_DECLS
+
+int feclearexcept(int);
+int fegetexceptflag(fexcept_t *, int);
+int feraiseexcept(int);
+int fesetexceptflag(const fexcept_t *, int);
+int fetestexcept(int);
+
+int fegetround(void);
+int fesetround(int);
+
+int fegetenv(fenv_t *);
+int feholdexcept(fenv_t *);
+int fesetenv(const fenv_t *);
+int feupdateenv(const fenv_t *);
+
+#if __BSD_VISIBLE
+int feenableexcept(int);
+int fedisableexcept(int);
+int fegetexcept(void);
+#endif /* __BSD_VISIBLE */
+
+__END_DECLS
+
+#endif /* ! _FENV_H_ */
diff --git a/include/float.h b/include/float.h
new file mode 100644
index 0000000..24ffe8b
--- /dev/null
+++ b/include/float.h
@@ -0,0 +1,95 @@
+/* $OpenBSD: float.h,v 1.1 2012/06/26 16:16:16 deraadt Exp $ */
+
+/*
+ * Copyright (c) 1989 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 _FLOAT_H_
+#define _FLOAT_H_
+
+#include <sys/cdefs.h>
+#include <machine/_float.h>
+
+__BEGIN_DECLS
+int __flt_rounds(void);
+__END_DECLS
+
+#define FLT_RADIX __FLT_RADIX /* b */
+#define FLT_ROUNDS __FLT_ROUNDS
+
+#if __ISO_C_VISIBLE >= 1999
+#define FLT_EVAL_METHOD __FLT_EVAL_METHOD /* long double */
+#endif
+
+#define FLT_MANT_DIG __FLT_MANT_DIG /* p */
+#define FLT_EPSILON __FLT_EPSILON /* b**(1-p) */
+#ifndef FLT_DIG
+#define FLT_DIG __FLT_DIG /* floor((p-1)*log10(b))+(b == 10) */
+#endif
+#define FLT_MIN_EXP __FLT_MIN_EXP /* emin */
+#ifndef FLT_MIN
+#define FLT_MIN __FLT_MIN /* b**(emin-1) */
+#endif
+#define FLT_MIN_10_EXP __FLT_MIN_10_EXP /* ceil(log10(b**(emin-1))) */
+#define FLT_MAX_EXP __FLT_MAX_EXP /* emax */
+#ifndef FLT_MAX
+#define FLT_MAX __FLT_MAX /* (1-b**(-p))*b**emax */
+#endif
+#define FLT_MAX_10_EXP __FLT_MAX_10_EXP /* floor(log10((1-b**(-p))*b**emax)) */
+
+#define DBL_MANT_DIG __DBL_MANT_DIG
+#define DBL_EPSILON __DBL_EPSILON
+#ifndef DBL_DIG
+#define DBL_DIG __DBL_DIG
+#endif
+#define DBL_MIN_EXP __DBL_MIN_EXP
+#ifndef DBL_MIN
+#define DBL_MIN __DBL_MIN
+#endif
+#define DBL_MIN_10_EXP __DBL_MIN_10_EXP
+#define DBL_MAX_EXP __DBL_MAX_EXP
+#ifndef DBL_MAX
+#define DBL_MAX __DBL_MAX
+#endif
+#define DBL_MAX_10_EXP __DBL_MAX_10_EXP
+
+#define LDBL_MANT_DIG __LDBL_MANT_DIG
+#define LDBL_EPSILON __LDBL_EPSILON
+#define LDBL_DIG __LDBL_DIG
+#define LDBL_MIN_EXP __LDBL_MIN_EXP
+#define LDBL_MIN __LDBL_MIN
+#define LDBL_MIN_10_EXP __LDBL_MIN_10_EXP
+#define LDBL_MAX_EXP __LDBL_MAX_EXP
+#define LDBL_MAX __LDBL_MAX
+#define LDBL_MAX_10_EXP __LDBL_MAX_10_EXP
+
+#if __ISO_C_VISIBLE >= 1999
+#define DECIMAL_DIG __DECIMAL_DIG
+#endif
+
+#endif /* _FLOAT_H_ */
diff --git a/include/fnmatch.h b/include/fnmatch.h
new file mode 100644
index 0000000..4b27d06
--- /dev/null
+++ b/include/fnmatch.h
@@ -0,0 +1,57 @@
+/* $OpenBSD: fnmatch.h,v 1.8 2005/12/13 00:35:22 millert Exp $ */
+/* $NetBSD: fnmatch.h,v 1.5 1994/10/26 00:55:53 cgd Exp $ */
+
+/*-
+ * 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.
+ *
+ * @(#)fnmatch.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _FNMATCH_H_
+#define _FNMATCH_H_
+
+#include <sys/cdefs.h>
+
+#define FNM_NOMATCH 1 /* Match failed. */
+#define FNM_NOSYS 2 /* Function not supported (unused). */
+
+#define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */
+#define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */
+#define FNM_PERIOD 0x04 /* Period must be matched by period. */
+#if __BSD_VISIBLE
+#define FNM_LEADING_DIR 0x08 /* Ignore /<tail> after Imatch. */
+#define FNM_CASEFOLD 0x10 /* Case insensitive search. */
+#define FNM_IGNORECASE FNM_CASEFOLD
+#define FNM_FILE_NAME FNM_PATHNAME
+#endif
+
+__BEGIN_DECLS
+int fnmatch(const char *, const char *, int);
+__END_DECLS
+
+#endif /* !_FNMATCH_H_ */
diff --git a/include/fstab.h b/include/fstab.h
new file mode 100644
index 0000000..ebb955e
--- /dev/null
+++ b/include/fstab.h
@@ -0,0 +1,78 @@
+/* $OpenBSD: fstab.h,v 1.5 2003/06/02 19:34:12 millert Exp $ */
+/* $NetBSD: fstab.h,v 1.3 1994/10/26 00:55:53 cgd Exp $ */
+
+/*
+ * Copyright (c) 1980 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.
+ *
+ * @(#)fstab.h 5.12 (Berkeley) 4/3/91
+ */
+
+#ifndef _FSTAB_H_
+#define _FSTAB_H_
+
+/*
+ * File system table, see fstab(5).
+ *
+ * Used by dump, mount, umount, swapon, fsck, df, ...
+ *
+ * For ufs fs_spec field is the block special name. Programs that want to
+ * use the character special name must create that name by prepending a 'r'
+ * after the right most slash. Quota files are always named "quotas", so
+ * if type is "rq", then use concatenation of fs_file and "quotas" to locate
+ * quota file.
+ */
+#define _PATH_FSTAB "/etc/fstab"
+#define FSTAB "/etc/fstab" /* deprecated */
+
+#define FSTAB_RW "rw" /* read/write device */
+#define FSTAB_RQ "rq" /* read/write with quotas */
+#define FSTAB_RO "ro" /* read-only device */
+#define FSTAB_SW "sw" /* swap device */
+#define FSTAB_XX "xx" /* ignore totally */
+
+struct fstab {
+ char *fs_spec; /* block special device name */
+ char *fs_file; /* file system path prefix */
+ char *fs_vfstype; /* File system type, ufs, nfs */
+ char *fs_mntops; /* Mount options ala -o */
+ char *fs_type; /* FSTAB_* from fs_mntops */
+ int fs_freq; /* dump frequency, in days */
+ int fs_passno; /* pass number on parallel fsck */
+};
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+struct fstab *getfsent(void);
+struct fstab *getfsspec(const char *);
+struct fstab *getfsfile(const char *);
+int setfsent(void);
+void endfsent(void);
+__END_DECLS
+
+#endif /* !_FSTAB_H_ */
diff --git a/include/fts.h b/include/fts.h
new file mode 100644
index 0000000..a5b3aff
--- /dev/null
+++ b/include/fts.h
@@ -0,0 +1,127 @@
+/* $OpenBSD: fts.h,v 1.14 2012/12/05 23:19:57 deraadt Exp $ */
+/* $NetBSD: fts.h,v 1.5 1994/12/28 01:41:50 mycroft Exp $ */
+
+/*
+ * 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.
+ * 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.
+ *
+ * @(#)fts.h 8.3 (Berkeley) 8/14/94
+ */
+
+#ifndef _FTS_H_
+#define _FTS_H_
+
+#include <sys/cdefs.h>
+
+typedef struct {
+ struct _ftsent *fts_cur; /* current node */
+ struct _ftsent *fts_child; /* linked list of children */
+ struct _ftsent **fts_array; /* sort array */
+ dev_t fts_dev; /* starting device # */
+ char *fts_path; /* path for this descent */
+ int fts_rfd; /* fd for root */
+ size_t fts_pathlen; /* sizeof(path) */
+ int fts_nitems; /* elements in the sort array */
+ int (*fts_compar)(); /* compare function */
+
+#define FTS_COMFOLLOW 0x0001 /* follow command line symlinks */
+#define FTS_LOGICAL 0x0002 /* logical walk */
+#define FTS_NOCHDIR 0x0004 /* don't change directories */
+#define FTS_NOSTAT 0x0008 /* don't get stat info */
+#define FTS_PHYSICAL 0x0010 /* physical walk */
+#define FTS_SEEDOT 0x0020 /* return dot and dot-dot */
+#define FTS_XDEV 0x0040 /* don't cross devices */
+#define FTS_OPTIONMASK 0x00ff /* valid user option mask */
+
+#define FTS_NAMEONLY 0x1000 /* (private) child names only */
+#define FTS_STOP 0x2000 /* (private) unrecoverable error */
+ int fts_options; /* fts_open options, global flags */
+} FTS;
+
+typedef struct _ftsent {
+ struct _ftsent *fts_cycle; /* cycle node */
+ struct _ftsent *fts_parent; /* parent directory */
+ struct _ftsent *fts_link; /* next file in directory */
+ long fts_number; /* local numeric value */
+ void *fts_pointer; /* local address value */
+ char *fts_accpath; /* access path */
+ char *fts_path; /* root path */
+ int fts_errno; /* errno for this node */
+ int fts_symfd; /* fd for symlink */
+ size_t fts_pathlen; /* strlen(fts_path) */
+ size_t fts_namelen; /* strlen(fts_name) */
+
+ ino_t fts_ino; /* inode */
+ dev_t fts_dev; /* device */
+ nlink_t fts_nlink; /* link count */
+
+#define FTS_ROOTPARENTLEVEL -1
+#define FTS_ROOTLEVEL 0
+#define FTS_MAXLEVEL 0x7fffffff
+ int fts_level; /* depth (-1 to N) */
+
+#define FTS_D 1 /* preorder directory */
+#define FTS_DC 2 /* directory that causes cycles */
+#define FTS_DEFAULT 3 /* none of the above */
+#define FTS_DNR 4 /* unreadable directory */
+#define FTS_DOT 5 /* dot or dot-dot */
+#define FTS_DP 6 /* postorder directory */
+#define FTS_ERR 7 /* error; errno is set */
+#define FTS_F 8 /* regular file */
+#define FTS_INIT 9 /* initialized only */
+#define FTS_NS 10 /* stat(2) failed */
+#define FTS_NSOK 11 /* no stat(2) requested */
+#define FTS_SL 12 /* symbolic link */
+#define FTS_SLNONE 13 /* symbolic link without target */
+ unsigned short fts_info; /* user flags for FTSENT structure */
+
+#define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */
+#define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */
+ unsigned short fts_flags; /* private flags for FTSENT structure */
+
+#define FTS_AGAIN 1 /* read node again */
+#define FTS_FOLLOW 2 /* follow symbolic link */
+#define FTS_NOINSTR 3 /* no instructions */
+#define FTS_SKIP 4 /* discard node */
+ unsigned short fts_instr; /* fts_set() instructions */
+
+ unsigned short fts_spare; /* unused */
+
+ struct stat *fts_statp; /* stat(2) information */
+ char fts_name[1]; /* file name */
+} FTSENT;
+
+__BEGIN_DECLS
+FTSENT *fts_children(FTS *, int);
+int fts_close(FTS *);
+FTS *fts_open(char * const *, int,
+ int (*)(const FTSENT **, const FTSENT **));
+FTSENT *fts_read(FTS *);
+int fts_set(FTS *, FTSENT *, int);
+__END_DECLS
+
+#endif /* !_FTS_H_ */
diff --git a/include/ftw.h b/include/ftw.h
new file mode 100644
index 0000000..9947815
--- /dev/null
+++ b/include/ftw.h
@@ -0,0 +1,60 @@
+/* $OpenBSD: ftw.h,v 1.2 2019/01/25 00:19:25 millert Exp $ */
+
+/*
+ * Copyright (c) 2003 Todd C. Miller <millert@openbsd.org>
+ *
+ * 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.
+ *
+ * Sponsored in part by the Defense Advanced Research Projects
+ * Agency (DARPA) and Air Force Research Laboratory, Air Force
+ * Materiel Command, USAF, under agreement number F39502-99-1-0512.
+ */
+
+#ifndef _FTW_H
+#define _FTW_H
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+/*
+ * Valid flags for the 3rd argument to the function that is passed as the
+ * second argument to ftw(3) and nftw(3). Say it three times fast!
+ */
+#define FTW_F 0 /* File. */
+#define FTW_D 1 /* Directory. */
+#define FTW_DNR 2 /* Directory without read permission. */
+#define FTW_DP 3 /* Directory with subdirectories visited. */
+#define FTW_NS 4 /* Unknown type; stat() failed. */
+#define FTW_SL 5 /* Symbolic link. */
+#define FTW_SLN 6 /* Sym link that names a nonexistent file. */
+
+/*
+ * Flags for use as the 4th argument to nftw(3). These may be ORed together.
+ */
+#define FTW_PHYS 0x01 /* Physical walk, don't follow sym links. */
+#define FTW_MOUNT 0x02 /* The walk does not cross a mount point. */
+#define FTW_DEPTH 0x04 /* Subdirs visited before the dir itself. */
+#define FTW_CHDIR 0x08 /* Change to a directory before reading it. */
+
+struct FTW {
+ int base;
+ int level;
+};
+
+__BEGIN_DECLS
+int ftw(const char *, int (*)(const char *, const struct stat *, int), int);
+int nftw(const char *, int (*)(const char *, const struct stat *, int,
+ struct FTW *), int, int);
+__END_DECLS
+
+#endif /* !_FTW_H */
diff --git a/include/getopt.h b/include/getopt.h
new file mode 100644
index 0000000..dd51864
--- /dev/null
+++ b/include/getopt.h
@@ -0,0 +1,76 @@
+/* $OpenBSD: getopt.h,v 1.3 2013/11/22 21:32:49 millert Exp $ */
+/* $NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $ */
+
+/*-
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Dieter Baron and Thomas Klausner.
+ *
+ * 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.
+ */
+
+#ifndef _GETOPT_H_
+#define _GETOPT_H_
+
+#include <sys/cdefs.h>
+
+/*
+ * GNU-like getopt_long()
+ */
+#define no_argument 0
+#define required_argument 1
+#define optional_argument 2
+
+struct option {
+ /* name of long option */
+ const char *name;
+ /*
+ * one of no_argument, required_argument, and optional_argument:
+ * whether option takes an argument
+ */
+ int has_arg;
+ /* if not NULL, set *flag to val when option found */
+ int *flag;
+ /* if flag not NULL, value to set *flag to; else return value */
+ int val;
+};
+
+__BEGIN_DECLS
+int getopt_long(int, char * const *, const char *,
+ const struct option *, int *);
+int getopt_long_only(int, char * const *, const char *,
+ const struct option *, int *);
+#ifndef _GETOPT_DEFINED_
+#define _GETOPT_DEFINED_
+int getopt(int, char * const *, const char *);
+
+extern char *optarg; /* getopt(3) external variables */
+extern int opterr;
+extern int optind;
+extern int optopt;
+extern int optreset;
+#endif
+__END_DECLS
+
+#endif /* !_GETOPT_H_ */
diff --git a/include/glob.h b/include/glob.h
new file mode 100644
index 0000000..6e64bca
--- /dev/null
+++ b/include/glob.h
@@ -0,0 +1,103 @@
+/* $OpenBSD: glob.h,v 1.14 2019/02/04 16:45:40 millert Exp $ */
+/* $NetBSD: glob.h,v 1.5 1994/10/26 00:55:56 cgd Exp $ */
+
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Guido van Rossum.
+ *
+ * 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.
+ *
+ * @(#)glob.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _GLOB_H_
+#define _GLOB_H_
+
+#include <sys/stat.h>
+#include <machine/_types.h>
+
+#ifndef _SIZE_T_DEFINED_
+#define _SIZE_T_DEFINED_
+typedef __size_t size_t;
+#endif
+
+struct stat;
+typedef struct {
+ size_t gl_pathc; /* Count of total paths so far. */
+ size_t gl_matchc; /* Count of paths matching pattern. */
+ size_t gl_offs; /* Reserved at beginning of gl_pathv. */
+ int gl_flags; /* Copy of flags parameter to glob. */
+ char **gl_pathv; /* List of paths matching pattern. */
+ struct stat **gl_statv; /* Stat entries corresponding to gl_pathv */
+ /* Copy of errfunc parameter to glob. */
+ int (*gl_errfunc)(const char *, int);
+
+ /*
+ * Alternate filesystem access methods for glob; replacement
+ * versions of closedir(3), readdir(3), opendir(3), stat(2)
+ * and lstat(2).
+ */
+ void (*gl_closedir)(void *);
+ struct dirent *(*gl_readdir)(void *);
+ void *(*gl_opendir)(const char *);
+ int (*gl_lstat)(const char *, struct stat *);
+ int (*gl_stat)(const char *, struct stat *);
+} glob_t;
+
+#define GLOB_APPEND 0x0001 /* Append to output from previous call. */
+#define GLOB_DOOFFS 0x0002 /* Use gl_offs. */
+#define GLOB_ERR 0x0004 /* Return on error. */
+#define GLOB_MARK 0x0008 /* Append / to matching directories. */
+#define GLOB_NOCHECK 0x0010 /* Return pattern itself if nothing matches. */
+#define GLOB_NOSORT 0x0020 /* Don't sort. */
+#define GLOB_NOESCAPE 0x1000 /* Disable backslash escaping. */
+
+#define GLOB_NOSPACE (-1) /* Malloc call failed. */
+#define GLOB_ABORTED (-2) /* Unignored error. */
+#define GLOB_NOMATCH (-3) /* No match and GLOB_NOCHECK not set. */
+#define GLOB_NOSYS (-4) /* Function not supported. */
+
+#if __BSD_VISIBLE
+#define GLOB_ALTDIRFUNC 0x0040 /* Use alternately specified directory funcs. */
+#define GLOB_BRACE 0x0080 /* Expand braces ala csh. */
+#define GLOB_MAGCHAR 0x0100 /* Pattern had globbing characters. */
+#define GLOB_NOMAGIC 0x0200 /* GLOB_NOCHECK without magic chars (csh). */
+#define GLOB_QUOTE 0x0400 /* Quote special chars with \. */
+#define GLOB_TILDE 0x0800 /* Expand tilde names from the passwd file. */
+#define GLOB_LIMIT 0x2000 /* Limit pattern match output to ARG_MAX */
+#define GLOB_KEEPSTAT 0x4000 /* Retain stat data for paths in gl_statv. */
+#define GLOB_ABEND GLOB_ABORTED /* backward compatibility */
+#endif
+
+__BEGIN_DECLS
+int glob(const char *__restrict, int, int (*)(const char *, int),
+ glob_t *__restrict);
+void globfree(glob_t *);
+__END_DECLS
+
+#endif /* !_GLOB_H_ */
diff --git a/include/grp.h b/include/grp.h
new file mode 100644
index 0000000..c59cf96
--- /dev/null
+++ b/include/grp.h
@@ -0,0 +1,4 @@
+#include_next <grp.h>
+#define setgroupent(n) setgrent()
+const char *group_from_gid(gid_t, int);
+int gid_from_group(const char *, gid_t *);
diff --git a/include/icdb.h b/include/icdb.h
new file mode 100644
index 0000000..921e4ed
--- /dev/null
+++ b/include/icdb.h
@@ -0,0 +1,44 @@
+/* $OpenBSD: icdb.h,v 1.4 2016/09/04 14:51:39 nicm Exp $ */
+/*
+ * Copyright (c) 2015 Ted Unangst <tedu@openbsd.org>
+ *
+ * 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.
+ */
+
+#ifndef _ICDB_H_
+#define _ICDB_H_
+
+#include <sys/types.h>
+
+__BEGIN_DECLS
+
+struct icdb;
+
+struct icdb *icdb_new(uint32_t version, uint32_t nentries, uint32_t entrysize,
+ uint32_t nkeys, const uint32_t *keysizes, const uint32_t *keyoffsets);
+
+struct icdb *icdb_open(const char *name, int flags, uint32_t version);
+int icdb_get(struct icdb *db, void *entry, uint32_t idx);
+int icdb_lookup(struct icdb *db, int keynum, const void *key, void *entry,
+ uint32_t *idxp);
+int icdb_nentries(struct icdb *db);
+const void *icdb_entries(struct icdb *db);
+int icdb_update(struct icdb *db, const void *entry, int offset);
+int icdb_add(struct icdb *db, const void *entry);
+int icdb_rehash(struct icdb *db);
+int icdb_save(struct icdb *db, int fd);
+int icdb_close(struct icdb *db);
+
+__END_DECLS
+
+#endif /* !_ICDB_H_ */
diff --git a/include/ieeefp.h b/include/ieeefp.h
new file mode 100644
index 0000000..627ce50
--- /dev/null
+++ b/include/ieeefp.h
@@ -0,0 +1,23 @@
+/* $OpenBSD: ieeefp.h,v 1.4 2009/09/27 21:23:55 martynas Exp $ */
+
+/*
+ * Written by J.T. Conklin, Apr 6, 1995
+ * Public domain.
+ */
+
+#ifndef _IEEEFP_H_
+#define _IEEEFP_H_
+
+#include <sys/cdefs.h>
+#include <machine/ieeefp.h>
+
+__BEGIN_DECLS
+extern fp_rnd fpgetround(void);
+extern fp_rnd fpsetround(fp_rnd);
+extern fp_except fpgetmask(void);
+extern fp_except fpsetmask(fp_except);
+extern fp_except fpgetsticky(void);
+extern fp_except fpsetsticky(fp_except);
+__END_DECLS
+
+#endif /* _IEEEFP_H_ */
diff --git a/include/ifaddrs.h b/include/ifaddrs.h
new file mode 100644
index 0000000..9baa159
--- /dev/null
+++ b/include/ifaddrs.h
@@ -0,0 +1,56 @@
+/* $OpenBSD: ifaddrs.h,v 1.4 2004/01/22 21:48:02 espie Exp $ */
+
+/*
+ * Copyright (c) 1995, 1999
+ * Berkeley Software Design, 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.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, 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 Berkeley Software Design, Inc. 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.
+ *
+ * BSDI ifaddrs.h,v 2.5 2000/02/23 14:51:59 dab Exp
+ */
+
+#ifndef _IFADDRS_H_
+#define _IFADDRS_H_
+
+struct ifaddrs {
+ struct ifaddrs *ifa_next;
+ char *ifa_name;
+ unsigned int ifa_flags;
+ struct sockaddr *ifa_addr;
+ struct sockaddr *ifa_netmask;
+ struct sockaddr *ifa_dstaddr;
+ void *ifa_data;
+};
+
+/*
+ * This may have been defined in <net/if.h>. Note that if <net/if.h> is
+ * to be included it must be included before this header file.
+ */
+#ifndef ifa_broadaddr
+#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */
+#endif
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+extern int getifaddrs(struct ifaddrs **);
+extern void freeifaddrs(struct ifaddrs *);
+__END_DECLS
+
+#endif
diff --git a/include/inttypes.h b/include/inttypes.h
new file mode 100644
index 0000000..b8f4507
--- /dev/null
+++ b/include/inttypes.h
@@ -0,0 +1,262 @@
+/* $OpenBSD: inttypes.h,v 1.13 2019/01/25 00:19:25 millert Exp $ */
+
+/*
+ * Copyright (c) 1997, 2005 Todd C. Miller <millert@openbsd.org>
+ *
+ * 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.
+ */
+
+#ifndef _INTTYPES_H_
+#define _INTTYPES_H_
+
+#include <sys/stdint.h>
+
+#ifdef __cplusplus
+#define __wchar_t wchar_t
+#endif
+
+/*
+ * 7.8.1 Macros for format specifiers
+ *
+ * Each of the following object-like macros expands to a string
+ * literal containing a conversion specifier, possibly modified by
+ * a prefix such as hh, h, l, or ll, suitable for use within the
+ * format argument of a formatted input/output function when
+ * converting the corresponding integer type. These macro names
+ * have the general form of PRI (character string literals for the
+ * fprintf family) or SCN (character string literals for the fscanf
+ * family), followed by the conversion specifier, followed by a
+ * name corresponding to a similar typedef name. For example,
+ * PRIdFAST32 can be used in a format string to print the value of
+ * an integer of type int_fast32_t.
+ */
+
+/* fprintf macros for signed integers */
+#define PRId8 "d" /* int8_t */
+#define PRId16 "d" /* int16_t */
+#define PRId32 "d" /* int32_t */
+#define PRId64 "lld" /* int64_t */
+
+#define PRIdLEAST8 "d" /* int_least8_t */
+#define PRIdLEAST16 "d" /* int_least16_t */
+#define PRIdLEAST32 "d" /* int_least32_t */
+#define PRIdLEAST64 "lld" /* int_least64_t */
+
+#define PRIdFAST8 "d" /* int_fast8_t */
+#define PRIdFAST16 "d" /* int_fast16_t */
+#define PRIdFAST32 "d" /* int_fast32_t */
+#define PRIdFAST64 "lld" /* int_fast64_t */
+
+#define PRIdMAX "jd" /* intmax_t */
+#define PRIdPTR "ld" /* intptr_t */
+
+#define PRIi8 "i" /* int8_t */
+#define PRIi16 "i" /* int16_t */
+#define PRIi32 "i" /* int32_t */
+#define PRIi64 "lli" /* int64_t */
+
+#define PRIiLEAST8 "i" /* int_least8_t */
+#define PRIiLEAST16 "i" /* int_least16_t */
+#define PRIiLEAST32 "i" /* int_least32_t */
+#define PRIiLEAST64 "lli" /* int_least64_t */
+
+#define PRIiFAST8 "i" /* int_fast8_t */
+#define PRIiFAST16 "i" /* int_fast16_t */
+#define PRIiFAST32 "i" /* int_fast32_t */
+#define PRIiFAST64 "lli" /* int_fast64_t */
+
+#define PRIiMAX "ji" /* intmax_t */
+#define PRIiPTR "li" /* intptr_t */
+
+/* fprintf macros for unsigned integers */
+#define PRIo8 "o" /* int8_t */
+#define PRIo16 "o" /* int16_t */
+#define PRIo32 "o" /* int32_t */
+#define PRIo64 "llo" /* int64_t */
+
+#define PRIoLEAST8 "o" /* int_least8_t */
+#define PRIoLEAST16 "o" /* int_least16_t */
+#define PRIoLEAST32 "o" /* int_least32_t */
+#define PRIoLEAST64 "llo" /* int_least64_t */
+
+#define PRIoFAST8 "o" /* int_fast8_t */
+#define PRIoFAST16 "o" /* int_fast16_t */
+#define PRIoFAST32 "o" /* int_fast32_t */
+#define PRIoFAST64 "llo" /* int_fast64_t */
+
+#define PRIoMAX "jo" /* intmax_t */
+#define PRIoPTR "lo" /* intptr_t */
+
+#define PRIu8 "u" /* uint8_t */
+#define PRIu16 "u" /* uint16_t */
+#define PRIu32 "u" /* uint32_t */
+#define PRIu64 "llu" /* uint64_t */
+
+#define PRIuLEAST8 "u" /* uint_least8_t */
+#define PRIuLEAST16 "u" /* uint_least16_t */
+#define PRIuLEAST32 "u" /* uint_least32_t */
+#define PRIuLEAST64 "llu" /* uint_least64_t */
+
+#define PRIuFAST8 "u" /* uint_fast8_t */
+#define PRIuFAST16 "u" /* uint_fast16_t */
+#define PRIuFAST32 "u" /* uint_fast32_t */
+#define PRIuFAST64 "llu" /* uint_fast64_t */
+
+#define PRIuMAX "ju" /* uintmax_t */
+#define PRIuPTR "lu" /* uintptr_t */
+
+#define PRIx8 "x" /* uint8_t */
+#define PRIx16 "x" /* uint16_t */
+#define PRIx32 "x" /* uint32_t */
+#define PRIx64 "llx" /* uint64_t */
+
+#define PRIxLEAST8 "x" /* uint_least8_t */
+#define PRIxLEAST16 "x" /* uint_least16_t */
+#define PRIxLEAST32 "x" /* uint_least32_t */
+#define PRIxLEAST64 "llx" /* uint_least64_t */
+
+#define PRIxFAST8 "x" /* uint_fast8_t */
+#define PRIxFAST16 "x" /* uint_fast16_t */
+#define PRIxFAST32 "x" /* uint_fast32_t */
+#define PRIxFAST64 "llx" /* uint_fast64_t */
+
+#define PRIxMAX "jx" /* uintmax_t */
+#define PRIxPTR "lx" /* uintptr_t */
+
+#define PRIX8 "X" /* uint8_t */
+#define PRIX16 "X" /* uint16_t */
+#define PRIX32 "X" /* uint32_t */
+#define PRIX64 "llX" /* uint64_t */
+
+#define PRIXLEAST8 "X" /* uint_least8_t */
+#define PRIXLEAST16 "X" /* uint_least16_t */
+#define PRIXLEAST32 "X" /* uint_least32_t */
+#define PRIXLEAST64 "llX" /* uint_least64_t */
+
+#define PRIXFAST8 "X" /* uint_fast8_t */
+#define PRIXFAST16 "X" /* uint_fast16_t */
+#define PRIXFAST32 "X" /* uint_fast32_t */
+#define PRIXFAST64 "llX" /* uint_fast64_t */
+
+#define PRIXMAX "jX" /* uintmax_t */
+#define PRIXPTR "lX" /* uintptr_t */
+
+/* fscanf macros for signed integers */
+#define SCNd8 "hhd" /* int8_t */
+#define SCNd16 "hd" /* int16_t */
+#define SCNd32 "d" /* int32_t */
+#define SCNd64 "lld" /* int64_t */
+
+#define SCNdLEAST8 "hhd" /* int_least8_t */
+#define SCNdLEAST16 "hd" /* int_least16_t */
+#define SCNdLEAST32 "d" /* int_least32_t */
+#define SCNdLEAST64 "lld" /* int_least64_t */
+
+#define SCNdFAST8 "d" /* int_fast8_t */
+#define SCNdFAST16 "d" /* int_fast16_t */
+#define SCNdFAST32 "d" /* int_fast32_t */
+#define SCNdFAST64 "lld" /* int_fast64_t */
+
+#define SCNdMAX "jd" /* intmax_t */
+#define SCNdPTR "ld" /* intptr_t */
+
+#define SCNi8 "hhi" /* int8_t */
+#define SCNi16 "hi" /* int16_t */
+#define SCNi32 "i" /* int32_t */
+#define SCNi64 "lli" /* int64_t */
+
+#define SCNiLEAST8 "hhi" /* int_least8_t */
+#define SCNiLEAST16 "hi" /* int_least16_t */
+#define SCNiLEAST32 "i" /* int_least32_t */
+#define SCNiLEAST64 "lli" /* int_least64_t */
+
+#define SCNiFAST8 "i" /* int_fast8_t */
+#define SCNiFAST16 "i" /* int_fast16_t */
+#define SCNiFAST32 "i" /* int_fast32_t */
+#define SCNiFAST64 "lli" /* int_fast64_t */
+
+#define SCNiMAX "ji" /* intmax_t */
+#define SCNiPTR "li" /* intptr_t */
+
+/* fscanf macros for unsigned integers */
+#define SCNo8 "hho" /* uint8_t */
+#define SCNo16 "ho" /* uint16_t */
+#define SCNo32 "o" /* uint32_t */
+#define SCNo64 "llo" /* uint64_t */
+
+#define SCNoLEAST8 "hho" /* uint_least8_t */
+#define SCNoLEAST16 "ho" /* uint_least16_t */
+#define SCNoLEAST32 "o" /* uint_least32_t */
+#define SCNoLEAST64 "llo" /* uint_least64_t */
+
+#define SCNoFAST8 "o" /* uint_fast8_t */
+#define SCNoFAST16 "o" /* uint_fast16_t */
+#define SCNoFAST32 "o" /* uint_fast32_t */
+#define SCNoFAST64 "llo" /* uint_fast64_t */
+
+#define SCNoMAX "jo" /* uintmax_t */
+#define SCNoPTR "lo" /* uintptr_t */
+
+#define SCNu8 "hhu" /* uint8_t */
+#define SCNu16 "hu" /* uint16_t */
+#define SCNu32 "u" /* uint32_t */
+#define SCNu64 "llu" /* uint64_t */
+
+#define SCNuLEAST8 "hhu" /* uint_least8_t */
+#define SCNuLEAST16 "hu" /* uint_least16_t */
+#define SCNuLEAST32 "u" /* uint_least32_t */
+#define SCNuLEAST64 "llu" /* uint_least64_t */
+
+#define SCNuFAST8 "u" /* uint_fast8_t */
+#define SCNuFAST16 "u" /* uint_fast16_t */
+#define SCNuFAST32 "u" /* uint_fast32_t */
+#define SCNuFAST64 "llu" /* uint_fast64_t */
+
+#define SCNuMAX "ju" /* uintmax_t */
+#define SCNuPTR "lu" /* uintptr_t */
+
+#define SCNx8 "hhx" /* uint8_t */
+#define SCNx16 "hx" /* uint16_t */
+#define SCNx32 "x" /* uint32_t */
+#define SCNx64 "llx" /* uint64_t */
+
+#define SCNxLEAST8 "hhx" /* uint_least8_t */
+#define SCNxLEAST16 "hx" /* uint_least16_t */
+#define SCNxLEAST32 "x" /* uint_least32_t */
+#define SCNxLEAST64 "llx" /* uint_least64_t */
+
+#define SCNxFAST8 "x" /* uint_fast8_t */
+#define SCNxFAST16 "x" /* uint_fast16_t */
+#define SCNxFAST32 "x" /* uint_fast32_t */
+#define SCNxFAST64 "llx" /* uint_fast64_t */
+
+#define SCNxMAX "jx" /* uintmax_t */
+#define SCNxPTR "lx" /* uintptr_t */
+
+typedef struct {
+ intmax_t quot; /* quotient */
+ intmax_t rem; /* remainder */
+} imaxdiv_t;
+
+__BEGIN_DECLS
+intmax_t imaxabs(intmax_t);
+imaxdiv_t imaxdiv(intmax_t, intmax_t);
+intmax_t strtoimax(const char *, char **, int);
+uintmax_t strtoumax(const char *, char **, int);
+intmax_t wcstoimax(const __wchar_t * __restrict,
+ __wchar_t ** __restrict, int);
+uintmax_t wcstoumax(const __wchar_t * __restrict,
+ __wchar_t ** __restrict, int);
+__END_DECLS
+
+#endif /* _INTTYPES_H_ */
diff --git a/include/iso646.h b/include/iso646.h
new file mode 100644
index 0000000..535e96b
--- /dev/null
+++ b/include/iso646.h
@@ -0,0 +1,26 @@
+/* $OpenBSD: iso646.h,v 1.3 2001/10/11 00:05:21 espie Exp $ */
+/* $NetBSD: iso646.h,v 1.1 1995/02/17 09:08:10 jtc Exp $ */
+
+/*
+ * Written by J.T. Conklin <jtc@wimsey.com> 02/16/95.
+ * Public domain.
+ */
+
+#ifndef _ISO646_H_
+#define _ISO646_H_
+
+#ifndef __cplusplus
+#define and &&
+#define and_eq &=
+#define bitand &
+#define bitor |
+#define compl ~
+#define not !
+#define not_eq !=
+#define or ||
+#define or_eq |=
+#define xor ^
+#define xor_eq ^=
+#endif
+
+#endif /* !_ISO646_H_ */
diff --git a/include/kvm.h b/include/kvm.h
new file mode 100644
index 0000000..9c83239
--- /dev/null
+++ b/include/kvm.h
@@ -0,0 +1,79 @@
+/* $OpenBSD: kvm.h,v 1.18 2013/10/22 16:40:25 guenther Exp $ */
+/* $NetBSD: kvm.h,v 1.7 1996/04/19 12:02:50 leo Exp $ */
+
+/*-
+ * 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.
+ * 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.
+ *
+ * @(#)kvm.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _KVM_H_
+#define _KVM_H_
+
+/* Default version symbol. */
+#define VRS_SYM "_version"
+#define VRS_KEY "VERSION"
+
+/*
+ * Flag for kvm_open* that disables opening of any files. We're just
+ * interested in a handle to run sysctls.
+ */
+#define KVM_NO_FILES 0x80000000
+
+#include <nlist.h>
+#include <stdio.h>
+
+__BEGIN_DECLS
+
+typedef struct __kvm kvm_t;
+
+struct kinfo_proc;
+int kvm_close(kvm_t *);
+int kvm_dump_inval(kvm_t *);
+int kvm_dump_mkheader(kvm_t *, off_t);
+int kvm_dump_wrtheader(kvm_t *, FILE *, int);
+char **kvm_getargv(kvm_t *, const struct kinfo_proc *, int);
+char **kvm_getenvv(kvm_t *, const struct kinfo_proc *, int);
+char *kvm_geterr(kvm_t *);
+int kvm_getloadavg(kvm_t *, double [], int);
+struct kinfo_file *
+ kvm_getfiles(kvm_t *, int, int, size_t, int *);
+struct kinfo_proc *
+ kvm_getprocs(kvm_t *, int, int, size_t, int *);
+int kvm_nlist(kvm_t *, struct nlist *);
+kvm_t *kvm_open(const char *, const char *, const char *, int, const char *);
+kvm_t *kvm_openfiles(const char *, const char *, const char *,
+ int, char *);
+ssize_t kvm_read(kvm_t *, unsigned long, void *, size_t)
+ __attribute__((__bounded__(__buffer__,3,4)));
+ssize_t kvm_write(kvm_t *, unsigned long, const void *, size_t)
+ __attribute__((__bounded__(__buffer__,3,4)));
+
+__END_DECLS
+
+#endif /* !_KVM_H_ */
diff --git a/include/langinfo.h b/include/langinfo.h
new file mode 100644
index 0000000..dd37bfc
--- /dev/null
+++ b/include/langinfo.h
@@ -0,0 +1,88 @@
+/* $OpenBSD: langinfo.h,v 1.8 2017/09/05 03:16:13 schwarze Exp $ */
+/* $NetBSD: langinfo.h,v 1.3 1995/04/28 23:30:54 jtc Exp $ */
+
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>
+ * Public domain.
+ */
+
+#ifndef _LANGINFO_H_
+#define _LANGINFO_H_
+
+#include <nl_types.h>
+
+#define D_T_FMT 0 /* String for formatting date and time */
+#define D_FMT 1 /* Date format string */
+#define T_FMT 2 /* Time format string */
+#define T_FMT_AMPM 3 /* Time format string with 12 hour clock */
+#define AM_STR 4 /* Ante Meridiem afix */
+#define PM_STR 5 /* Post Meridiem afix */
+
+#define DAY_1 6 /* Name of the first day of the week */
+#define DAY_2 7
+#define DAY_3 8
+#define DAY_4 9
+#define DAY_5 10
+#define DAY_6 11
+#define DAY_7 12
+
+#define ABDAY_1 13 /* Abbrev. name of the first day of the week */
+#define ABDAY_2 14
+#define ABDAY_3 15
+#define ABDAY_4 16
+#define ABDAY_5 17
+#define ABDAY_6 18
+#define ABDAY_7 19
+
+#define MON_1 20 /* Name of the first month */
+#define MON_2 21
+#define MON_3 22
+#define MON_4 23
+#define MON_5 24
+#define MON_6 25
+#define MON_7 26
+#define MON_8 27
+#define MON_9 28
+#define MON_10 29
+#define MON_11 30
+#define MON_12 31
+
+#define ABMON_1 32 /* Abbrev. name of the first month */
+#define ABMON_2 33
+#define ABMON_3 34
+#define ABMON_4 35
+#define ABMON_5 36
+#define ABMON_6 37
+#define ABMON_7 38
+#define ABMON_8 39
+#define ABMON_9 40
+#define ABMON_10 41
+#define ABMON_11 42
+#define ABMON_12 43
+
+#define RADIXCHAR 44 /* Radix character */
+#define THOUSEP 45 /* Separator for thousands */
+#define YESSTR 46 /* Affirmative response for yes/no queries */
+#define YESEXPR 47 /* Affirmative response for yes/no queries */
+#define NOSTR 48 /* Negative response for yes/no queries */
+#define NOEXPR 49 /* Negative response for yes/no queries */
+#define CRNCYSTR 50 /* Currency symbol */
+
+#define CODESET 51 /* Codeset name */
+
+#if __POSIX_VISIBLE >= 200809
+#ifndef _LOCALE_T_DEFINED_
+#define _LOCALE_T_DEFINED_
+typedef void *locale_t;
+#endif
+#endif
+
+__BEGIN_DECLS
+char *nl_langinfo(nl_item);
+
+#if __POSIX_VISIBLE >= 200809
+char *nl_langinfo_l(nl_item, locale_t);
+#endif
+__END_DECLS
+
+#endif /* _LANGINFO_H_ */
diff --git a/include/libgen.h b/include/libgen.h
new file mode 100644
index 0000000..4312373
--- /dev/null
+++ b/include/libgen.h
@@ -0,0 +1,29 @@
+/* $OpenBSD: libgen.h,v 1.9 2019/01/25 00:19:25 millert Exp $ */
+
+/*
+ * Copyright (c) 1997 Todd C. Miller <millert@openbsd.org>
+ *
+ * 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.
+ */
+
+#ifndef _LIBGEN_H_
+#define _LIBGEN_H_
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+char *basename(const char *);
+char *dirname(const char *);
+__END_DECLS
+
+#endif /* _LIBGEN_H_ */
diff --git a/include/limits.h b/include/limits.h
new file mode 100644
index 0000000..08913b4
--- /dev/null
+++ b/include/limits.h
@@ -0,0 +1,117 @@
+/* $OpenBSD: limits.h,v 1.19 2015/01/20 22:09:50 tedu Exp $ */
+/* $NetBSD: limits.h,v 1.7 1994/10/26 00:56:00 cgd Exp $ */
+
+/*
+ * Copyright (c) 1988 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.
+ *
+ * @(#)limits.h 5.9 (Berkeley) 4/3/91
+ */
+
+#ifndef _LIMITS_H_
+#define _LIMITS_H_
+
+#include <sys/cdefs.h>
+
+#if __POSIX_VISIBLE
+#define _POSIX_ARG_MAX 4096
+#define _POSIX_CHILD_MAX 25
+#define _POSIX_LINK_MAX 8
+#define _POSIX_MAX_CANON 255
+#define _POSIX_MAX_INPUT 255
+#define _POSIX_NAME_MAX 14
+#define _POSIX_PATH_MAX 256
+#define _POSIX_PIPE_BUF 512
+#define _POSIX_RE_DUP_MAX 255
+#define _POSIX_SEM_NSEMS_MAX 256
+#define _POSIX_SEM_VALUE_MAX 32767
+#define _POSIX_SSIZE_MAX 32767
+#define _POSIX_STREAM_MAX 8
+#define _POSIX_SYMLINK_MAX 255
+#define _POSIX_SYMLOOP_MAX 8
+#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4
+#define _POSIX_THREAD_KEYS_MAX 128
+#define _POSIX_THREAD_THREADS_MAX 4
+
+#if __POSIX_VISIBLE >= 200112
+#define _POSIX_CLOCKRES_MIN 20000000
+#define _POSIX_NGROUPS_MAX 8
+#define _POSIX_OPEN_MAX 20
+#define _POSIX_TZNAME_MAX 6
+#else
+#define _POSIX_NGROUPS_MAX 0
+#define _POSIX_OPEN_MAX 16
+#define _POSIX_TZNAME_MAX 3
+#endif
+
+#define _POSIX2_BC_BASE_MAX 99
+#define _POSIX2_BC_DIM_MAX 2048
+#define _POSIX2_BC_SCALE_MAX 99
+#define _POSIX2_BC_STRING_MAX 1000
+#define _POSIX2_COLL_WEIGHTS_MAX 2
+#define _POSIX2_EXPR_NEST_MAX 32
+#define _POSIX2_LINE_MAX 2048
+#define _POSIX2_RE_DUP_MAX _POSIX_RE_DUP_MAX
+#define _POSIX2_CHARCLASS_NAME_MAX 14
+
+#if __POSIX_VISIBLE >= 200112
+#define _POSIX_HOST_NAME_MAX 255
+#define _POSIX_LOGIN_NAME_MAX 9 /* includes trailing NUL */
+#define _POSIX_TTY_NAME_MAX 9 /* includes trailing NUL */
+#endif /* __POSIX_VISIBLE >= 200112 */
+#endif /* __POSIX_VISIBLE */
+
+#if __XPG_VISIBLE || __POSIX_VISIBLE >= 200809
+#define NL_ARGMAX 9
+#define NL_LANGMAX 14
+#define NL_MSGMAX 32767
+#define NL_SETMAX 255
+#define NL_TEXTMAX 255
+#endif
+
+#if __XPG_VISIBLE
+# if __XPG_VISIBLE < 600
+# define PASS_MAX 128 /* _PASSWORD_LEN from <pwd.h> */
+# define TMP_MAX 0x7fffffff /* more, but don't overflow int */
+# endif
+
+# if __XPG_VISIBLE < 700
+# define NL_NMAX 1
+# endif
+
+#define _XOPEN_IOV_MAX 16
+#define _XOPEN_NAME_MAX 255
+#define _XOPEN_PATH_MAX 1024
+#endif /* __XPG_VISIBLE */
+
+#include <sys/limits.h>
+
+#if __POSIX_VISIBLE
+#include <sys/syslimits.h>
+#endif
+
+#endif /* !_LIMITS_H_ */
diff --git a/include/link.h b/include/link.h
new file mode 100644
index 0000000..cee7157
--- /dev/null
+++ b/include/link.h
@@ -0,0 +1,149 @@
+/* $OpenBSD: link.h,v 1.15 2013/10/19 09:00:18 deraadt Exp $ */
+/* $NetBSD: link.h,v 1.10 1996/01/09 00:00:11 pk Exp $ */
+
+/*
+ * Copyright (c) 1993 Paul Kranenburg
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Paul Kranenburg.
+ * 4. 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.
+ */
+
+
+#ifndef _LINK_H_
+#define _LINK_H_
+
+#ifdef __ELF__
+#include <link_elf.h>
+#endif
+
+/*
+ * A `Shared Object Descriptor' describes a shared object that is needed
+ * to complete the link edit process of the object containing it.
+ * A list of such objects (chained through `sod_next') is pointed at
+ * by `sdt_sods' in the section_dispatch_table structure.
+ */
+
+struct sod { /* Shared Object Descriptor */
+ long sod_name; /* name (relative to load address) */
+ unsigned int sod_library : 1,/* Searched for by library rules */
+ sod_reserved : 31;
+ short sod_major; /* major version number */
+ short sod_minor; /* minor version number */
+ long sod_next; /* next sod */
+};
+
+/*
+ * `Shared Object Map's are used by the run-time link editor (ld.so) to
+ * keep track of all shared objects loaded into a process' address space.
+ * These structures are only used at run-time and do not occur within
+ * the text or data segment of an executable or shared library.
+ */
+struct so_map { /* Shared Object Map */
+ caddr_t som_addr; /* Address at which object mapped */
+ char *som_path; /* Path to mmap'ed file */
+ struct so_map *som_next; /* Next map in chain */
+ struct sod *som_sod; /* Sod responsible for this map */
+ caddr_t som_sodbase; /* Base address of this sod */
+ unsigned int som_write : 1; /* Text is currently writable */
+ struct _dynamic *som_dynamic; /* _dynamic structure */
+ caddr_t som_spd; /* Private data */
+};
+
+
+/*
+ * Debug rendezvous struct. Pointer to this is set up in the
+ * target code pointed by the DT_DEBUG tag. If it is
+ * defined.
+ */
+struct r_debug {
+ int r_version; /* Protocol version. */
+ struct link_map *r_map; /* Head of list of loaded objects. */
+
+ /*
+ * This is the address of a function internal to the run-time linker,
+ * that will always be called when the linker begins to map in a
+ * library or unmap it, and again when the mapping change is complete.
+ * The debugger can set a breakpoint at this address if it wants to
+ * notice shared object mapping changes.
+ */
+ unsigned long r_brk;
+ enum {
+ /*
+ * This state value describes the mapping change taking place
+ * when the `r_brk' address is called.
+ */
+ RT_CONSISTENT, /* Mapping change is complete. */
+ RT_ADD, /* Adding a new object. */
+ RT_DELETE /* Removing an object mapping. */
+ } r_state;
+
+ unsigned long r_ldbase; /* Base address the linker is loaded at. */
+};
+
+
+
+/*
+ * Maximum number of recognized shared object version numbers.
+ */
+#define MAXDEWEY 8
+
+/*
+ * Header of the hints file.
+ */
+struct hints_header {
+ long hh_magic;
+#define HH_MAGIC 011421044151
+ long hh_version; /* Interface version number */
+#define LD_HINTS_VERSION_1 1
+#define LD_HINTS_VERSION_2 2
+ long hh_hashtab; /* Location of hash table */
+ long hh_nbucket; /* Number of buckets in hashtab */
+ long hh_strtab; /* Location of strings */
+ long hh_strtab_sz; /* Size of strings */
+ long hh_ehints; /* End of hints (max offset in file) */
+ long hh_dirlist; /* Colon-separated list of srch dirs */
+};
+
+#define HH_BADMAG(hdr) ((hdr).hh_magic != HH_MAGIC)
+
+/*
+ * Hash table element in hints file.
+ */
+struct hints_bucket {
+ /* namex and pathx are indices into the string table */
+ int hi_namex; /* Library name */
+ int hi_pathx; /* Full path */
+ int hi_dewey[MAXDEWEY]; /* The versions */
+ int hi_ndewey; /* Number of version numbers */
+#define hi_major hi_dewey[0]
+#define hi_minor hi_dewey[1]
+ int hi_next; /* Next in this bucket */
+};
+
+#define _PATH_LD_HINTS "/var/run/ld.so.hints"
+
+#endif /* _LINK_H_ */
+
diff --git a/include/link_elf.h b/include/link_elf.h
new file mode 100644
index 0000000..45fc1b9
--- /dev/null
+++ b/include/link_elf.h
@@ -0,0 +1,42 @@
+/* $OpenBSD: link_elf.h,v 1.7 2016/09/20 18:24:55 kettenis Exp $ */
+
+/*
+ * Public domain.
+ */
+
+#ifndef _LINK_ELF_H
+#define _LINK_ELF_H
+
+#include <elf_abi.h>
+
+#ifndef DT_PROCNUM
+#define DT_PROCNUM 0
+#endif
+
+/*
+ * struct link_map is a part of the protocol between the debugger and
+ * ld.so. ld.so may have additional fields in it's version of this
+ * structure but those are ld.so private fields.
+ */
+struct link_map {
+ caddr_t l_addr; /* Base address of library */
+ const char *l_name; /* Absolute path to library */
+ void *l_ld; /* pointer to _DYNAMIC */
+ struct link_map *l_next;
+ struct link_map *l_prev;
+};
+
+struct dl_phdr_info {
+ Elf_Addr dlpi_addr;
+ const char *dlpi_name;
+ const Elf_Phdr *dlpi_phdr;
+ Elf_Half dlpi_phnum;
+};
+
+__BEGIN_DECLS
+int dl_iterate_phdr (int (*)(struct dl_phdr_info *, size_t, void *),
+ void *);
+void *dl_unwind_find_exidx(const void *, int *);
+__END_DECLS
+
+#endif /* !_LINK_ELF_H */
diff --git a/include/locale.h b/include/locale.h
new file mode 100644
index 0000000..7818996
--- /dev/null
+++ b/include/locale.h
@@ -0,0 +1,112 @@
+/* $OpenBSD: locale.h,v 1.11 2017/09/05 03:16:13 schwarze Exp $ */
+/* $NetBSD: locale.h,v 1.6 1994/10/26 00:56:02 cgd Exp $ */
+
+/*
+ * Copyright (c) 1991 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.
+ *
+ * @(#)locale.h 5.2 (Berkeley) 2/24/91
+ */
+
+#ifndef _LOCALE_H_
+#define _LOCALE_H_
+
+#include <sys/_null.h>
+
+struct lconv {
+ char *decimal_point;
+ char *thousands_sep;
+ char *grouping;
+ char *int_curr_symbol;
+ char *currency_symbol;
+ char *mon_decimal_point;
+ char *mon_thousands_sep;
+ char *mon_grouping;
+ char *positive_sign;
+ char *negative_sign;
+ char int_frac_digits;
+ char frac_digits;
+ char p_cs_precedes;
+ char p_sep_by_space;
+ char n_cs_precedes;
+ char n_sep_by_space;
+ char p_sign_posn;
+ char n_sign_posn;
+ char int_p_cs_precedes;
+ char int_p_sep_by_space;
+ char int_n_cs_precedes;
+ char int_n_sep_by_space;
+ char int_p_sign_posn;
+ char int_n_sign_posn;
+};
+
+#define LC_ALL 0
+#define LC_COLLATE 1
+#define LC_CTYPE 2
+#define LC_MONETARY 3
+#define LC_NUMERIC 4
+#define LC_TIME 5
+#define LC_MESSAGES 6
+
+#define _LC_LAST 7 /* marks end */
+
+#include <sys/cdefs.h>
+
+#if __POSIX_VISIBLE >= 200809
+
+#ifndef _LOCALE_T_DEFINED_
+#define _LOCALE_T_DEFINED_
+typedef void *locale_t;
+#endif
+
+#define LC_COLLATE_MASK (1 << LC_COLLATE)
+#define LC_CTYPE_MASK (1 << LC_CTYPE)
+#define LC_MONETARY_MASK (1 << LC_MONETARY)
+#define LC_NUMERIC_MASK (1 << LC_NUMERIC)
+#define LC_TIME_MASK (1 << LC_TIME)
+#define LC_MESSAGES_MASK (1 << LC_MESSAGES)
+
+#define LC_ALL_MASK ((1 << _LC_LAST) - 2)
+
+#define LC_GLOBAL_LOCALE ((locale_t)-1)
+
+#endif /* __POSIX_VISIBLE >= 200809 */
+
+
+__BEGIN_DECLS
+struct lconv *localeconv(void);
+char *setlocale(int, const char *);
+
+#if __POSIX_VISIBLE >= 200809
+locale_t duplocale(locale_t);
+void freelocale(locale_t);
+locale_t newlocale(int, const char *, locale_t);
+locale_t uselocale(locale_t);
+#endif
+__END_DECLS
+
+#endif /* _LOCALE_H_ */
diff --git a/include/login_cap.h b/include/login_cap.h
new file mode 100644
index 0000000..46a8bb6
--- /dev/null
+++ b/include/login_cap.h
@@ -0,0 +1,110 @@
+/* $OpenBSD: login_cap.h,v 1.16 2018/07/29 19:40:41 deraadt Exp $ */
+
+/*-
+ * Copyright (c) 1995,1997 Berkeley Software Design, 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Berkeley Software Design,
+ * Inc.
+ * 4. The name of Berkeley Software Design, Inc. may not be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN, 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 BERKELEY SOFTWARE DESIGN, INC. 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.
+ *
+ * BSDI $From: login_cap.h,v 2.11 1999/09/08 18:11:57 prb Exp $
+ */
+
+#ifndef _LOGIN_CAP_H_
+#define _LOGIN_CAP_H_
+
+#define LOGIN_DEFCLASS "default"
+#define LOGIN_DEFSTYLE "passwd"
+#define LOGIN_DEFSERVICE "login"
+#define LOGIN_DEFUMASK 022
+#define _PATH_LOGIN_CONF "/etc/login.conf"
+#define _PATH_AUTHPROGDIR "/usr/libexec/auth"
+#define _PATH_AUTHPROG "/usr/libexec/auth/login_"
+
+#define LOGIN_SETGROUP 0x0001 /* Set group */
+#define LOGIN_SETLOGIN 0x0002 /* Set login */
+#define LOGIN_SETPATH 0x0004 /* Set path */
+#define LOGIN_SETPRIORITY 0x0008 /* Set priority */
+#define LOGIN_SETRESOURCES 0x0010 /* Set resource limits */
+#define LOGIN_SETUMASK 0x0020 /* Set umask */
+#define LOGIN_SETUSER 0x0040 /* Set user */
+#define LOGIN_SETENV 0x0080 /* Set environment */
+#define LOGIN_SETALL 0x00ff /* Set all. */
+
+#define BI_AUTH "authorize" /* Accepted authentication */
+#define BI_REJECT "reject" /* Rejected authentication */
+#define BI_CHALLENGE "reject challenge" /* Reject with a challenge */
+#define BI_SILENT "reject silent" /* Reject silently */
+#define BI_REMOVE "remove" /* remove file on error */
+#define BI_ROOTOKAY "authorize root" /* root authenticated */
+#define BI_SECURE "authorize secure" /* okay on non-secure line */
+#define BI_SETENV "setenv" /* set environment variable */
+#define BI_UNSETENV "unsetenv" /* unset environment variable */
+#define BI_VALUE "value" /* set local variable */
+#define BI_EXPIRED "reject expired" /* account expired */
+#define BI_PWEXPIRED "reject pwexpired" /* password expired */
+#define BI_FDPASS "fd" /* child is passing an fd */
+
+/*
+ * bits which can be returned by authenticate()/auth_scan()
+ */
+#define AUTH_OKAY 0x01 /* user authenticated */
+#define AUTH_ROOTOKAY 0x02 /* authenticated as root */
+#define AUTH_SECURE 0x04 /* secure login */
+#define AUTH_SILENT 0x08 /* silent rejection */
+#define AUTH_CHALLENGE 0x10 /* a challenge was given */
+#define AUTH_EXPIRED 0x20 /* account expired */
+#define AUTH_PWEXPIRED 0x40 /* password expired */
+
+#define AUTH_ALLOW (AUTH_OKAY | AUTH_ROOTOKAY | AUTH_SECURE)
+
+typedef struct login_cap {
+ char *lc_class;
+ char *lc_cap;
+ char *lc_style;
+} login_cap_t;
+
+#include <sys/cdefs.h>
+__BEGIN_DECLS
+struct passwd;
+
+login_cap_t *login_getclass(char *);
+void login_close(login_cap_t *);
+int login_getcapbool(login_cap_t *, char *, unsigned int);
+quad_t login_getcapnum(login_cap_t *, char *, quad_t, quad_t);
+quad_t login_getcapsize(login_cap_t *, char *, quad_t, quad_t);
+char *login_getcapstr(login_cap_t *, char *, char *, char *);
+quad_t login_getcaptime(login_cap_t *, char *, quad_t, quad_t);
+char *login_getstyle(login_cap_t *, char *, char *);
+
+int secure_path(char *);
+int setclasscontext(char *, unsigned int);
+int setusercontext(login_cap_t *, struct passwd *, uid_t, unsigned int);
+
+__END_DECLS
+
+#endif /* _LOGIN_CAP_H_ */
diff --git a/include/machine/endian.h b/include/machine/endian.h
new file mode 100644
index 0000000..2dc4d83
--- /dev/null
+++ b/include/machine/endian.h
@@ -0,0 +1 @@
+#include <endian.h>
diff --git a/include/math.h b/include/math.h
new file mode 100644
index 0000000..e6dd268
--- /dev/null
+++ b/include/math.h
@@ -0,0 +1,497 @@
+/* $OpenBSD: math.h,v 1.36 2018/03/10 20:52:58 kettenis Exp $ */
+/*
+ * ====================================================
+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
+ *
+ * Developed at SunPro, a Sun Microsystems, Inc. business.
+ * Permission to use, copy, modify, and distribute this
+ * software is freely granted, provided that this notice
+ * is preserved.
+ * ====================================================
+ */
+
+/*
+ * from: @(#)fdlibm.h 5.1 93/09/24
+ */
+
+#ifndef _MATH_H_
+#define _MATH_H_
+
+#include <sys/_types.h>
+#include <sys/limits.h>
+
+__BEGIN_DECLS
+/*
+ * ANSI/POSIX
+ */
+extern char __infinity[];
+#if __GNUC_PREREQ__(3, 3)
+#define HUGE_VAL __builtin_huge_val()
+#else /* __GNUC_PREREQ__(3, 3) */
+#define HUGE_VAL (*(double *)(void *)__infinity)
+#endif /* __GNUC_PREREQ__(3, 3) */
+
+/*
+ * C99
+ */
+#if __ISO_C_VISIBLE >= 1999
+typedef __double_t double_t;
+typedef __float_t float_t;
+
+#if __GNUC_PREREQ__(3, 3)
+#define HUGE_VALF __builtin_huge_valf()
+#define HUGE_VALL __builtin_huge_vall()
+#define INFINITY __builtin_inff()
+#define NAN __builtin_nanf("")
+#else /* __GNUC_PREREQ__(3, 3) */
+#define HUGE_VALF ((float)HUGE_VAL)
+#define HUGE_VALL ((long double)HUGE_VAL)
+#define INFINITY HUGE_VALF
+extern char __nan[];
+#define NAN (*(float *)(void *)__nan)
+#endif /* __GNUC_PREREQ__(3, 3) */
+
+#define FP_INFINITE 0x01
+#define FP_NAN 0x02
+#define FP_NORMAL 0x04
+#define FP_SUBNORMAL 0x08
+#define FP_ZERO 0x10
+
+#define FP_ILOGB0 (-INT_MAX)
+#define FP_ILOGBNAN INT_MAX
+
+#ifdef __FP_FAST_FMA
+#define FP_FAST_FMA 1
+#endif /* __FP_FAST_FMA */
+
+#ifdef __FP_FAST_FMAF
+#define FP_FAST_FMAF 1
+#endif /* __FP_FAST_FMAF */
+
+#ifdef __FP_FAST_FMAL
+#define FP_FAST_FMAL 1
+#endif /* __FP_FAST_FMAL */
+
+#define MATH_ERRNO 1
+#define MATH_ERREXCEPT 2
+#define math_errhandling MATH_ERREXCEPT
+
+#define fpclassify(x) \
+ ((sizeof (x) == sizeof (float)) ? \
+ __fpclassifyf(x) \
+ : (sizeof (x) == sizeof (double)) ? \
+ __fpclassify(x) \
+ : __fpclassifyl(x))
+#define isfinite(x) \
+ ((sizeof (x) == sizeof (float)) ? \
+ __isfinitef(x) \
+ : (sizeof (x) == sizeof (double)) ? \
+ __isfinite(x) \
+ : __isfinitel(x))
+#define isnormal(x) \
+ ((sizeof (x) == sizeof (float)) ? \
+ __isnormalf(x) \
+ : (sizeof (x) == sizeof (double)) ? \
+ __isnormal(x) \
+ : __isnormall(x))
+#define signbit(x) \
+ ((sizeof (x) == sizeof (float)) ? \
+ __signbitf(x) \
+ : (sizeof (x) == sizeof (double)) ? \
+ __signbit(x) \
+ : __signbitl(x))
+
+#define isgreater(x, y) (!isunordered((x), (y)) && (x) > (y))
+#define isgreaterequal(x, y) (!isunordered((x), (y)) && (x) >= (y))
+#define isless(x, y) (!isunordered((x), (y)) && (x) < (y))
+#define islessequal(x, y) (!isunordered((x), (y)) && (x) <= (y))
+#define islessgreater(x, y) (!isunordered((x), (y)) && \
+ ((x) > (y) || (y) > (x)))
+#define isunordered(x, y) (isnan(x) || isnan(y))
+#endif /* __ISO_C_VISIBLE >= 1999 */
+
+#define isinf(x) \
+ ((sizeof (x) == sizeof (float)) ? \
+ __isinff(x) \
+ : (sizeof (x) == sizeof (double)) ? \
+ __isinf(x) \
+ : __isinfl(x))
+#define isnan(x) \
+ ((sizeof (x) == sizeof (float)) ? \
+ __isnanf(x) \
+ : (sizeof (x) == sizeof (double)) ? \
+ __isnan(x) \
+ : __isnanl(x))
+
+/*
+ * XOPEN/SVID
+ */
+#if __BSD_VISIBLE || __XPG_VISIBLE
+#define M_E ((double)2.7182818284590452354) /* e */
+#define M_LOG2E ((double)1.4426950408889634074) /* log 2e */
+#define M_LOG10E ((double)0.43429448190325182765) /* log 10e */
+#define M_LN2 ((double)0.69314718055994530942) /* log e2 */
+#define M_LN10 ((double)2.30258509299404568402) /* log e10 */
+#define M_PI ((double)3.14159265358979323846) /* pi */
+#define M_PI_2 ((double)1.57079632679489661923) /* pi/2 */
+#define M_PI_4 ((double)0.78539816339744830962) /* pi/4 */
+#define M_1_PI ((double)0.31830988618379067154) /* 1/pi */
+#define M_2_PI ((double)0.63661977236758134308) /* 2/pi */
+#define M_2_SQRTPI ((double)1.12837916709551257390) /* 2/sqrt(pi) */
+#define M_SQRT2 ((double)1.41421356237309504880) /* sqrt(2) */
+#define M_SQRT1_2 ((double)0.70710678118654752440) /* 1/sqrt(2) */
+
+#define MAXFLOAT ((float)3.40282346638528860e+38)
+
+extern int signgam;
+#endif /* __BSD_VISIBLE || __XPG_VISIBLE */
+
+#if __POSIX_VISIBLE >= 201403
+#define M_El 2.718281828459045235360287471352662498L /* e */
+#define M_LOG2El 1.442695040888963407359924681001892137L /* log 2e */
+#define M_LOG10El 0.434294481903251827651128918916605082L /* log 10e */
+#define M_LN2l 0.693147180559945309417232121458176568L /* log e2 */
+#define M_LN10l 2.302585092994045684017991454684364208L /* log e10 */
+#define M_PIl 3.141592653589793238462643383279502884L /* pi */
+#define M_PI_2l 1.570796326794896619231321691639751442L /* pi/2 */
+#define M_PI_4l 0.785398163397448309615660845819875721L /* pi/4 */
+#define M_1_PIl 0.318309886183790671537767526745028724L /* 1/pi */
+#define M_2_PIl 0.636619772367581343075535053490057448L /* 2/pi */
+#define M_2_SQRTPIl 1.128379167095512573896158903121545172L /* 2/sqrt(pi) */
+#define M_SQRT2l 1.414213562373095048801688724209698079L /* sqrt(2) */
+#define M_SQRT1_2l 0.707106781186547524400844362104849039L /* 1/sqrt(2) */
+#endif /* __POSIX_VISIBLE >= 201403 */
+
+#if __BSD_VISIBLE
+#define HUGE MAXFLOAT
+#endif /* __BSD_VISIBLE */
+
+/*
+ * ANSI/POSIX
+ */
+double acos(double);
+double asin(double);
+double atan(double);
+double atan2(double, double);
+double cos(double);
+double sin(double);
+double tan(double);
+
+double cosh(double);
+double sinh(double);
+double tanh(double);
+
+double exp(double);
+double frexp(double, int *);
+double ldexp(double, int);
+double log(double);
+double log10(double);
+double modf(double, double *);
+
+double pow(double, double);
+double sqrt(double);
+
+double ceil(double);
+double fabs(double);
+double floor(double);
+double fmod(double, double);
+
+/*
+ * C99
+ */
+#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XPG_VISIBLE
+double acosh(double);
+double asinh(double);
+double atanh(double);
+
+double exp2(double);
+double expm1(double);
+int ilogb(double);
+double log1p(double);
+double log2(double);
+double logb(double);
+double scalbn(double, int);
+double scalbln(double, long int);
+
+double cbrt(double);
+double hypot(double, double);
+
+double erf(double);
+double erfc(double);
+double lgamma(double);
+double tgamma(double);
+
+double nearbyint(double);
+double rint(double);
+long int lrint(double);
+long long int llrint(double);
+double round(double);
+long int lround(double);
+long long int llround(double);
+double trunc(double);
+
+double remainder(double, double);
+double remquo(double, double, int *);
+
+double copysign(double, double);
+double nan(const char *);
+double nextafter(double, double);
+double nexttoward(double, long double);
+
+double fdim(double, double);
+double fmax(double, double);
+double fmin(double, double);
+
+double fma(double, double, double);
+#endif /* __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999 || __XPG_VISIBLE */
+
+#if __BSD_VISIBLE || __XPG_VISIBLE
+double j0(double);
+double j1(double);
+double jn(int, double);
+double scalb(double, double);
+double y0(double);
+double y1(double);
+double yn(int, double);
+#endif /* __BSD_VISIBLE || __XPG_VISIBLE */
+
+#if __BSD_VISIBLE || __XPG_VISIBLE <= 500
+double gamma(double);
+#endif /* __BSD_VISIBLE || __XPG_VISIBLE <= 500 */
+
+/*
+ * BSD math library entry points
+ */
+#if __BSD_VISIBLE
+double drem(double, double);
+int finite(double);
+
+/*
+ * Reentrant version of gamma & lgamma; passes signgam back by reference
+ * as the second argument; user must allocate space for signgam.
+ */
+double gamma_r(double, int *);
+double lgamma_r(double, int *);
+
+void sincos(double, double *, double *);
+
+/*
+ * IEEE Test Vector
+ */
+double significand(double);
+#endif /* __BSD_VISIBLE */
+
+/*
+ * Float versions of C99 functions
+ */
+#if __ISO_C_VISIBLE >= 1999
+float acosf(float);
+float asinf(float);
+float atanf(float);
+float atan2f(float, float);
+float cosf(float);
+float sinf(float);
+float tanf(float);
+
+float acoshf(float);
+float asinhf(float);
+float atanhf(float);
+float coshf(float);
+float sinhf(float);
+float tanhf(float);
+
+float expf(float);
+float exp2f(float);
+float expm1f(float);
+float frexpf(float, int *);
+int ilogbf(float);
+float ldexpf(float, int);
+float logf(float);
+float log10f(float);
+float log1pf(float);
+float log2f(float);
+float logbf(float);
+float modff(float, float *);
+float scalbnf(float, int);
+float scalblnf(float, long int);
+
+float cbrtf(float);
+float fabsf(float);
+float hypotf(float, float);
+float powf(float, float);
+float sqrtf(float);
+
+float erff(float);
+float erfcf(float);
+float lgammaf(float);
+float tgammaf(float);
+
+float ceilf(float);
+float floorf(float);
+float nearbyintf(float);
+float rintf(float);
+long int lrintf(float);
+long long int llrintf(float);
+float roundf(float);
+long int lroundf(float);
+long long int llroundf(float);
+float truncf(float);
+
+float fmodf(float, float);
+float remainderf(float, float);
+float remquof(float, float, int *);
+
+float copysignf(float, float);
+float nanf(const char *);
+float nextafterf(float, float);
+float nexttowardf(float, long double);
+
+float fdimf(float, float);
+float fmaxf(float, float);
+float fminf(float, float);
+
+float fmaf(float, float, float);
+#endif /* __ISO_C_VISIBLE >= 1999 */
+
+#if __BSD_VISIBLE || __XPG_VISIBLE
+float j0f(float);
+float j1f(float);
+float jnf(int, float);
+float scalbf(float, float);
+float y0f(float);
+float y1f(float);
+float ynf(int, float);
+#endif /* __BSD_VISIBLE || __XPG_VISIBLE */
+
+#if __BSD_VISIBLE || __XPG_VISIBLE <= 500
+float gammaf(float);
+#endif /* __BSD_VISIBLE || __XPG_VISIBLE <= 500 */
+
+/*
+ * Float versions of BSD math library entry points
+ */
+#if __BSD_VISIBLE
+float dremf(float, float);
+int finitef(float);
+int isinff(float);
+int isnanf(float);
+
+/*
+ * Float versions of reentrant version of gamma & lgamma; passes
+ * signgam back by reference as the second argument; user must
+ * allocate space for signgam.
+ */
+float gammaf_r(float, int *);
+float lgammaf_r(float, int *);
+
+void sincosf(float, float *, float *);
+
+/*
+ * Float version of IEEE Test Vector
+ */
+float significandf(float);
+#endif /* __BSD_VISIBLE */
+
+/*
+ * Long double versions of C99 functions
+ */
+#if __ISO_C_VISIBLE >= 1999
+long double acosl(long double);
+long double asinl(long double);
+long double atanl(long double);
+long double atan2l(long double, long double);
+long double cosl(long double);
+long double sinl(long double);
+long double tanl(long double);
+
+long double acoshl(long double);
+long double asinhl(long double);
+long double atanhl(long double);
+long double coshl(long double);
+long double sinhl(long double);
+long double tanhl(long double);
+
+long double expl(long double);
+long double exp2l(long double);
+long double expm1l(long double);
+long double frexpl(long double, int *);
+int ilogbl(long double);
+long double ldexpl(long double, int);
+long double logl(long double);
+long double log10l(long double);
+long double log1pl(long double);
+long double log2l(long double);
+long double logbl(long double);
+long double modfl(long double, long double *);
+long double scalbnl(long double, int);
+long double scalblnl(long double, long int);
+
+long double cbrtl(long double);
+long double fabsl(long double);
+long double hypotl(long double, long double);
+long double powl(long double, long double);
+long double sqrtl(long double);
+
+long double erfl(long double);
+long double erfcl(long double);
+long double lgammal(long double);
+long double tgammal(long double);
+
+long double ceill(long double);
+long double floorl(long double);
+long double nearbyintl(long double);
+long double rintl(long double);
+long int lrintl(long double);
+long long int llrintl(long double);
+long double roundl(long double);
+long int lroundl(long double);
+long long int llroundl(long double);
+long double truncl(long double);
+
+long double fmodl(long double, long double);
+long double remainderl(long double, long double);
+long double remquol(long double, long double, int *);
+
+long double copysignl(long double, long double);
+long double nanl(const char *);
+long double nextafterl(long double, long double);
+long double nexttowardl(long double, long double);
+
+long double fdiml(long double, long double);
+long double fmaxl(long double, long double);
+long double fminl(long double, long double);
+
+long double fmal(long double, long double, long double);
+#endif /* __ISO_C_VISIBLE >= 1999 */
+
+/*
+ * Long double versions of BSD math library entry points
+ */
+#if __BSD_VISIBLE
+void sincosl(long double, long double *, long double *);
+#endif
+
+/*
+ * Library implementation
+ */
+int __fpclassify(double);
+int __fpclassifyf(float);
+int __fpclassifyl(long double);
+int __isfinite(double);
+int __isfinitef(float);
+int __isfinitel(long double);
+int __isinf(double);
+int __isinff(float);
+int __isinfl(long double);
+int __isnan(double);
+int __isnanf(float);
+int __isnanl(long double);
+int __isnormal(double);
+int __isnormalf(float);
+int __isnormall(long double);
+int __signbit(double);
+int __signbitf(float);
+int __signbitl(long double);
+__END_DECLS
+
+#endif /* !_MATH_H_ */
diff --git a/include/md5.h b/include/md5.h
new file mode 100644
index 0000000..2fa7de8
--- /dev/null
+++ b/include/md5.h
@@ -0,0 +1,49 @@
+/* $OpenBSD: md5.h,v 1.17 2012/12/05 23:19:57 deraadt Exp $ */
+
+/*
+ * This code implements the MD5 message-digest algorithm.
+ * The algorithm is due to Ron Rivest. This code was
+ * written by Colin Plumb in 1993, no copyright is claimed.
+ * This code is in the public domain; do with it what you wish.
+ *
+ * Equivalent code is available from RSA Data Security, Inc.
+ * This code has been tested against that, and is equivalent,
+ * except that you don't need to include two pages of legalese
+ * with every copy.
+ */
+
+#ifndef _MD5_H_
+#define _MD5_H_
+
+#define MD5_BLOCK_LENGTH 64
+#define MD5_DIGEST_LENGTH 16
+#define MD5_DIGEST_STRING_LENGTH (MD5_DIGEST_LENGTH * 2 + 1)
+
+typedef struct MD5Context {
+ u_int32_t state[4]; /* state */
+ u_int64_t count; /* number of bits, mod 2^64 */
+ u_int8_t buffer[MD5_BLOCK_LENGTH]; /* input buffer */
+} MD5_CTX;
+
+__BEGIN_DECLS
+void MD5Init(MD5_CTX *);
+void MD5Update(MD5_CTX *, const u_int8_t *, size_t)
+ __attribute__((__bounded__(__string__,2,3)));
+void MD5Pad(MD5_CTX *);
+void MD5Final(u_int8_t [MD5_DIGEST_LENGTH], MD5_CTX *)
+ __attribute__((__bounded__(__minbytes__,1,MD5_DIGEST_LENGTH)));
+void MD5Transform(u_int32_t [4], const u_int8_t [MD5_BLOCK_LENGTH])
+ __attribute__((__bounded__(__minbytes__,1,4)))
+ __attribute__((__bounded__(__minbytes__,2,MD5_BLOCK_LENGTH)));
+char *MD5End(MD5_CTX *, char *)
+ __attribute__((__bounded__(__minbytes__,2,MD5_DIGEST_STRING_LENGTH)));
+char *MD5File(const char *, char *)
+ __attribute__((__bounded__(__minbytes__,2,MD5_DIGEST_STRING_LENGTH)));
+char *MD5FileChunk(const char *, char *, off_t, off_t)
+ __attribute__((__bounded__(__minbytes__,2,MD5_DIGEST_STRING_LENGTH)));
+char *MD5Data(const u_int8_t *, size_t, char *)
+ __attribute__((__bounded__(__string__,1,2)))
+ __attribute__((__bounded__(__minbytes__,3,MD5_DIGEST_STRING_LENGTH)));
+__END_DECLS
+
+#endif /* _MD5_H_ */
diff --git a/include/memory.h b/include/memory.h
new file mode 100644
index 0000000..b7fadca
--- /dev/null
+++ b/include/memory.h
@@ -0,0 +1,35 @@
+/* $OpenBSD: memory.h,v 1.3 2003/06/02 19:34:12 millert Exp $ */
+/* $NetBSD: memory.h,v 1.3 1994/10/26 00:56:06 cgd Exp $ */
+
+/*
+ * Copyright (c) 1988 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.
+ *
+ * @(#)memory.h 5.5 (Berkeley) 6/1/90
+ */
+
+#include <string.h>
diff --git a/include/ndbm.h b/include/ndbm.h
new file mode 100644
index 0000000..4c1efa9
--- /dev/null
+++ b/include/ndbm.h
@@ -0,0 +1,78 @@
+/* $OpenBSD: ndbm.h,v 1.6 2004/05/03 17:27:50 millert Exp $ */
+/* $NetBSD: ndbm.h,v 1.6 1995/07/20 23:31:11 jtc Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Margo Seltzer.
+ *
+ * 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.
+ *
+ * @(#)ndbm.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _NDBM_H_
+#define _NDBM_H_
+
+#include <db.h>
+
+/* Map dbm interface onto db(3). */
+#define DBM_RDONLY O_RDONLY
+
+/* Flags to dbm_store(). */
+#define DBM_INSERT 0
+#define DBM_REPLACE 1
+
+/*
+ * The db(3) support for ndbm(3) always appends this suffix to the
+ * file name to avoid overwriting the user's original database.
+ */
+#define DBM_SUFFIX ".db"
+
+typedef struct {
+ void *dptr;
+ size_t dsize;
+} datum;
+
+typedef DB DBM;
+#define dbm_pagfno(a) DBM_PAGFNO_NOT_AVAILABLE
+
+__BEGIN_DECLS
+int dbm_clearerr(DBM *);
+void dbm_close(DBM *);
+int dbm_delete(DBM *, datum);
+int dbm_error(DBM *);
+datum dbm_fetch(DBM *, datum);
+datum dbm_firstkey(DBM *);
+datum dbm_nextkey(DBM *);
+DBM *dbm_open(const char *, int, mode_t);
+int dbm_store(DBM *, datum, datum, int);
+int dbm_dirfno(DBM *);
+int dbm_rdonly(DBM *);
+__END_DECLS
+
+#endif /* !_NDBM_H_ */
diff --git a/include/netdb.h b/include/netdb.h
new file mode 100644
index 0000000..0f7303e
--- /dev/null
+++ b/include/netdb.h
@@ -0,0 +1,329 @@
+/* $OpenBSD: netdb.h,v 1.33 2015/01/18 20:29:31 deraadt Exp $ */
+
+/*
+ * ++Copyright++ 1980, 1983, 1988, 1993
+ * -
+ * Copyright (c) 1980, 1983, 1988, 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.
+ * -
+ * Portions Copyright (c) 1993 by Digital Equipment Corporation.
+ *
+ * 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, and that
+ * the name of Digital Equipment Corporation not be used in advertising or
+ * publicity pertaining to distribution of the document or software without
+ * specific, written prior permission.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
+ * CORPORATION 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.
+ * -
+ * --Copyright--
+ */
+
+/*
+ * Copyright (c) 1995, 1996, 1997, 1998, 1999 Craig Metz. 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 author nor the names of any 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.
+ */
+
+/*
+ * @(#)netdb.h 8.1 (Berkeley) 6/2/93
+ * $From: netdb.h,v 8.7 1996/05/09 05:59:09 vixie Exp $
+ */
+
+#ifndef _NETDB_H_
+#define _NETDB_H_
+
+#include <netinet/in.h>
+
+#ifndef _SOCKLEN_T_DEFINED_
+#define _SOCKLEN_T_DEFINED_
+typedef __socklen_t socklen_t; /* length type for network syscalls */
+#endif
+
+#define _PATH_HEQUIV "/etc/hosts.equiv"
+#define _PATH_HOSTS "/etc/hosts"
+#define _PATH_NETWORKS "/etc/networks"
+#define _PATH_PROTOCOLS "/etc/protocols"
+#define _PATH_SERVICES "/etc/services"
+
+/*
+ * Structures returned by network data base library. All addresses are
+ * supplied in host order, and returned in network order (suitable for
+ * use in system calls).
+ */
+struct hostent {
+ char *h_name; /* official name of host */
+ char **h_aliases; /* alias list */
+ int h_addrtype; /* host address type */
+ int h_length; /* length of address */
+ char **h_addr_list; /* list of addresses from name server */
+#define h_addr h_addr_list[0] /* address, for backward compatibility */
+};
+
+/*
+ * Assumption here is that a network number
+ * fits in an in_addr_t -- probably a poor one.
+ */
+struct netent {
+ char *n_name; /* official name of net */
+ char **n_aliases; /* alias list */
+ int n_addrtype; /* net address type */
+ in_addr_t n_net; /* network # */
+};
+
+struct servent {
+ char *s_name; /* official service name */
+ char **s_aliases; /* alias list */
+ int s_port; /* port # */
+ char *s_proto; /* protocol to use */
+};
+
+struct protoent {
+ char *p_name; /* official protocol name */
+ char **p_aliases; /* alias list */
+ int p_proto; /* protocol # */
+};
+
+#if __BSD_VISIBLE || __POSIX_VISIBLE < 200809
+extern int h_errno;
+
+/*
+ * Error return codes from gethostbyname() and gethostbyaddr()
+ * (left in extern int h_errno).
+ */
+
+#define NETDB_INTERNAL -1 /* see errno */
+#define NETDB_SUCCESS 0 /* no problem */
+#define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */
+#define TRY_AGAIN 2 /* Non-Authoritative Host not found, or SERVERFAIL */
+#define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
+#define NO_DATA 4 /* Valid name, no data record of requested type */
+#define NO_ADDRESS NO_DATA /* no address */
+#endif /* __BSD_VISIBLE || __POSIX_VISIBLE < 200809 */
+
+/* Values for getaddrinfo() and getnameinfo() */
+#define AI_PASSIVE 1 /* socket address is intended for bind() */
+#define AI_CANONNAME 2 /* request for canonical name */
+#define AI_NUMERICHOST 4 /* don't ever try hostname lookup */
+#define AI_EXT 8 /* enable non-portable extensions */
+#define AI_NUMERICSERV 16 /* don't ever try servname lookup */
+#define AI_FQDN 32 /* return the FQDN that was resolved */
+#define AI_ADDRCONFIG 64 /* return configured address families only */
+/* valid flags for addrinfo */
+#define AI_MASK \
+ (AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | AI_NUMERICSERV | AI_FQDN | \
+ AI_ADDRCONFIG)
+
+#define NI_NUMERICHOST 1 /* return the host address, not the name */
+#define NI_NUMERICSERV 2 /* return the service address, not the name */
+#define NI_NOFQDN 4 /* return a short name if in the local domain */
+#define NI_NAMEREQD 8 /* fail if either host or service name is unknown */
+#define NI_DGRAM 16 /* look up datagram service instead of stream */
+/* #define NI_NUMERICSCOPE 32 return the scope number, not the name */
+
+#if __BSD_VISIBLE
+#define NI_MAXHOST 256 /* max host name from getnameinfo (MAXHOSTNAMELEN) */
+#define NI_MAXSERV 32 /* max serv. name length returned by getnameinfo */
+
+/*
+ * Scope delimit character (KAME hack)
+ */
+#define SCOPE_DELIMITER '%'
+#endif
+
+#define EAI_BADFLAGS -1 /* invalid value for ai_flags */
+#define EAI_NONAME -2 /* name or service is not known */
+#define EAI_AGAIN -3 /* temporary failure in name resolution */
+#define EAI_FAIL -4 /* non-recoverable failure in name resolution */
+#define EAI_NODATA -5 /* no address associated with name */
+#define EAI_FAMILY -6 /* ai_family not supported */
+#define EAI_SOCKTYPE -7 /* ai_socktype not supported */
+#define EAI_SERVICE -8 /* service not supported for ai_socktype */
+#define EAI_ADDRFAMILY -9 /* address family for name not supported */
+#define EAI_MEMORY -10 /* memory allocation failure */
+#define EAI_SYSTEM -11 /* system error (code indicated in errno) */
+#define EAI_BADHINTS -12 /* invalid value for hints */
+#define EAI_PROTOCOL -13 /* resolved protocol is unknown */
+#define EAI_OVERFLOW -14 /* argument buffer overflow */
+
+struct addrinfo {
+ int ai_flags; /* input flags */
+ int ai_family; /* protocol family for socket */
+ int ai_socktype; /* socket type */
+ int ai_protocol; /* protocol for socket */
+ socklen_t ai_addrlen; /* length of socket-address */
+ struct sockaddr *ai_addr; /* socket-address for socket */
+ char *ai_canonname; /* canonical name for service location (iff req) */
+ struct addrinfo *ai_next; /* pointer to next in list */
+};
+
+#if __BSD_VISIBLE
+/*
+ * Flags for getrrsetbyname()
+ */
+#define RRSET_VALIDATED 1
+
+/*
+ * Return codes for getrrsetbyname()
+ */
+#define ERRSET_SUCCESS 0
+#define ERRSET_NOMEMORY 1
+#define ERRSET_FAIL 2
+#define ERRSET_INVAL 3
+#define ERRSET_NONAME 4
+#define ERRSET_NODATA 5
+
+/*
+ * Structures used by getrrsetbyname() and freerrset()
+ */
+struct rdatainfo {
+ unsigned int rdi_length; /* length of data */
+ unsigned char *rdi_data; /* record data */
+};
+
+struct rrsetinfo {
+ unsigned int rri_flags; /* RRSET_VALIDATED ... */
+ unsigned int rri_rdclass; /* class number */
+ unsigned int rri_rdtype; /* RR type number */
+ unsigned int rri_ttl; /* time to live */
+ unsigned int rri_nrdatas; /* size of rdatas array */
+ unsigned int rri_nsigs; /* size of sigs array */
+ char *rri_name; /* canonical name */
+ struct rdatainfo *rri_rdatas; /* individual records */
+ struct rdatainfo *rri_sigs; /* individual signatures */
+};
+
+struct servent_data {
+ void *fp;
+ char **aliases;
+ int maxaliases;
+ int stayopen;
+ char *line;
+};
+
+struct protoent_data {
+ void *fp;
+ char **aliases;
+ int maxaliases;
+ int stayopen;
+ char *line;
+};
+#endif
+
+__BEGIN_DECLS
+void endhostent(void);
+void endnetent(void);
+void endprotoent(void);
+void endservent(void);
+#if __BSD_VISIBLE || __POSIX_VISIBLE < 200809
+struct hostent *gethostbyaddr(const void *, socklen_t, int);
+struct hostent *gethostbyname(const char *);
+#endif
+#if __BSD_VISIBLE
+struct hostent *gethostbyname2(const char *, int);
+#endif
+struct hostent *gethostent(void);
+struct netent *getnetbyaddr(in_addr_t, int);
+struct netent *getnetbyname(const char *);
+struct netent *getnetent(void);
+struct protoent *getprotobyname(const char *);
+struct protoent *getprotobynumber(int);
+struct protoent *getprotoent(void);
+struct servent *getservbyname(const char *, const char *);
+struct servent *getservbyport(int, const char *);
+struct servent *getservent(void);
+#if __BSD_VISIBLE
+void herror(const char *);
+const char *hstrerror(int);
+#endif
+void sethostent(int);
+/* void sethostfile(const char *); */
+void setnetent(int);
+void setprotoent(int);
+void setservent(int);
+
+#if __BSD_VISIBLE
+void endprotoent_r(struct protoent_data *);
+void endservent_r(struct servent_data *);
+int getprotobyname_r(const char *, struct protoent *,
+ struct protoent_data *);
+int getprotobynumber_r(int, struct protoent *,
+ struct protoent_data *);
+int getservbyname_r(const char *, const char *, struct servent *,
+ struct servent_data *);
+int getservbyport_r(int, const char *, struct servent *,
+ struct servent_data *);
+int getservent_r(struct servent *, struct servent_data *);
+int getprotoent_r(struct protoent *, struct protoent_data *);
+void setprotoent_r(int, struct protoent_data *);
+void setservent_r(int, struct servent_data *);
+#endif
+
+int getaddrinfo(const char *, const char *,
+ const struct addrinfo *, struct addrinfo **);
+void freeaddrinfo(struct addrinfo *);
+int getnameinfo(const struct sockaddr *, socklen_t,
+ char *, size_t, char *, size_t, int);
+const char *gai_strerror(int);
+
+#if __BSD_VISIBLE
+int getrrsetbyname(const char *, unsigned int, unsigned int, unsigned int, struct rrsetinfo **);
+void freerrset(struct rrsetinfo *);
+#endif
+__END_DECLS
+
+#endif /* !_NETDB_H_ */
diff --git a/include/netgroup.h b/include/netgroup.h
new file mode 100644
index 0000000..ce29367
--- /dev/null
+++ b/include/netgroup.h
@@ -0,0 +1,67 @@
+/* $OpenBSD: netgroup.h,v 1.8 2015/09/10 18:59:34 deraadt Exp $ */
+/*
+ * Copyright (c) 1994 Christos Zoulas
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Christos Zoulas.
+ * 4. 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.
+ *
+ */
+#ifndef _NETGROUP_H_
+#define _NETGROUP_H_
+
+#define _PATH_NETGROUP "/etc/netgroup"
+
+#define _PATH_NETGROUP_DB "/etc/netgroup.db"
+
+#define _PATH_NETGROUP_MKDB "/usr/sbin/netgroup_mkdb"
+
+#define _NG_KEYBYNAME '1' /* stored by name */
+#define _NG_KEYBYUSER '2' /* stored by user */
+#define _NG_KEYBYHOST '3' /* stored by host */
+
+#define _NG_ERROR -1
+#define _NG_NONE 0
+#define _NG_NAME 1
+#define _NG_GROUP 2
+
+struct netgroup {
+ char *ng_host; /* host name */
+ char *ng_user; /* user name */
+ char *ng_domain; /* domain name */
+ struct netgroup *ng_next; /* thread */
+};
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+void setnetgrent(const char *);
+int getnetgrent(const char **, const char **, const char **);
+void endnetgrent(void);
+int innetgr(const char *, const char *, const char *, const char *);
+__END_DECLS
+
+#endif /* !_NETGROUP_H_ */
diff --git a/include/netinet/ip.h b/include/netinet/ip.h
new file mode 100644
index 0000000..238358c
--- /dev/null
+++ b/include/netinet/ip.h
@@ -0,0 +1,9 @@
+#include_next <netinet/ip.h>
+#define IPTOS_DSCP_CS0 0x00
+#define IPTOS_DSCP_CS1 0x20
+#define IPTOS_DSCP_CS2 0x40
+#define IPTOS_DSCP_CS3 0x60
+#define IPTOS_DSCP_CS4 0x80
+#define IPTOS_DSCP_CS5 0xa0
+#define IPTOS_DSCP_CS6 0xc0
+#define IPTOS_DSCP_CS7 0xe0
diff --git a/include/nl_types.h b/include/nl_types.h
new file mode 100644
index 0000000..5d03c06
--- /dev/null
+++ b/include/nl_types.h
@@ -0,0 +1,91 @@
+/* $OpenBSD: nl_types.h,v 1.8 2008/06/26 05:42:04 ray Exp $ */
+/* $NetBSD: nl_types.h,v 1.6 1996/05/13 23:11:15 jtc Exp $ */
+
+/*-
+ * Copyright (c) 1996 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by J.T. Conklin.
+ *
+ * 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 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 _NL_TYPES_H_
+#define _NL_TYPES_H_
+#include <sys/cdefs.h>
+
+#ifdef _NLS_PRIVATE
+/*
+ * MESSAGE CATALOG FILE FORMAT.
+ *
+ * The NetBSD message catalog format is similar to the format used by
+ * Svr4 systems. The differences are:
+ * * fixed byte order (big endian)
+ * * fixed data field sizes
+ *
+ * A message catalog contains four data types: a catalog header, one
+ * or more set headers, one or more message headers, and one or more
+ * text strings.
+ */
+
+#define _NLS_MAGIC 0xff88ff89
+
+struct _nls_cat_hdr {
+ int32_t __magic;
+ int32_t __nsets;
+ int32_t __mem;
+ int32_t __msg_hdr_offset;
+ int32_t __msg_txt_offset;
+} ;
+
+struct _nls_set_hdr {
+ int32_t __setno; /* set number: 0 < x <= NL_SETMAX */
+ int32_t __nmsgs; /* number of messages in the set */
+ int32_t __index; /* index of first msg_hdr in msg_hdr table */
+} ;
+
+struct _nls_msg_hdr {
+ int32_t __msgno; /* msg number: 0 < x <= NL_MSGMAX */
+ int32_t __msglen;
+ int32_t __offset;
+} ;
+
+#endif
+
+#define NL_SETD 1
+#define NL_CAT_LOCALE 1
+
+typedef struct _nl_catd {
+ void *__data;
+ int __size;
+} *nl_catd;
+
+typedef long nl_item;
+
+__BEGIN_DECLS
+extern nl_catd catopen(const char *, int);
+extern char *catgets(nl_catd, int, int, const char *);
+extern int catclose(nl_catd);
+__END_DECLS
+
+#endif /* _NL_TYPES_H_ */
diff --git a/include/nlist.h b/include/nlist.h
new file mode 100644
index 0000000..279582c
--- /dev/null
+++ b/include/nlist.h
@@ -0,0 +1,87 @@
+/* $OpenBSD: nlist.h,v 1.4 2003/06/02 19:34:12 millert Exp $ */
+/* $NetBSD: nlist.h,v 1.5 1994/10/26 00:56:11 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)nlist.h 8.2 (Berkeley) 1/21/94
+ */
+
+#ifndef _NLIST_H_
+#define _NLIST_H_
+
+/*
+ * Symbol table entry format. The #ifdef's are so that programs including
+ * nlist.h can initialize nlist structures statically.
+ */
+struct nlist {
+#ifdef _AOUT_INCLUDE_
+ union {
+ char *n_name; /* symbol name (in memory) */
+ long n_strx; /* file string table offset (on disk) */
+ } n_un;
+#else
+ char *n_name; /* symbol name (in memory) */
+#endif
+
+#define N_UNDF 0x00 /* undefined */
+#define N_ABS 0x02 /* absolute address */
+#define N_TEXT 0x04 /* text segment */
+#define N_DATA 0x06 /* data segment */
+#define N_BSS 0x08 /* bss segment */
+#define N_INDR 0x0a /* alias definition */
+#define N_SIZE 0x0c /* pseudo type, defines a symbol's size */
+#define N_COMM 0x12 /* common reference */
+#define N_FN 0x1e /* file name (N_EXT on) */
+#define N_WARN 0x1e /* warning message (N_EXT off) */
+
+#define N_EXT 0x01 /* external (global) bit, OR'ed in */
+#define N_TYPE 0x1e /* mask for all the type bits */
+ unsigned char n_type; /* type defines */
+
+ char n_other; /* spare */
+#define n_hash n_desc /* used internally by ld(1); XXX */
+ short n_desc; /* used by stab entries */
+ unsigned long n_value; /* address/value of the symbol */
+};
+
+#define N_FORMAT "%08x" /* namelist value format; XXX */
+#define N_STAB 0x0e0 /* mask for debugger symbols -- stab(5) */
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+int nlist(const char *, struct nlist *);
+__END_DECLS
+
+#endif /* !_NLIST_H_ */
diff --git a/include/paths.h b/include/paths.h
new file mode 100644
index 0000000..129d0c1
--- /dev/null
+++ b/include/paths.h
@@ -0,0 +1,81 @@
+/* $OpenBSD: paths.h,v 1.26 2019/07/11 03:54:17 tedu Exp $ */
+/* $NetBSD: paths.h,v 1.7 1994/10/26 00:56:12 cgd Exp $ */
+
+/*
+ * 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.
+ * 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.
+ *
+ * @(#)paths.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _PATHS_H_
+#define _PATHS_H_
+
+/* Default search path. */
+#define _PATH_DEFPATH "/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin"
+/* All standard utilities path. */
+#define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin"
+
+#define _PATH_BSHELL "/bin/sh"
+#define _PATH_CONSOLE "/dev/console"
+#define _PATH_CSHELL "/bin/csh"
+#define _PATH_DEFTAPE "/dev/rst0"
+#define _PATH_DEVDB "/var/run/dev.db"
+#define _PATH_DEVNULL "/dev/null"
+#define _PATH_FSIRAND "/sbin/fsirand"
+#define _PATH_KLOG "/dev/klog"
+#define _PATH_KMEM "/dev/kmem"
+#define _PATH_KSHELL "/bin/ksh"
+#define _PATH_KSYMS "/dev/ksyms"
+#define _PATH_KVMDB "/var/db/kvm_bsd.db"
+#define _PATH_LOCALE "/usr/share/locale"
+#define _PATH_LOGCONF "/etc/syslog.conf"
+#define _PATH_LOGPID "/var/run/syslog.pid"
+#define _PATH_MAILDIR "/var/mail"
+#define _PATH_MAN "/usr/share/man"
+#define _PATH_MEM "/dev/mem"
+#define _PATH_NOLOGIN "/etc/nologin"
+#define _PATH_RSH "/usr/bin/ssh"
+#define _PATH_SENDMAIL "/usr/sbin/sendmail"
+#define _PATH_SHELLS "/etc/shells"
+#define _PATH_TTY "/dev/tty"
+#define _PATH_UNIX "/bsd"
+#define _PATH_VI "/usr/bin/vi"
+
+
+/* Provide trailing slash, since mostly used for building pathnames. */
+#define _PATH_BOOTDIR "/usr/mdec/"
+#define _PATH_DEV "/dev/"
+#define _PATH_DEVFD "/dev/fd/"
+#define _PATH_TMP "/tmp/"
+#define _PATH_UUCPLOCK "/var/spool/lock/"
+#define _PATH_VARDB "/var/db/"
+#define _PATH_VAREMPTY "/var/empty/"
+#define _PATH_VARRUN "/var/run/"
+#define _PATH_VARTMP "/var/tmp/"
+
+#endif /* !_PATHS_H_ */
diff --git a/include/poll.h b/include/poll.h
new file mode 100644
index 0000000..cea7b04
--- /dev/null
+++ b/include/poll.h
@@ -0,0 +1,9 @@
+/* $OpenBSD: poll.h,v 1.3 2003/10/29 16:41:13 deraadt Exp $ */
+
+/*
+ * Written by Theo de Raadt, Public Domain
+ *
+ * Typical poll() implementations expect poll.h to be in /usr/include.
+ * However this is not a convenient place for the real definitions.
+ */
+#include <sys/poll.h>
diff --git a/include/protocols/CVS/Entries b/include/protocols/CVS/Entries
new file mode 100644
index 0000000..f53456b
--- /dev/null
+++ b/include/protocols/CVS/Entries
@@ -0,0 +1,6 @@
+/dumprestore.h/1.10/Fri Jul 11 16:01:40 2014//
+/routed.h/1.3/Mon Jun 2 19:34:12 2003//
+/rwhod.h/1.4/Mon Jun 2 19:34:12 2003//
+/talkd.h/1.5/Wed Jan 21 02:23:14 2015//
+/timed.h/1.4/Fri Jan 16 00:27:00 2015//
+D
diff --git a/include/protocols/CVS/Repository b/include/protocols/CVS/Repository
new file mode 100644
index 0000000..c49ead8
--- /dev/null
+++ b/include/protocols/CVS/Repository
@@ -0,0 +1 @@
+src/include/protocols
diff --git a/include/protocols/CVS/Root b/include/protocols/CVS/Root
new file mode 100644
index 0000000..3811072
--- /dev/null
+++ b/include/protocols/CVS/Root
@@ -0,0 +1 @@
+/cvs
diff --git a/include/protocols/dumprestore.h b/include/protocols/dumprestore.h
new file mode 100644
index 0000000..9a94a0c
--- /dev/null
+++ b/include/protocols/dumprestore.h
@@ -0,0 +1,159 @@
+/* $OpenBSD: dumprestore.h,v 1.10 2014/07/11 16:01:40 halex Exp $ */
+/* $NetBSD: dumprestore.h,v 1.14 2005/12/26 19:01:47 perry Exp $ */
+
+/*
+ * Copyright (c) 1980, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)dumprestore.h 8.2 (Berkeley) 1/21/94
+ */
+
+#ifndef _PROTOCOLS_DUMPRESTORE_H_
+#define _PROTOCOLS_DUMPRESTORE_H_
+
+/*
+ * TP_BSIZE is the size of file blocks on the dump tapes.
+ * Note that TP_BSIZE must be a multiple of DEV_BSIZE.
+ *
+ * NTREC is the number of TP_BSIZE blocks that are written
+ * in each tape record. HIGHDENSITYTREC is the number of
+ * TP_BSIZE blocks that are written in each tape record on
+ * 6250 BPI or higher density tapes.
+ *
+ * TP_NINDIR is the number of indirect pointers in a TS_INODE
+ * or TS_ADDR record. Note that it must be a power of two.
+ */
+#define TP_BSIZE 1024
+#define NTREC 10
+#define HIGHDENSITYTREC 32
+#define TP_NINDIR (TP_BSIZE/2)
+#define LBLSIZE 16
+#define NAMELEN 64
+
+#define OFS_MAGIC (int)60011
+#define NFS_MAGIC (int)60012
+#ifndef FS_UFS2_MAGIC
+#define FS_UFS2_MAGIC (int)0x19540119
+#endif
+#define CHECKSUM (int)84446
+
+union u_spcl {
+ char dummy[TP_BSIZE];
+ struct s_spcl {
+ int32_t c_type; /* record type (see below) */
+ int32_t c_old_date; /* date of this dump */
+ int32_t c_old_ddate; /* date of previous dump */
+ int32_t c_volume; /* dump volume number */
+ int32_t c_old_tapea; /* logical block of this record */
+ uint32_t c_inumber; /* number of inode */
+ int32_t c_magic; /* magic number (see above) */
+ int32_t c_checksum; /* record checksum */
+ union {
+ struct ufs1_dinode __uc_dinode;
+ struct {
+ uint16_t __uc_mode;
+ int16_t __uc_spare1[3];
+ uint64_t __uc_size;
+ int32_t __uc_old_atime;
+ int32_t __uc_atimensec;
+ int32_t __uc_old_mtime;
+ int32_t __uc_mtimensec;
+ int32_t __uc_spare2[2];
+ int32_t __uc_rdev;
+ int32_t __uc_birthtimensec;
+ int64_t __uc_birthtime;
+ int64_t __uc_atime;
+ int64_t __uc_mtime;
+ int32_t __uc_spare4[7];
+ uint32_t __uc_file_flags;
+ int32_t __uc_spare5[2];
+ uint32_t __uc_uid;
+ uint32_t __uc_gid;
+ int32_t __uc_spare6[2];
+ } __uc_ino;
+ } __c_ino;
+ int32_t c_count; /* number of valid c_addr entries */
+ char c_addr[TP_NINDIR]; /* 1 => data; 0 => hole in inode */
+ char c_label[LBLSIZE]; /* dump label */
+ int32_t c_level; /* level of this dump */
+ char c_filesys[NAMELEN]; /* name of dumped file system */
+ char c_dev[NAMELEN]; /* name of dumped device */
+ char c_host[NAMELEN]; /* name of dumped host */
+ int32_t c_flags; /* additional information */
+ int32_t c_old_firstrec; /* first record on volume */
+ int64_t c_date; /* date of this dump */
+ int64_t c_ddate; /* date of previous dump */
+ int64_t c_tapea; /* logical block of this record */
+ int64_t c_firstrec; /* first record on volume */
+ int32_t c_spare[24]; /* reserved for future uses */
+ } s_spcl;
+} u_spcl;
+#define spcl u_spcl.s_spcl
+
+#define c_dinode __c_ino.__uc_dinode
+#define c_mode __c_ino.__uc_ino.__uc_mode
+#define c_spare1 __c_ino.__uc_ino.__uc_spare1
+#define c_size __c_ino.__uc_ino.__uc_size
+#define c_old_atime __c_ino.__uc_ino.__uc_old_atime
+#define c_atime __c_ino.__uc_ino.__uc_atime
+#define c_atimensec __c_ino.__uc_ino.__uc_atimensec
+#define c_mtime __c_ino.__uc_ino.__uc_mtime
+#define c_mtimensec __c_ino.__uc_ino.__uc_mtimensec
+#define c_birthtime __c_ino.__uc_ino.__uc_birthtime
+#define c_birthtimensec __c_ino.__uc_ino.__uc_birthtimensec
+#define c_old_mtime __c_ino.__uc_ino.__uc_old_mtime
+#define c_rdev __c_ino.__uc_ino.__uc_rdev
+#define c_file_flags __c_ino.__uc_ino.__uc_file_flags
+#define c_uid __c_ino.__uc_ino.__uc_uid
+#define c_gid __c_ino.__uc_ino.__uc_gid
+
+/*
+ * special record types
+ */
+#define TS_TAPE 1 /* dump tape header */
+#define TS_INODE 2 /* beginning of file record */
+#define TS_ADDR 4 /* continuation of file record */
+#define TS_BITS 3 /* map of inodes on tape */
+#define TS_CLRI 6 /* map of inodes deleted since last dump */
+#define TS_END 5 /* end of volume marker */
+
+/*
+ * flag values
+ */
+#define DR_NEWHEADER 0x0001 /* new format tape header */
+#define DR_NEWINODEFMT 0x0002 /* new format inodes on tape */
+
+#define DUMPOUTFMT "%-18s %c %s" /* for printf */
+ /* name, level, ctime(date) */
+#define DUMPINFMT "%18s %c %[^\n]\n" /* inverse for scanf */
+
+#endif /* !_PROTOCOLS_DUMPRESTORE_H_ */
diff --git a/include/protocols/routed.h b/include/protocols/routed.h
new file mode 100644
index 0000000..83331a4
--- /dev/null
+++ b/include/protocols/routed.h
@@ -0,0 +1,152 @@
+/* $OpenBSD: routed.h,v 1.3 2003/06/02 19:34:12 millert Exp $ */
+
+/*-
+ * Copyright (c) 1983, 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.
+ * 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.
+ *
+ * @(#)routed.h 8.1 (Berkeley) 6/2/93
+ *
+ */
+
+#ifndef _ROUTED_H_
+#define _ROUTED_H_
+
+/*
+ * Routing Information Protocol
+ *
+ * Derived from Xerox NS Routing Information Protocol
+ * by changing 32-bit net numbers to sockaddr's and
+ * padding stuff to 32-bit boundaries.
+ */
+
+#define RIPv1 1
+#define RIPv2 2
+#ifndef RIPVERSION
+#define RIPVERSION RIPv1
+#endif
+
+#define RIP_PORT 520
+
+#if RIPVERSION == 1
+/* Note that this so called sockaddr has a 2-byte sa_family and no sa_len.
+ * It is not a UNIX sockaddr, but the shape of an address as defined
+ * in RIPv1. It is still defined to allow old versions of programs
+ * such as `gated` to use this file to define RIPv1.
+ */
+struct netinfo {
+ struct sockaddr rip_dst; /* destination net/host */
+ u_int32_t rip_metric; /* cost of route */
+};
+#else
+struct netinfo {
+ u_int16_t n_family;
+#define RIP_AF_INET htons(AF_INET)
+#define RIP_AF_UNSPEC 0
+#define RIP_AF_AUTH 0xffff
+ u_int16_t n_tag; /* optional in RIPv2 */
+ u_int32_t n_dst; /* destination net or host */
+#define RIP_DEFAULT 0
+ u_int32_t n_mask; /* netmask in RIPv2 */
+ u_int32_t n_nhop; /* optional next hop in RIPv2 */
+ u_int32_t n_metric; /* cost of route */
+};
+#endif
+
+/* RIPv2 authentication */
+struct netauth {
+ u_int16_t a_type;
+#define RIP_AUTH_PW htons(2) /* password type */
+ union {
+#define RIP_AUTH_PW_LEN 16
+ int8_t au_pw[RIP_AUTH_PW_LEN];
+ } au;
+};
+
+struct rip {
+ u_int8_t rip_cmd; /* request/response */
+ u_int8_t rip_vers; /* protocol version # */
+ u_int16_t rip_res1; /* pad to 32-bit boundary */
+ union { /* variable length... */
+ struct netinfo ru_nets[1];
+ int8_t ru_tracefile[1];
+ struct netauth ru_auth[1];
+ } ripun;
+#define rip_nets ripun.ru_nets
+#define rip_tracefile ripun.ru_tracefile
+};
+
+/* Packet types.
+ */
+#define RIPCMD_REQUEST 1 /* want info */
+#define RIPCMD_RESPONSE 2 /* responding to request */
+#define RIPCMD_TRACEON 3 /* turn tracing on */
+#define RIPCMD_TRACEOFF 4 /* turn it off */
+
+/* Gated extended RIP to include a "poll" command instead of using
+ * RIPCMD_REQUEST with (RIP_AF_UNSPEC, RIP_DEFAULT). RFC 1058 says
+ * command 5 is used by Sun Microsystems for its own purposes.
+ */
+#define RIPCMD_POLL 5
+
+#define RIPCMD_MAX 6
+
+#ifdef RIPCMDS
+char *ripcmds[RIPCMD_MAX] = {
+ "#0", "REQUEST", "RESPONSE", "TRACEON", "TRACEOFF"
+};
+#endif
+
+#define HOPCNT_INFINITY 16
+#define MAXPACKETSIZE 512 /* max broadcast size */
+#define NETS_LEN ((MAXPACKETSIZE-sizeof(struct rip)) \
+ / sizeof(struct netinfo) +1)
+
+#define INADDR_RIP_GROUP __IPADDR(0xe0000009) /* 224.0.0.9 */
+
+
+/* Timer values used in managing the routing table.
+ *
+ * Complete tables are broadcast every SUPPLY_INTERVAL seconds.
+ * If changes occur between updates, dynamic updates containing only changes
+ * may be sent. When these are sent, a timer is set for a random value
+ * between MIN_WAITTIME and MAX_WAITTIME, and no additional dynamic updates
+ * are sent until the timer expires.
+ *
+ * Every update of a routing entry forces an entry's timer to be reset.
+ * After EXPIRE_TIME without updates, the entry is marked invalid,
+ * but held onto until GARBAGE_TIME so that others may see it, to
+ * "poison" the bad route.
+ */
+#define SUPPLY_INTERVAL 30 /* time to supply tables */
+#define MIN_WAITTIME 2 /* min sec until next flash updates */
+#define MAX_WAITTIME 5 /* max sec until flash update */
+
+#define STALE_TIME 90 /* switch to a new gateway */
+#define EXPIRE_TIME 180 /* time to mark entry invalid */
+#define GARBAGE_TIME 240 /* time to garbage collect */
+
+#endif /* !_ROUTED_H_ */
diff --git a/include/protocols/rwhod.h b/include/protocols/rwhod.h
new file mode 100644
index 0000000..c182e96
--- /dev/null
+++ b/include/protocols/rwhod.h
@@ -0,0 +1,67 @@
+/* $OpenBSD: rwhod.h,v 1.4 2003/06/02 19:34:12 millert Exp $ */
+/* $NetBSD: rwhod.h,v 1.3 1994/10/26 00:56:51 cgd Exp $ */
+
+/*
+ * Copyright (c) 1983 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.
+ *
+ * @(#)rwhod.h 5.6 (Berkeley) 4/3/91
+ */
+
+#ifndef _RWHOD_H_
+#define _RWHOD_H_
+
+/*
+ * rwho protocol packet format.
+ */
+struct outmp {
+ char out_line[8]; /* tty name */
+ char out_name[8]; /* user id */
+ int32_t out_time; /* time on */
+};
+
+struct whod {
+ char wd_vers; /* protocol version # */
+ char wd_type; /* packet type, see below */
+ char wd_pad[2];
+ int32_t wd_sendtime; /* time stamp by sender */
+ int32_t wd_recvtime; /* time stamp applied by receiver */
+ char wd_hostname[32]; /* hosts's name */
+ int32_t wd_loadav[3]; /* load average as in uptime */
+ int32_t wd_boottime; /* time system booted */
+ struct whoent {
+ struct outmp we_utmp; /* active tty info */
+ int32_t we_idle; /* tty idle time */
+ } wd_we[1024 / sizeof (struct whoent)];
+};
+
+#define WHODVERSION 1
+#define WHODTYPE_STATUS 1 /* host status */
+
+#define _PATH_RWHODIR "/var/rwho"
+
+#endif /* !_RWHOD_H_ */
diff --git a/include/protocols/talkd.h b/include/protocols/talkd.h
new file mode 100644
index 0000000..fae2b42
--- /dev/null
+++ b/include/protocols/talkd.h
@@ -0,0 +1,120 @@
+/* $OpenBSD: talkd.h,v 1.5 2015/01/21 02:23:14 guenther Exp $ */
+/* $NetBSD: talkd.h,v 1.5 1995/03/04 07:59:30 cgd Exp $ */
+
+/*
+ * Copyright (c) 1983 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.
+ *
+ * @(#)talkd.h 5.7 (Berkeley) 4/3/91
+ */
+
+#ifndef _TALKD_H_
+#define _TALKD_H_
+
+/*
+ * This describes the protocol used by the talk server and clients.
+ *
+ * The talk server acts a repository of invitations, responding to
+ * requests by clients wishing to rendezvous for the purpose of
+ * holding a conversation. In normal operation, a client, the caller,
+ * initiates a rendezvous by sending a CTL_MSG to the server of
+ * type LOOK_UP. This causes the server to search its invitation
+ * tables to check if an invitation currently exists for the caller
+ * (to speak to the callee specified in the message). If the lookup
+ * fails, the caller then sends an ANNOUNCE message causing the server
+ * to broadcast an announcement on the callee's login ports requesting
+ * contact. When the callee responds, the local server uses the
+ * recorded invitation to respond with the appropriate rendezvous
+ * address and the caller and callee client programs establish a
+ * stream connection through which the conversation takes place.
+ */
+
+struct osockaddr {
+ unsigned short sa_family; /* address family */
+ char sa_data[14]; /* up to 14 bytes of direct address */
+};
+
+/*
+ * Client->server request message format.
+ */
+typedef struct {
+ unsigned char vers; /* protocol version */
+ unsigned char type; /* request type, see below */
+ unsigned char answer; /* not used */
+ unsigned char pad;
+ u_int32_t id_num; /* message id */
+ struct osockaddr addr; /* old (4.3) style */
+ struct osockaddr ctl_addr; /* old (4.3) style */
+ int32_t pid; /* caller's process id */
+#define NAME_SIZE 12
+ char l_name[NAME_SIZE]; /* caller's name */
+ char r_name[NAME_SIZE]; /* callee's name */
+#define TTY_SIZE 16
+ char r_tty[TTY_SIZE]; /* callee's tty name */
+} CTL_MSG;
+
+/*
+ * Server->client response message format.
+ */
+typedef struct {
+ unsigned char vers; /* protocol version */
+ unsigned char type; /* type of request message, see below */
+ unsigned char answer; /* response to request message,
+ see below */
+ unsigned char pad;
+ u_int32_t id_num; /* message id */
+ struct osockaddr addr; /* address for establishing
+ conversation */
+} CTL_RESPONSE;
+
+#define TALK_VERSION 1 /* protocol version */
+
+/* message type values */
+#define LEAVE_INVITE 0 /* leave invitation with server */
+#define LOOK_UP 1 /* check for invitation by callee */
+#define DELETE 2 /* delete invitation by caller */
+#define ANNOUNCE 3 /* announce invitation by caller */
+
+/* answer values */
+#define SUCCESS 0 /* operation completed properly */
+#define NOT_HERE 1 /* callee not logged in */
+#define FAILED 2 /* operation failed for unexplained reason */
+#define MACHINE_UNKNOWN 3 /* caller's machine name unknown */
+#define PERMISSION_DENIED 4 /* callee's tty doesn't permit announce */
+#define UNKNOWN_REQUEST 5 /* request has invalid type value */
+#define BADVERSION 6 /* request has invalid protocol version */
+#define BADADDR 7 /* request has invalid addr value */
+#define BADCTLADDR 8 /* request has invalid ctl_addr value */
+
+/*
+ * Operational parameters.
+ */
+#define MAX_LIFE 60 /* max time daemon saves invitations */
+/* RING_WAIT should be 10's of seconds less than MAX_LIFE */
+#define RING_WAIT 30 /* time to wait before resending invitation */
+
+#endif /* !_TALKD_H_ */
diff --git a/include/protocols/timed.h b/include/protocols/timed.h
new file mode 100644
index 0000000..12531d1
--- /dev/null
+++ b/include/protocols/timed.h
@@ -0,0 +1,101 @@
+/* $OpenBSD: timed.h,v 1.4 2015/01/16 00:27:00 deraadt Exp $ */
+/* $NetBSD: timed.h,v 1.5 1996/04/09 20:40:32 cgd Exp $ */
+
+/*
+ * Copyright (c) 1983 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.
+ *
+ * @(#)timed.h 1.10 (Berkeley) 4/3/91
+ */
+
+#ifndef _TIMED_H_
+#define _TIMED_H_
+
+/*
+ * Time Synchronization Protocol
+ */
+
+#define TSPVERSION 1
+#define ANYADDR NULL
+
+struct tsp {
+ u_int8_t tsp_type;
+ u_int8_t tsp_vers;
+ u_int16_t tsp_seq;
+ union {
+ struct {
+ int32_t tv_sec;
+ int32_t tv_usec;
+ } tspu_time;
+ char tspu_hopcnt;
+ } tsp_u;
+ char tsp_name[256];
+};
+
+#define tsp_time tsp_u.tspu_time
+#define tsp_hopcnt tsp_u.tspu_hopcnt
+
+/*
+ * Command types.
+ */
+#define TSP_ANY 0 /* match any types */
+#define TSP_ADJTIME 1 /* send adjtime */
+#define TSP_ACK 2 /* generic acknowledgement */
+#define TSP_MASTERREQ 3 /* ask for master's name */
+#define TSP_MASTERACK 4 /* acknowledge master request */
+#define TSP_SETTIME 5 /* send network time */
+#define TSP_MASTERUP 6 /* inform slaves that master is up */
+#define TSP_SLAVEUP 7 /* slave is up but not polled */
+#define TSP_ELECTION 8 /* advance candidature for master */
+#define TSP_ACCEPT 9 /* support candidature of master */
+#define TSP_REFUSE 10 /* reject candidature of master */
+#define TSP_CONFLICT 11 /* two or more masters present */
+#define TSP_RESOLVE 12 /* masters' conflict resolution */
+#define TSP_QUIT 13 /* reject candidature if master is up */
+#define TSP_DATE 14 /* reset the time (date command) */
+#define TSP_DATEREQ 15 /* remote request to reset the time */
+#define TSP_DATEACK 16 /* acknowledge time setting */
+#define TSP_TRACEON 17 /* turn tracing on */
+#define TSP_TRACEOFF 18 /* turn tracing off */
+#define TSP_MSITE 19 /* find out master's site */
+#define TSP_MSITEREQ 20 /* remote master's site request */
+#define TSP_TEST 21 /* for testing election algo */
+#define TSP_SETDATE 22 /* New from date command */
+#define TSP_SETDATEREQ 23 /* New remote for above */
+#define TSP_LOOP 24 /* loop detection packet */
+
+#define TSPTYPENUMBER 25
+
+#ifdef TSPTYPES
+char *tsptype[TSPTYPENUMBER] =
+ { "ANY", "ADJTIME", "ACK", "MASTERREQ", "MASTERACK", "SETTIME", "MASTERUP",
+ "SLAVEUP", "ELECTION", "ACCEPT", "REFUSE", "CONFLICT", "RESOLVE", "QUIT",
+ "DATE", "DATEREQ", "DATEACK", "TRACEON", "TRACEOFF", "MSITE", "MSITEREQ",
+ "TEST", "SETDATE", "SETDATEREQ", "LOOP" };
+#endif
+
+#endif /* !_TIMED_H_ */
diff --git a/include/pthread.h b/include/pthread.h
new file mode 100644
index 0000000..cfb1356
--- /dev/null
+++ b/include/pthread.h
@@ -0,0 +1,315 @@
+/* $OpenBSD: pthread.h,v 1.4 2018/03/05 01:15:26 deraadt Exp $ */
+
+/*
+ * Copyright (c) 1993, 1994 by Chris Provenzano, proven@mit.edu
+ * Copyright (c) 1995-1998 by John Birrell <jb@cimlogic.com.au>
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Chris Provenzano.
+ * 4. The name of Chris Provenzano may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY CHRIS PROVENZANO ``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 CHRIS PROVENZANO 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: pthread.h,v 1.13 1999/07/31 08:36:07 rse Exp $
+ */
+#ifndef _PTHREAD_H_
+#define _PTHREAD_H_
+
+/*
+ * Header files.
+ */
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/signal.h>
+#include <limits.h>
+#include <sched.h>
+
+/*
+ * Run-time invariant values:
+ */
+#define PTHREAD_DESTRUCTOR_ITERATIONS 4
+#define PTHREAD_KEYS_MAX 256
+#define PTHREAD_STACK_MIN (1U << _MAX_PAGE_SHIFT)
+#define PTHREAD_THREADS_MAX ULONG_MAX
+
+/*
+ * Flags for threads and thread attributes.
+ */
+#define PTHREAD_DETACHED 0x1
+#define PTHREAD_SCOPE_SYSTEM 0x2
+#define PTHREAD_INHERIT_SCHED 0x4
+#define PTHREAD_NOFLOAT 0x8
+
+#define PTHREAD_CREATE_DETACHED PTHREAD_DETACHED
+#define PTHREAD_CREATE_JOINABLE 0
+#define PTHREAD_SCOPE_PROCESS 0
+#define PTHREAD_EXPLICIT_SCHED 0
+
+/*
+ * Flags for read/write lock attributes
+ */
+#define PTHREAD_PROCESS_PRIVATE 0
+#define PTHREAD_PROCESS_SHARED 1
+
+/*
+ * Flags for cancelling threads
+ */
+#define PTHREAD_CANCEL_ENABLE 0
+#define PTHREAD_CANCEL_DISABLE 1
+#define PTHREAD_CANCEL_DEFERRED 0
+#define PTHREAD_CANCEL_ASYNCHRONOUS 2
+#define PTHREAD_CANCELED ((void *) 1)
+
+/*
+ * Barrier flags
+ */
+#define PTHREAD_BARRIER_SERIAL_THREAD -1
+
+/*
+ * Forward structure definitions.
+ *
+ * These are mostly opaque to the user.
+ */
+struct pthread;
+struct pthread_attr;
+struct pthread_cond;
+struct pthread_cond_attr;
+struct pthread_mutex;
+struct pthread_mutex_attr;
+struct pthread_once;
+struct pthread_rwlock;
+struct pthread_rwlockattr;
+
+/*
+ * Primitive system data type definitions required by P1003.1c.
+ *
+ * Note that P1003.1c specifies that there are no defined comparison
+ * or assignment operators for the types pthread_attr_t, pthread_cond_t,
+ * pthread_condattr_t, pthread_mutex_t, pthread_mutexattr_t.
+ */
+typedef struct pthread *pthread_t;
+typedef struct pthread_attr *pthread_attr_t;
+typedef volatile struct pthread_mutex *pthread_mutex_t;
+typedef struct pthread_mutex_attr *pthread_mutexattr_t;
+typedef struct pthread_cond *pthread_cond_t;
+typedef struct pthread_cond_attr *pthread_condattr_t;
+typedef int pthread_key_t;
+typedef struct pthread_once pthread_once_t;
+typedef struct pthread_rwlock *pthread_rwlock_t;
+typedef struct pthread_rwlockattr *pthread_rwlockattr_t;
+typedef struct pthread_barrier *pthread_barrier_t;
+typedef struct pthread_barrierattr *pthread_barrierattr_t;
+typedef struct pthread_spinlock *pthread_spinlock_t;
+
+/*
+ * Additional type definitions:
+ *
+ * Note that P1003.1c reserves the prefixes pthread_ and PTHREAD_ for
+ * use in header symbols.
+ */
+typedef void *pthread_addr_t;
+typedef void *(*pthread_startroutine_t)(void *);
+
+/*
+ * Once definitions.
+ */
+struct pthread_once {
+ int state;
+ pthread_mutex_t mutex;
+};
+
+/*
+ * Flags for once initialization.
+ */
+#define PTHREAD_NEEDS_INIT 0
+#define PTHREAD_DONE_INIT 1
+
+/*
+ * Static once initialization values.
+ */
+#define PTHREAD_ONCE_INIT { PTHREAD_NEEDS_INIT, PTHREAD_MUTEX_INITIALIZER }
+
+/*
+ * Static initialization values.
+ */
+#define PTHREAD_MUTEX_INITIALIZER NULL
+#define PTHREAD_COND_INITIALIZER NULL
+#define PTHREAD_RWLOCK_INITIALIZER NULL
+
+#define PTHREAD_PRIO_NONE 0
+#define PTHREAD_PRIO_INHERIT 1
+#define PTHREAD_PRIO_PROTECT 2
+
+/*
+ * Mutex types.
+ */
+enum pthread_mutextype {
+ PTHREAD_MUTEX_ERRORCHECK = 1, /* Error checking mutex */
+ PTHREAD_MUTEX_RECURSIVE = 2, /* Recursive mutex */
+ PTHREAD_MUTEX_NORMAL = 3, /* No error checking */
+ PTHREAD_MUTEX_STRICT_NP = 4, /* Strict error checking */
+ PTHREAD_MUTEX_TYPE_MAX
+};
+
+#define PTHREAD_MUTEX_ERRORCHECK PTHREAD_MUTEX_ERRORCHECK
+#define PTHREAD_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE
+#define PTHREAD_MUTEX_NORMAL PTHREAD_MUTEX_NORMAL
+#define PTHREAD_MUTEX_STRICT_NP PTHREAD_MUTEX_STRICT_NP
+#define PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_STRICT_NP
+
+/*
+ * Thread function prototype definitions:
+ */
+__BEGIN_DECLS
+int pthread_atfork(void (*)(void), void (*)(void), void (*)(void));
+int pthread_attr_destroy(pthread_attr_t *);
+int pthread_attr_getstack(const pthread_attr_t *,
+ void **, size_t *);
+int pthread_attr_getstacksize(const pthread_attr_t *, size_t *);
+int pthread_attr_getstackaddr(const pthread_attr_t *, void **);
+int pthread_attr_getguardsize(const pthread_attr_t *, size_t *);
+int pthread_attr_getdetachstate(const pthread_attr_t *, int *);
+int pthread_attr_init(pthread_attr_t *);
+int pthread_attr_setstacksize(pthread_attr_t *, size_t);
+int pthread_attr_setstack(pthread_attr_t *, void *, size_t);
+int pthread_attr_setstackaddr(pthread_attr_t *, void *);
+int pthread_attr_setguardsize(pthread_attr_t *, size_t);
+int pthread_attr_setdetachstate(pthread_attr_t *, int);
+void pthread_cleanup_pop(int);
+void pthread_cleanup_push(void (*) (void *), void *routine_arg);
+int pthread_condattr_destroy(pthread_condattr_t *);
+int pthread_condattr_init(pthread_condattr_t *);
+
+int pthread_cond_broadcast(pthread_cond_t *);
+int pthread_cond_destroy(pthread_cond_t *);
+int pthread_cond_init(pthread_cond_t *,
+ const pthread_condattr_t *);
+int pthread_cond_signal(pthread_cond_t *);
+int pthread_cond_timedwait(pthread_cond_t *,
+ pthread_mutex_t *, const struct timespec *);
+int pthread_cond_wait(pthread_cond_t *, pthread_mutex_t *);
+int pthread_create(pthread_t *, const pthread_attr_t *,
+ void *(*) (void *), void *);
+int pthread_detach(pthread_t);
+int pthread_equal(pthread_t, pthread_t);
+__dead void pthread_exit(void *);
+void *pthread_getspecific(pthread_key_t);
+int pthread_join(pthread_t, void **);
+int pthread_key_create(pthread_key_t *,
+ void (*) (void *));
+int pthread_key_delete(pthread_key_t);
+int pthread_kill(pthread_t, int);
+int pthread_mutexattr_init(pthread_mutexattr_t *);
+int pthread_mutexattr_destroy(pthread_mutexattr_t *);
+int pthread_mutexattr_gettype(pthread_mutexattr_t *, int *);
+int pthread_mutexattr_settype(pthread_mutexattr_t *, int);
+int pthread_mutex_destroy(pthread_mutex_t *);
+int pthread_mutex_init(pthread_mutex_t *,
+ const pthread_mutexattr_t *);
+int pthread_mutex_lock(pthread_mutex_t *);
+int pthread_mutex_timedlock(pthread_mutex_t *,
+ const struct timespec *);
+int pthread_mutex_trylock(pthread_mutex_t *);
+int pthread_mutex_unlock(pthread_mutex_t *);
+int pthread_once(pthread_once_t *, void (*) (void));
+int pthread_rwlock_destroy(pthread_rwlock_t *);
+int pthread_rwlock_init(pthread_rwlock_t *,
+ const pthread_rwlockattr_t *);
+int pthread_rwlock_rdlock(pthread_rwlock_t *);
+int pthread_rwlock_timedrdlock(pthread_rwlock_t *,
+ const struct timespec *);
+int pthread_rwlock_timedwrlock(pthread_rwlock_t *,
+ const struct timespec *);
+int pthread_rwlock_tryrdlock(pthread_rwlock_t *);
+int pthread_rwlock_trywrlock(pthread_rwlock_t *);
+int pthread_rwlock_unlock(pthread_rwlock_t *);
+int pthread_rwlock_wrlock(pthread_rwlock_t *);
+int pthread_rwlockattr_init(pthread_rwlockattr_t *);
+int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *,
+ int *);
+int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int);
+int pthread_rwlockattr_destroy(pthread_rwlockattr_t *);
+pthread_t pthread_self(void);
+int pthread_setspecific(pthread_key_t, const void *);
+
+int pthread_cancel(pthread_t);
+int pthread_setcancelstate(int, int *);
+int pthread_setcanceltype(int, int *);
+void pthread_testcancel(void);
+
+int pthread_getprio(pthread_t);
+int pthread_setprio(pthread_t, int);
+void pthread_yield(void);
+
+int pthread_mutexattr_getprioceiling(pthread_mutexattr_t *,
+ int *);
+int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *,
+ int);
+int pthread_mutex_getprioceiling(pthread_mutex_t *, int *);
+int pthread_mutex_setprioceiling(pthread_mutex_t *, int, int *);
+
+int pthread_mutexattr_getprotocol(pthread_mutexattr_t *, int *);
+int pthread_mutexattr_setprotocol(pthread_mutexattr_t *, int);
+
+int pthread_condattr_getclock(const pthread_condattr_t *,
+ clockid_t *);
+int pthread_condattr_setclock(pthread_condattr_t *, clockid_t);
+
+int pthread_attr_getinheritsched(const pthread_attr_t *, int *);
+int pthread_attr_getschedparam(const pthread_attr_t *,
+ struct sched_param *);
+int pthread_attr_getschedpolicy(const pthread_attr_t *, int *);
+int pthread_attr_getscope(const pthread_attr_t *, int *);
+int pthread_attr_setinheritsched(pthread_attr_t *, int);
+int pthread_attr_setschedparam(pthread_attr_t *,
+ const struct sched_param *);
+int pthread_attr_setschedpolicy(pthread_attr_t *, int);
+int pthread_attr_setscope(pthread_attr_t *, int);
+int pthread_getschedparam(pthread_t pthread, int *,
+ struct sched_param *);
+int pthread_setschedparam(pthread_t, int,
+ const struct sched_param *);
+int pthread_getconcurrency(void);
+int pthread_setconcurrency(int);
+int pthread_barrier_init(pthread_barrier_t *,
+ pthread_barrierattr_t *, unsigned int);
+int pthread_barrier_destroy(pthread_barrier_t *);
+int pthread_barrier_wait(pthread_barrier_t *);
+int pthread_barrierattr_init(pthread_barrierattr_t *);
+int pthread_barrierattr_destroy(pthread_barrierattr_t *);
+int pthread_barrierattr_getpshared(pthread_barrierattr_t *, int *);
+int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int);
+int pthread_spin_init(pthread_spinlock_t *, int);
+int pthread_spin_destroy(pthread_spinlock_t *);
+int pthread_spin_trylock(pthread_spinlock_t *);
+int pthread_spin_lock(pthread_spinlock_t *);
+int pthread_spin_unlock(pthread_spinlock_t *);
+
+#if __POSIX_VISIBLE >= 200112
+int pthread_getcpuclockid(pthread_t, clockid_t *);
+#endif
+__END_DECLS
+
+#endif /* _PTHREAD_H_ */
diff --git a/include/pthread_np.h b/include/pthread_np.h
new file mode 100644
index 0000000..fb7e962
--- /dev/null
+++ b/include/pthread_np.h
@@ -0,0 +1,56 @@
+/* $OpenBSD: pthread_np.h,v 1.3 2019/05/28 10:33:03 jca Exp $ */
+/*
+ * Copyright (c) 1996-98 John Birrell <jb@cimlogic.com.au>.
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by John Birrell.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL 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 _PTHREAD_NP_H_
+#define _PTHREAD_NP_H_
+
+#include <pthread.h>
+
+/*
+ * Non-POSIX type definitions:
+ */
+typedef void (*pthread_switch_routine_t)(pthread_t, pthread_t);
+
+/*
+ * Non-POSIX thread function prototype definitions:
+ */
+__BEGIN_DECLS
+int pthread_mutexattr_getkind_np(pthread_mutexattr_t);
+int pthread_mutexattr_setkind_np(pthread_mutexattr_t *, int);
+void pthread_get_name_np(pthread_t, char *, size_t);
+void pthread_set_name_np(pthread_t, const char *);
+int pthread_stackseg_np(pthread_t, stack_t *);
+int pthread_main_np(void);
+__END_DECLS
+
+#endif
diff --git a/include/pwd.h b/include/pwd.h
new file mode 100644
index 0000000..c1aabba
--- /dev/null
+++ b/include/pwd.h
@@ -0,0 +1,4 @@
+#include_next <pwd.h>
+#define setpassent(n) setpwent()
+const char *user_from_uid(uid_t, int);
+int uid_from_user(const char *, uid_t *);
diff --git a/include/ranlib.h b/include/ranlib.h
new file mode 100644
index 0000000..d56d120
--- /dev/null
+++ b/include/ranlib.h
@@ -0,0 +1,49 @@
+/* $OpenBSD: ranlib.h,v 1.3 2003/06/02 19:34:12 millert Exp $ */
+/* $NetBSD: ranlib.h,v 1.4 1994/10/26 00:56:14 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1990 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.
+ *
+ * @(#)ranlib.h 5.2 (Berkeley) 4/3/91
+ */
+
+#ifndef _RANLIB_H_
+#define _RANLIB_H_
+
+#define RANLIBMAG "__.SYMDEF" /* archive file name */
+#define RANLIBSKEW 3 /* creation time offset */
+
+struct ranlib {
+ union {
+ long ran_strx; /* string table index */
+ char *ran_name; /* in memory symbol name */
+ } ran_un;
+ long ran_off; /* archive file offset */
+};
+
+#endif /* !_RANLIB_H_ */
diff --git a/include/readpassphrase.h b/include/readpassphrase.h
new file mode 100644
index 0000000..cef36f0
--- /dev/null
+++ b/include/readpassphrase.h
@@ -0,0 +1,40 @@
+/* $OpenBSD: readpassphrase.h,v 1.5 2003/06/17 21:56:23 millert Exp $ */
+
+/*
+ * Copyright (c) 2000, 2002 Todd C. Miller <Todd.Miller@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.
+ *
+ * Sponsored in part by the Defense Advanced Research Projects
+ * Agency (DARPA) and Air Force Research Laboratory, Air Force
+ * Materiel Command, USAF, under agreement number F39502-99-1-0512.
+ */
+
+#ifndef _READPASSPHRASE_H_
+#define _READPASSPHRASE_H_
+
+#define RPP_ECHO_OFF 0x00 /* Turn off echo (default). */
+#define RPP_ECHO_ON 0x01 /* Leave echo on. */
+#define RPP_REQUIRE_TTY 0x02 /* Fail if there is no tty. */
+#define RPP_FORCELOWER 0x04 /* Force input to lower case. */
+#define RPP_FORCEUPPER 0x08 /* Force input to upper case. */
+#define RPP_SEVENBIT 0x10 /* Strip the high bit from input. */
+#define RPP_STDIN 0x20 /* Read from stdin, not /dev/tty */
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+char * readpassphrase(const char *, char *, size_t, int);
+__END_DECLS
+
+#endif /* !_READPASSPHRASE_H_ */
diff --git a/include/regex.h b/include/regex.h
new file mode 100644
index 0000000..e24d9ae
--- /dev/null
+++ b/include/regex.h
@@ -0,0 +1,104 @@
+/* $OpenBSD: regex.h,v 1.7 2012/12/05 23:19:57 deraadt Exp $ */
+/* $NetBSD: regex.h,v 1.4.6.1 1996/06/10 18:57:07 explorer Exp $ */
+
+/*-
+ * Copyright (c) 1992 Henry Spencer.
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Henry Spencer of the University of Toronto.
+ *
+ * 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.
+ *
+ * @(#)regex.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _REGEX_H_
+#define _REGEX_H_
+
+#include <sys/types.h>
+
+/* types */
+typedef off_t regoff_t;
+
+typedef struct {
+ int re_magic;
+ size_t re_nsub; /* number of parenthesized subexpressions */
+ const char *re_endp; /* end pointer for REG_PEND */
+ struct re_guts *re_g; /* none of your business :-) */
+} regex_t;
+
+typedef struct {
+ regoff_t rm_so; /* start of match */
+ regoff_t rm_eo; /* end of match */
+} regmatch_t;
+
+/* regcomp() flags */
+#define REG_BASIC 0000
+#define REG_EXTENDED 0001
+#define REG_ICASE 0002
+#define REG_NOSUB 0004
+#define REG_NEWLINE 0010
+#define REG_NOSPEC 0020
+#define REG_PEND 0040
+#define REG_DUMP 0200
+
+/* regerror() flags */
+#define REG_NOMATCH 1
+#define REG_BADPAT 2
+#define REG_ECOLLATE 3
+#define REG_ECTYPE 4
+#define REG_EESCAPE 5
+#define REG_ESUBREG 6
+#define REG_EBRACK 7
+#define REG_EPAREN 8
+#define REG_EBRACE 9
+#define REG_BADBR 10
+#define REG_ERANGE 11
+#define REG_ESPACE 12
+#define REG_BADRPT 13
+#define REG_EMPTY 14
+#define REG_ASSERT 15
+#define REG_INVARG 16
+#define REG_ATOI 255 /* convert name to number (!) */
+#define REG_ITOA 0400 /* convert number to name (!) */
+
+/* regexec() flags */
+#define REG_NOTBOL 00001
+#define REG_NOTEOL 00002
+#define REG_STARTEND 00004
+#define REG_TRACE 00400 /* tracing of execution */
+#define REG_LARGE 01000 /* force large representation */
+#define REG_BACKR 02000 /* force use of backref code */
+
+__BEGIN_DECLS
+int regcomp(regex_t *, const char *, int);
+size_t regerror(int, const regex_t *, char *, size_t);
+int regexec(const regex_t *, const char *, size_t, regmatch_t [], int);
+void regfree(regex_t *);
+__END_DECLS
+
+#endif /* !_REGEX_H_ */
diff --git a/include/resolv.h b/include/resolv.h
new file mode 100644
index 0000000..23f19f9
--- /dev/null
+++ b/include/resolv.h
@@ -0,0 +1,3 @@
+#include_next <resolv.h>
+int b64_ntop(unsigned char const *, size_t, char *, size_t);
+int b64_pton(char const *, unsigned char *, size_t);
diff --git a/include/rmd160.h b/include/rmd160.h
new file mode 100644
index 0000000..5137c59
--- /dev/null
+++ b/include/rmd160.h
@@ -0,0 +1,60 @@
+/* $OpenBSD: rmd160.h,v 1.17 2012/12/05 23:19:57 deraadt Exp $ */
+/*
+ * Copyright (c) 2001 Markus Friedl. 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.
+ */
+#ifndef _RMD160_H
+#define _RMD160_H
+
+#define RMD160_BLOCK_LENGTH 64
+#define RMD160_DIGEST_LENGTH 20
+#define RMD160_DIGEST_STRING_LENGTH (RMD160_DIGEST_LENGTH * 2 + 1)
+
+/* RMD160 context. */
+typedef struct RMD160Context {
+ u_int32_t state[5]; /* state */
+ u_int64_t count; /* number of bits, mod 2^64 */
+ u_int8_t buffer[RMD160_BLOCK_LENGTH]; /* input buffer */
+} RMD160_CTX;
+
+__BEGIN_DECLS
+void RMD160Init(RMD160_CTX *);
+void RMD160Transform(u_int32_t [5], const u_int8_t [RMD160_BLOCK_LENGTH])
+ __attribute__((__bounded__(__minbytes__,1,5)))
+ __attribute__((__bounded__(__minbytes__,2,RMD160_BLOCK_LENGTH)));
+void RMD160Update(RMD160_CTX *, const u_int8_t *, size_t)
+ __attribute__((__bounded__(__string__,2,3)));
+void RMD160Pad(RMD160_CTX *);
+void RMD160Final(u_int8_t [RMD160_DIGEST_LENGTH], RMD160_CTX *)
+ __attribute__((__bounded__(__minbytes__,1,RMD160_DIGEST_LENGTH)));
+char *RMD160End(RMD160_CTX *, char *)
+ __attribute__((__bounded__(__minbytes__,2,RMD160_DIGEST_STRING_LENGTH)));
+char *RMD160File(const char *, char *)
+ __attribute__((__bounded__(__minbytes__,2,RMD160_DIGEST_STRING_LENGTH)));
+char *RMD160FileChunk(const char *, char *, off_t, off_t)
+ __attribute__((__bounded__(__minbytes__,2,RMD160_DIGEST_STRING_LENGTH)));
+char *RMD160Data(const u_int8_t *, size_t, char *)
+ __attribute__((__bounded__(__string__,1,2)))
+ __attribute__((__bounded__(__minbytes__,3,RMD160_DIGEST_STRING_LENGTH)));
+__END_DECLS
+
+#endif /* _RMD160_H */
diff --git a/include/rpc/CVS/Entries b/include/rpc/CVS/Entries
new file mode 100644
index 0000000..da29e02
--- /dev/null
+++ b/include/rpc/CVS/Entries
@@ -0,0 +1,14 @@
+/auth.h/1.8/Sun Sep 13 12:29:03 2015//
+/auth_unix.h/1.5/Wed Sep 1 14:43:34 2010//
+/clnt.h/1.11/Wed Sep 1 14:43:34 2010//
+/pmap_clnt.h/1.7/Wed Sep 1 14:43:34 2010//
+/pmap_prot.h/1.6/Wed Sep 1 14:43:34 2010//
+/pmap_rmt.h/1.5/Wed Sep 1 14:43:34 2010//
+/rpc.h/1.11/Wed Sep 1 14:43:34 2010//
+/rpc_des.h/1.4/Wed Sep 1 14:43:34 2010//
+/rpc_msg.h/1.7/Wed Oct 29 04:34:21 2014//
+/svc.h/1.16/Sat Aug 27 04:28:28 2016//
+/svc_auth.h/1.5/Sun Sep 13 15:36:57 2015//
+/types.h/1.3/Wed Sep 1 14:43:34 2010//
+/xdr.h/1.12/Wed Sep 1 14:43:34 2010//
+D
diff --git a/include/rpc/CVS/Repository b/include/rpc/CVS/Repository
new file mode 100644
index 0000000..f7a5a0b
--- /dev/null
+++ b/include/rpc/CVS/Repository
@@ -0,0 +1 @@
+src/include/rpc
diff --git a/include/rpc/CVS/Root b/include/rpc/CVS/Root
new file mode 100644
index 0000000..3811072
--- /dev/null
+++ b/include/rpc/CVS/Root
@@ -0,0 +1 @@
+/cvs
diff --git a/include/rpc/auth.h b/include/rpc/auth.h
new file mode 100644
index 0000000..1cd94bb
--- /dev/null
+++ b/include/rpc/auth.h
@@ -0,0 +1,184 @@
+/* $OpenBSD: auth.h,v 1.8 2015/09/13 12:29:03 guenther Exp $ */
+/* $NetBSD: auth.h,v 1.7 1995/04/29 05:27:55 cgd Exp $ */
+
+/*
+ * Copyright (c) 2010, Oracle America, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of the "Oracle America, Inc." 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT HOLDER 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: @(#)auth.h 1.17 88/02/08 SMI
+ * @(#)auth.h 2.3 88/08/07 4.0 RPCSRC
+ */
+
+/*
+ * auth.h, Authentication interface.
+ *
+ * The data structures are completely opaque to the client. The client
+ * is required to pass a AUTH * to routines that create rpc
+ * "sessions".
+ */
+
+#ifndef _RPC_AUTH_H
+#define _RPC_AUTH_H
+#include <sys/cdefs.h>
+
+#define MAX_AUTH_BYTES 400
+#define MAXNETNAMELEN 255 /* maximum length of network user's name */
+
+/*
+ * Status returned from authentication check
+ */
+enum auth_stat {
+ AUTH_OK=0,
+ /*
+ * failed at remote end
+ */
+ AUTH_BADCRED=1, /* bogus credentials (seal broken) */
+ AUTH_REJECTEDCRED=2, /* client should begin new session */
+ AUTH_BADVERF=3, /* bogus verifier (seal broken) */
+ AUTH_REJECTEDVERF=4, /* verifier expired or was replayed */
+ AUTH_TOOWEAK=5, /* rejected due to security reasons */
+ /*
+ * failed locally
+ */
+ AUTH_INVALIDRESP=6, /* bogus response verifier */
+ AUTH_FAILED=7 /* some unknown reason */
+};
+
+typedef u_int32_t u_int32; /* 32-bit unsigned integers */
+
+union des_block {
+ struct {
+ u_int32 high;
+ u_int32 low;
+ } key;
+ char c[8];
+};
+typedef union des_block des_block;
+__BEGIN_DECLS
+extern bool_t xdr_des_block(XDR *, des_block *);
+__END_DECLS
+
+/*
+ * Authentication info. Opaque to client.
+ */
+struct opaque_auth {
+ enum_t oa_flavor; /* flavor of auth */
+ caddr_t oa_base; /* address of more auth stuff */
+ unsigned int oa_length; /* not to exceed MAX_AUTH_BYTES */
+};
+
+
+/*
+ * Auth handle, interface to client side authenticators.
+ */
+typedef struct __rpc_auth {
+ struct opaque_auth ah_cred;
+ struct opaque_auth ah_verf;
+ union des_block ah_key;
+ struct auth_ops {
+ void (*ah_nextverf)(struct __rpc_auth *);
+ /* nextverf & serialize */
+ int (*ah_marshal)(struct __rpc_auth *, XDR *);
+ /* validate varifier */
+ int (*ah_validate)(struct __rpc_auth *,
+ struct opaque_auth *);
+ /* refresh credentials */
+ int (*ah_refresh)(struct __rpc_auth *);
+ /* destroy this structure */
+ void (*ah_destroy)(struct __rpc_auth *);
+ } *ah_ops;
+ caddr_t ah_private;
+} AUTH;
+
+
+/*
+ * Authentication ops.
+ * The ops and the auth handle provide the interface to the authenticators.
+ *
+ * AUTH *auth;
+ * XDR *xdrs;
+ * struct opaque_auth verf;
+ */
+#define AUTH_NEXTVERF(auth) \
+ ((*((auth)->ah_ops->ah_nextverf))(auth))
+#define auth_nextverf(auth) \
+ ((*((auth)->ah_ops->ah_nextverf))(auth))
+
+#define AUTH_MARSHALL(auth, xdrs) \
+ ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
+#define auth_marshall(auth, xdrs) \
+ ((*((auth)->ah_ops->ah_marshal))(auth, xdrs))
+
+#define AUTH_VALIDATE(auth, verfp) \
+ ((*((auth)->ah_ops->ah_validate))((auth), verfp))
+#define auth_validate(auth, verfp) \
+ ((*((auth)->ah_ops->ah_validate))((auth), verfp))
+
+#define AUTH_REFRESH(auth) \
+ ((*((auth)->ah_ops->ah_refresh))(auth))
+#define auth_refresh(auth) \
+ ((*((auth)->ah_ops->ah_refresh))(auth))
+
+#define AUTH_DESTROY(auth) \
+ ((*((auth)->ah_ops->ah_destroy))(auth))
+#define auth_destroy(auth) \
+ ((*((auth)->ah_ops->ah_destroy))(auth))
+
+
+extern struct opaque_auth _null_auth;
+
+
+/*
+ * These are the various implementations of client side authenticators.
+ */
+
+/*
+ * Unix style authentication
+ * AUTH *authunix_create(machname, uid, gid, len, aup_gids)
+ * char *machname;
+ * int uid;
+ * int gid;
+ * int len;
+ * int *aup_gids;
+ */
+__BEGIN_DECLS
+struct sockaddr_in;
+extern AUTH *authunix_create(char *, int, int, int, int *);
+extern AUTH *authunix_create_default(void);
+extern AUTH *authnone_create(void);
+extern void set_rpc_maxgrouplist(int);
+__END_DECLS
+
+#define AUTH_NONE 0 /* no authentication */
+#define AUTH_NULL 0 /* backward compatibility */
+#define AUTH_UNIX 1 /* unix style (uid, gids) */
+#define AUTH_SHORT 2 /* short hand unix style */
+#define AUTH_DES 3 /* des style (encrypted timestamps) */
+
+#endif /* !_RPC_AUTH_H */
diff --git a/include/rpc/auth_unix.h b/include/rpc/auth_unix.h
new file mode 100644
index 0000000..1ebf92c
--- /dev/null
+++ b/include/rpc/auth_unix.h
@@ -0,0 +1,84 @@
+/* $OpenBSD: auth_unix.h,v 1.5 2010/09/01 14:43:34 millert Exp $ */
+/* $NetBSD: auth_unix.h,v 1.4 1994/10/26 00:56:56 cgd Exp $ */
+
+/*
+ * Copyright (c) 2010, Oracle America, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of the "Oracle America, Inc." 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT HOLDER 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: @(#)auth_unix.h 1.8 88/02/08 SMI
+ * @(#)auth_unix.h 2.2 88/07/29 4.0 RPCSRC
+ */
+
+/*
+ * auth_unix.h, Protocol for UNIX style authentication parameters for RPC
+ */
+
+/*
+ * The system is very weak. The client uses no encryption for it
+ * credentials and only sends null verifiers. The server sends backs
+ * null verifiers or optionally a verifier that suggests a new short hand
+ * for the credentials.
+ */
+
+#ifndef _RPC_AUTH_UNIX_H
+#define _RPC_AUTH_UNIX_H
+#include <sys/cdefs.h>
+
+/* The machine name is part of a credential; it may not exceed 255 bytes */
+#define MAX_MACHINE_NAME 255
+
+/* gids compose part of a credential; there may not be more than 16 of them */
+#define NGRPS 16
+
+/*
+ * Unix style credentials.
+ */
+struct authunix_parms {
+ unsigned long aup_time;
+ char *aup_machname;
+ int aup_uid;
+ int aup_gid;
+ unsigned int aup_len;
+ int *aup_gids;
+};
+
+__BEGIN_DECLS
+extern bool_t xdr_authunix_parms(XDR *, struct authunix_parms *);
+__END_DECLS
+
+/*
+ * If a response verifier has flavor AUTH_SHORT,
+ * then the body of the response verifier encapsulates the following structure;
+ * again it is serialized in the obvious fashion.
+ */
+struct short_hand_verf {
+ struct opaque_auth new_cred;
+};
+
+#endif /* !_RPC_AUTH_UNIX_H */
diff --git a/include/rpc/clnt.h b/include/rpc/clnt.h
new file mode 100644
index 0000000..e5a62e3
--- /dev/null
+++ b/include/rpc/clnt.h
@@ -0,0 +1,361 @@
+/* $OpenBSD: clnt.h,v 1.11 2010/09/01 14:43:34 millert Exp $ */
+/* $NetBSD: clnt.h,v 1.6 1995/04/29 05:27:58 cgd Exp $ */
+
+/*
+ * Copyright (c) 2010, Oracle America, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of the "Oracle America, Inc." 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT HOLDER 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: @(#)clnt.h 1.31 88/02/08 SMI
+ * @(#)clnt.h 2.1 88/07/29 4.0 RPCSRC
+ */
+
+/*
+ * clnt.h - Client side remote procedure call interface.
+ */
+
+#ifndef _RPC_CLNT_H_
+#define _RPC_CLNT_H_
+#include <sys/cdefs.h>
+
+/*
+ * Rpc calls return an enum clnt_stat. This should be looked at more,
+ * since each implementation is required to live with this (implementation
+ * independent) list of errors.
+ */
+enum clnt_stat {
+ RPC_SUCCESS=0, /* call succeeded */
+ /*
+ * local errors
+ */
+ RPC_CANTENCODEARGS=1, /* can't encode arguments */
+ RPC_CANTDECODERES=2, /* can't decode results */
+ RPC_CANTSEND=3, /* failure in sending call */
+ RPC_CANTRECV=4, /* failure in receiving result */
+ RPC_TIMEDOUT=5, /* call timed out */
+ /*
+ * remote errors
+ */
+ RPC_VERSMISMATCH=6, /* rpc versions not compatible */
+ RPC_AUTHERROR=7, /* authentication error */
+ RPC_PROGUNAVAIL=8, /* program not available */
+ RPC_PROGVERSMISMATCH=9, /* program version mismatched */
+ RPC_PROCUNAVAIL=10, /* procedure unavailable */
+ RPC_CANTDECODEARGS=11, /* decode arguments error */
+ RPC_SYSTEMERROR=12, /* generic "other problem" */
+
+ /*
+ * callrpc & clnt_create errors
+ */
+ RPC_UNKNOWNHOST=13, /* unknown host name */
+ RPC_UNKNOWNPROTO=17, /* unknown protocol */
+
+ /*
+ * _ create errors
+ */
+ RPC_PMAPFAILURE=14, /* the pmapper failed in its call */
+ RPC_PROGNOTREGISTERED=15, /* remote program is not registered */
+ /*
+ * unspecified error
+ */
+ RPC_FAILED=16
+};
+
+
+/*
+ * Error info.
+ */
+struct rpc_err {
+ enum clnt_stat re_status;
+ union {
+ int RE_errno; /* related system error */
+ enum auth_stat RE_why; /* why the auth error occurred */
+ struct {
+ u_int32_t low; /* lowest verion supported */
+ u_int32_t high; /* highest verion supported */
+ } RE_vers;
+ struct { /* maybe meaningful if RPC_FAILED */
+ int32_t s1;
+ int32_t s2;
+ } RE_lb; /* life boot & debugging only */
+ } ru;
+#define re_errno ru.RE_errno
+#define re_why ru.RE_why
+#define re_vers ru.RE_vers
+#define re_lb ru.RE_lb
+};
+
+
+/*
+ * Client rpc handle.
+ * Created by individual implementations, see e.g. rpc_udp.c.
+ * Client is responsible for initializing auth, see e.g. auth_none.c.
+ */
+typedef struct __rpc_client {
+ AUTH *cl_auth; /* authenticator */
+ struct clnt_ops {
+ /* call remote procedure */
+ enum clnt_stat (*cl_call)(struct __rpc_client *,
+ unsigned long, xdrproc_t, caddr_t,
+ xdrproc_t, caddr_t, struct timeval);
+ /* abort a call */
+ void (*cl_abort)(struct __rpc_client *);
+ /* get specific error code */
+ void (*cl_geterr)(struct __rpc_client *,
+ struct rpc_err *);
+ /* frees results */
+ bool_t (*cl_freeres)(struct __rpc_client *,
+ xdrproc_t, caddr_t);
+ /* destroy this structure */
+ void (*cl_destroy)(struct __rpc_client *);
+ /* the ioctl() of rpc */
+ bool_t (*cl_control)(struct __rpc_client *,
+ unsigned int, void *);
+ } *cl_ops;
+ caddr_t cl_private; /* private stuff */
+} CLIENT;
+
+
+/*
+ * client side rpc interface ops
+ *
+ * Parameter types are:
+ *
+ */
+
+/*
+ * enum clnt_stat
+ * CLNT_CALL(rh, proc, xargs, argsp, xres, resp, timeout)
+ * CLIENT *rh;
+ * unsigned long proc;
+ * xdrproc_t xargs;
+ * caddr_t argsp;
+ * xdrproc_t xres;
+ * caddr_t resp;
+ * struct timeval timeout;
+ */
+#define CLNT_CALL(rh, proc, xargs, argsp, xres, resp, secs) \
+ ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, (caddr_t)argsp, \
+ xres, (caddr_t)resp, secs))
+#define clnt_call(rh, proc, xargs, argsp, xres, resp, secs) \
+ ((*(rh)->cl_ops->cl_call)(rh, proc, xargs, (caddr_t)argsp, \
+ xres, (caddr_t)resp, secs))
+
+/*
+ * void
+ * CLNT_ABORT(rh);
+ * CLIENT *rh;
+ */
+#define CLNT_ABORT(rh) ((*(rh)->cl_ops->cl_abort)(rh))
+#define clnt_abort(rh) ((*(rh)->cl_ops->cl_abort)(rh))
+
+/*
+ * struct rpc_err
+ * CLNT_GETERR(rh);
+ * CLIENT *rh;
+ */
+#define CLNT_GETERR(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
+#define clnt_geterr(rh,errp) ((*(rh)->cl_ops->cl_geterr)(rh, errp))
+
+
+/*
+ * bool_t
+ * CLNT_FREERES(rh, xres, resp);
+ * CLIENT *rh;
+ * xdrproc_t xres;
+ * caddr_t resp;
+ */
+#define CLNT_FREERES(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
+#define clnt_freeres(rh,xres,resp) ((*(rh)->cl_ops->cl_freeres)(rh,xres,resp))
+
+/*
+ * bool_t
+ * CLNT_CONTROL(cl, request, info)
+ * CLIENT *cl;
+ * unsigned int request;
+ * char *info;
+ */
+#define CLNT_CONTROL(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
+#define clnt_control(cl,rq,in) ((*(cl)->cl_ops->cl_control)(cl,rq,in))
+
+/*
+ * control operations that apply to both udp and tcp transports
+ */
+#define CLSET_TIMEOUT 1 /* set timeout (timeval) */
+#define CLGET_TIMEOUT 2 /* get timeout (timeval) */
+#define CLGET_SERVER_ADDR 3 /* get server's address (sockaddr) */
+/*
+ * udp only control operations
+ */
+#define CLSET_RETRY_TIMEOUT 4 /* set retry timeout (timeval) */
+#define CLGET_RETRY_TIMEOUT 5 /* get retry timeout (timeval) */
+
+/*
+ * void
+ * CLNT_DESTROY(rh);
+ * CLIENT *rh;
+ */
+#define CLNT_DESTROY(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
+#define clnt_destroy(rh) ((*(rh)->cl_ops->cl_destroy)(rh))
+
+
+/*
+ * RPCTEST is a test program which is accessable on every rpc
+ * transport/port. It is used for testing, performance evaluation,
+ * and network administration.
+ */
+
+#define RPCTEST_PROGRAM ((unsigned long)1)
+#define RPCTEST_VERSION ((unsigned long)1)
+#define RPCTEST_NULL_PROC ((unsigned long)2)
+#define RPCTEST_NULL_BATCH_PROC ((unsigned long)3)
+
+/*
+ * By convention, procedure 0 takes null arguments and returns them
+ */
+
+#define NULLPROC ((unsigned int)0)
+
+/*
+ * Below are the client handle creation routines for the various
+ * implementations of client side rpc. They can return NULL if a
+ * creation failure occurs.
+ */
+
+/*
+ * Memory based rpc (for speed check and testing)
+ * CLIENT *
+ * clntraw_create(prog, vers)
+ * unsigned long prog;
+ * unsigned long vers;
+ */
+__BEGIN_DECLS
+extern CLIENT *clntraw_create(unsigned long, unsigned long);
+__END_DECLS
+
+
+/*
+ * Generic client creation routine. Supported protocols are "udp" and "tcp"
+ * CLIENT *
+ * clnt_create(host, prog, vers, prot);
+ * char *host; -- hostname
+ * unsigned long prog; -- program number
+ * unsigned long vers; -- version number
+ * char *prot; -- protocol
+ */
+__BEGIN_DECLS
+extern CLIENT *clnt_create(char *, unsigned long, unsigned long, char *);
+__END_DECLS
+
+
+/*
+ * TCP based rpc
+ * CLIENT *
+ * clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz)
+ * struct sockaddr_in *raddr;
+ * unsigned long prog;
+ * unsigned long version;
+ * int *sockp;
+ * unsigned int sendsz;
+ * unsigned int recvsz;
+ */
+__BEGIN_DECLS
+extern CLIENT *clnttcp_create(struct sockaddr_in *, unsigned long,
+ unsigned long, int *, unsigned int, unsigned int);
+__END_DECLS
+
+
+/*
+ * UDP based rpc.
+ * CLIENT *
+ * clntudp_create(raddr, program, version, wait, sockp)
+ * struct sockaddr_in *raddr;
+ * unsigned long program;
+ * unsigned long version;
+ * struct timeval wait;
+ * int *sockp;
+ *
+ * Same as above, but you specify max packet sizes.
+ * CLIENT *
+ * clntudp_bufcreate(raddr, program, version, wait, sockp, sendsz, recvsz)
+ * struct sockaddr_in *raddr;
+ * unsigned long program;
+ * unsigned long version;
+ * struct timeval wait;
+ * int *sockp;
+ * unsigned int sendsz;
+ * unsigned int recvsz;
+ */
+__BEGIN_DECLS
+extern CLIENT *clntudp_create(struct sockaddr_in *, unsigned long,
+ unsigned long, struct timeval, int *);
+extern CLIENT *clntudp_bufcreate(struct sockaddr_in *, unsigned long,
+ unsigned long, struct timeval, int *, unsigned int, unsigned int);
+__END_DECLS
+
+
+/*
+ * Print why creation failed
+ */
+__BEGIN_DECLS
+extern void clnt_pcreateerror(char *); /* stderr */
+extern char *clnt_spcreateerror(char *); /* string */
+__END_DECLS
+
+/*
+ * Like clnt_perror(), but is more verbose in its output
+ */
+__BEGIN_DECLS
+extern void clnt_perrno(enum clnt_stat); /* stderr */
+extern char *clnt_sperrno(enum clnt_stat); /* string */
+__END_DECLS
+
+/*
+ * Print an English error message, given the client error code
+ */
+__BEGIN_DECLS
+extern void clnt_perror(CLIENT *, char *); /* stderr */
+extern char *clnt_sperror(CLIENT *, char *); /* string */
+__END_DECLS
+
+
+/*
+ * If a creation fails, the following allows the user to figure out why.
+ */
+struct rpc_createerr {
+ enum clnt_stat cf_stat;
+ struct rpc_err cf_error; /* useful when cf_stat == RPC_PMAPFAILURE */
+};
+
+extern struct rpc_createerr rpc_createerr;
+
+
+#define UDPMSGSIZE 8800 /* rpc imposed limit on udp msg size */
+#define RPCSMALLMSGSIZE 400 /* a more reasonable packet size */
+
+#endif /* !_RPC_CLNT_H */
diff --git a/include/rpc/pmap_clnt.h b/include/rpc/pmap_clnt.h
new file mode 100644
index 0000000..06aa27f
--- /dev/null
+++ b/include/rpc/pmap_clnt.h
@@ -0,0 +1,85 @@
+/* $OpenBSD: pmap_clnt.h,v 1.7 2010/09/01 14:43:34 millert Exp $ */
+/* $NetBSD: pmap_clnt.h,v 1.5 1994/12/04 01:12:42 cgd Exp $ */
+
+/*
+ * Copyright (c) 2010, Oracle America, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of the "Oracle America, Inc." 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT HOLDER 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: @(#)pmap_clnt.h 1.11 88/02/08 SMI
+ * @(#)pmap_clnt.h 2.1 88/07/29 4.0 RPCSRC
+ */
+
+/*
+ * pmap_clnt.h
+ * Supplies C routines to get to portmap services.
+ */
+
+/*
+ * Usage:
+ * success = pmap_set(program, version, protocol, port);
+ * success = pmap_unset(program, version);
+ * port = pmap_getport(address, program, version, protocol);
+ * head = pmap_getmaps(address);
+ * clnt_stat = pmap_rmtcall(address, program, version, procedure,
+ * xdrargs, argsp, xdrres, resp, tout, port_ptr)
+ * (works for udp only.)
+ * clnt_stat = clnt_broadcast(program, version, procedure,
+ * xdrargs, argsp, xdrres, resp, eachresult)
+ * (like pmap_rmtcall, except the call is broadcasted to all
+ * locally connected nets. For each valid response received,
+ * the procedure eachresult is called. Its form is:
+ * done = eachresult(resp, raddr)
+ * bool_t done;
+ * caddr_t resp;
+ * struct sockaddr_in raddr;
+ * where resp points to the results of the call and raddr is the
+ * address if the responder to the broadcast.
+ */
+
+#ifndef _RPC_PMAPCLNT_H
+#define _RPC_PMAPCLNT_H
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+extern bool_t pmap_set(unsigned long, unsigned long, unsigned int,
+ int);
+extern bool_t pmap_unset(unsigned long, unsigned long);
+extern struct pmaplist *pmap_getmaps(struct sockaddr_in *);
+extern enum clnt_stat pmap_rmtcall(struct sockaddr_in *, unsigned long,
+ unsigned long, unsigned long, xdrproc_t, caddr_t,
+ xdrproc_t, caddr_t, struct timeval,
+ unsigned long *);
+extern enum clnt_stat clnt_broadcast(unsigned long, unsigned long,
+ unsigned long, xdrproc_t, char *, xdrproc_t, char *,
+ bool_t (*)(caddr_t, struct sockaddr_in *));
+extern unsigned short pmap_getport(struct sockaddr_in *, unsigned long,
+ unsigned long, unsigned int);
+__END_DECLS
+
+#endif /* !_RPC_PMAPCLNT_H */
diff --git a/include/rpc/pmap_prot.h b/include/rpc/pmap_prot.h
new file mode 100644
index 0000000..58e4fa7
--- /dev/null
+++ b/include/rpc/pmap_prot.h
@@ -0,0 +1,106 @@
+/* $OpenBSD: pmap_prot.h,v 1.6 2010/09/01 14:43:34 millert Exp $ */
+/* $NetBSD: pmap_prot.h,v 1.4 1994/10/26 00:57:00 cgd Exp $ */
+
+/*
+ * Copyright (c) 2010, Oracle America, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of the "Oracle America, Inc." 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT HOLDER 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: @(#)pmap_prot.h 1.14 88/02/08 SMI
+ * @(#)pmap_prot.h 2.1 88/07/29 4.0 RPCSRC
+ */
+
+/*
+ * pmap_prot.h
+ * Protocol for the local binder service, or pmap.
+ *
+ * The following procedures are supported by the protocol:
+ *
+ * PMAPPROC_NULL() returns ()
+ * takes nothing, returns nothing
+ *
+ * PMAPPROC_SET(struct pmap) returns (bool_t)
+ * TRUE is success, FALSE is failure. Registers the tuple
+ * [prog, vers, prot, port].
+ *
+ * PMAPPROC_UNSET(struct pmap) returns (bool_t)
+ * TRUE is success, FALSE is failure. Un-registers pair
+ * [prog, vers]. prot and port are ignored.
+ *
+ * PMAPPROC_GETPORT(struct pmap) returns (unsigned long).
+ * 0 is failure. Otherwise returns the port number where the pair
+ * [prog, vers] is registered. It may lie!
+ *
+ * PMAPPROC_DUMP() RETURNS (struct pmaplist *)
+ *
+ * PMAPPROC_CALLIT(unsigned int, unsigned int, unsigned int, string<>)
+ * RETURNS (port, string<>);
+ * usage: encapsulatedresults = PMAPPROC_CALLIT(prog, vers, proc, encapsulatedargs);
+ * Calls the procedure on the local machine. If it is not registered,
+ * this procedure is quite; ie it does not return error information!!!
+ * This procedure only is supported on rpc/udp and calls via
+ * rpc/udp. This routine only passes null authentication parameters.
+ * This file has no interface to xdr routines for PMAPPROC_CALLIT.
+ *
+ * The service supports remote procedure calls on udp/ip or tcp/ip socket 111.
+ */
+
+#ifndef _RPC_PMAPPROT_H
+#define _RPC_PMAPPROT_H
+#include <sys/cdefs.h>
+
+#define PMAPPORT ((unsigned short)111)
+#define PMAPPROG ((unsigned long)100000)
+#define PMAPVERS ((unsigned long)2)
+#define PMAPVERS_PROTO ((unsigned long)2)
+#define PMAPVERS_ORIG ((unsigned long)1)
+#define PMAPPROC_NULL ((unsigned long)0)
+#define PMAPPROC_SET ((unsigned long)1)
+#define PMAPPROC_UNSET ((unsigned long)2)
+#define PMAPPROC_GETPORT ((unsigned long)3)
+#define PMAPPROC_DUMP ((unsigned long)4)
+#define PMAPPROC_CALLIT ((unsigned long)5)
+
+struct pmap {
+ unsigned long pm_prog;
+ unsigned long pm_vers;
+ unsigned long pm_prot;
+ unsigned long pm_port;
+};
+
+struct pmaplist {
+ struct pmap pml_map;
+ struct pmaplist *pml_next;
+};
+
+__BEGIN_DECLS
+extern bool_t xdr_pmap(XDR *, struct pmap *);
+extern bool_t xdr_pmaplist(XDR *, struct pmaplist **);
+__END_DECLS
+
+#endif /* !_RPC_PMAPPROT_H */
diff --git a/include/rpc/pmap_rmt.h b/include/rpc/pmap_rmt.h
new file mode 100644
index 0000000..5d65136
--- /dev/null
+++ b/include/rpc/pmap_rmt.h
@@ -0,0 +1,65 @@
+/* $OpenBSD: pmap_rmt.h,v 1.5 2010/09/01 14:43:34 millert Exp $ */
+/* $NetBSD: pmap_rmt.h,v 1.4 1994/10/26 00:57:01 cgd Exp $ */
+
+/*
+ * Copyright (c) 2010, Oracle America, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of the "Oracle America, Inc." 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT HOLDER 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: @(#)pmap_rmt.h 1.2 88/02/08 SMI
+ * @(#)pmap_rmt.h 2.1 88/07/29 4.0 RPCSRC
+ */
+
+/*
+ * Structures and XDR routines for parameters to and replies from
+ * the portmapper remote-call-service.
+ */
+
+#ifndef _RPC_PMAPRMT_H
+#define _RPC_PMAPRMT_H
+#include <sys/cdefs.h>
+
+struct rmtcallargs {
+ unsigned long prog, vers, proc, arglen;
+ caddr_t args_ptr;
+ xdrproc_t xdr_args;
+};
+
+struct rmtcallres {
+ unsigned long *port_ptr;
+ unsigned long resultslen;
+ caddr_t results_ptr;
+ xdrproc_t xdr_results;
+};
+
+__BEGIN_DECLS
+extern bool_t xdr_rmtcall_args(XDR *, struct rmtcallargs *);
+extern bool_t xdr_rmtcallres(XDR *, struct rmtcallres *);
+__END_DECLS
+
+#endif /* !_RPC_PMAPRMT_H */
diff --git a/include/rpc/rpc.h b/include/rpc/rpc.h
new file mode 100644
index 0000000..be9a3dc
--- /dev/null
+++ b/include/rpc/rpc.h
@@ -0,0 +1,108 @@
+/* $OpenBSD: rpc.h,v 1.11 2010/09/01 14:43:34 millert Exp $ */
+/* $NetBSD: rpc.h,v 1.5 1994/12/04 01:15:30 cgd Exp $ */
+
+/*
+ * Copyright (c) 2010, Oracle America, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of the "Oracle America, Inc." 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT HOLDER 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: @(#)rpc.h 1.9 88/02/08 SMI
+ * @(#)rpc.h 2.4 89/07/11 4.0 RPCSRC
+ */
+
+/*
+ * rpc.h, Just includes the billions of rpc header files necessary to
+ * do remote procedure calling.
+ */
+#ifndef _RPC_RPC_H
+#define _RPC_RPC_H
+
+#include <rpc/types.h> /* some typedefs */
+#include <netinet/in.h>
+
+/* external data representation interfaces */
+#include <rpc/xdr.h> /* generic (de)serializer */
+
+/* Client side only authentication */
+#include <rpc/auth.h> /* generic authenticator (client side) */
+
+/* Client side (mostly) remote procedure call */
+#include <rpc/clnt.h> /* generic rpc stuff */
+
+/* Client side (mostly) pmap functions */
+#include <rpc/pmap_clnt.h> /* generic pmap stuff */
+
+/* semi-private protocol headers */
+#include <rpc/rpc_msg.h> /* protocol for rpc messages */
+#include <rpc/auth_unix.h> /* protocol for unix style cred */
+/*
+ * Uncomment-out the next line if you are building the rpc library with
+ * DES Authentication (see the README file in the secure_rpc/ directory).
+ */
+#ifdef notdef
+#include <rpc/auth_des.h> /* protocol for des style cred */
+#endif
+
+/* Server side only remote procedure callee */
+#include <rpc/svc.h> /* service manager and multiplexer */
+#include <rpc/svc_auth.h> /* service side authenticator */
+
+/*
+ * COMMENT OUT THE NEXT INCLUDE (or add to the #ifndef) IF RUNNING ON
+ * A VERSION OF UNIX THAT USES SUN'S NFS SOURCE. These systems will
+ * already have the structures defined by <rpc/netdb.h> included in <netdb.h>.
+ */
+/* routines for parsing /etc/rpc */
+
+struct rpcent {
+ char *r_name; /* name of server for this rpc program */
+ char **r_aliases; /* alias list */
+ int r_number; /* rpc program number */
+};
+
+__BEGIN_DECLS
+extern struct rpcent *getrpcbyname(char *);
+extern struct rpcent *getrpcbynumber(int);
+extern struct rpcent *getrpcent(void);
+extern void setrpcent(int);
+extern void endrpcent(void);
+
+extern int get_myaddress(struct sockaddr_in *);
+extern int registerrpc(int, int, int, char *(*)(char [UDPMSGSIZE]),
+ xdrproc_t, xdrproc_t);
+extern int callrpc(char *, int, int, int, xdrproc_t, char *,
+ xdrproc_t , char *);
+extern int getrpcport(char *, int, int, int);
+
+extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *);
+
+extern int _rpc_dtablesize(void);
+
+__END_DECLS
+
+#endif /* !_RPC_RPC_H */
diff --git a/include/rpc/rpc_des.h b/include/rpc/rpc_des.h
new file mode 100644
index 0000000..92f5a85
--- /dev/null
+++ b/include/rpc/rpc_des.h
@@ -0,0 +1,135 @@
+/* $OpenBSD: rpc_des.h,v 1.4 2010/09/01 14:43:34 millert Exp $ */
+
+/* crypto/des/rpc_des.h */
+/* Copyright (C) 1995-1997 Eric Young (eay@mincom.oz.au)
+ * All rights reserved.
+ *
+ * This package is an SSL implementation written
+ * by Eric Young (eay@mincom.oz.au).
+ * The implementation was written so as to conform with Netscapes SSL.
+ *
+ * This library is free for commercial and non-commercial use as long as
+ * the following conditions are aheared to. The following conditions
+ * apply to all code found in this distribution, be it the RC4, RSA,
+ * lhash, DES, etc., code; not just the SSL code. The SSL documentation
+ * included with this distribution is covered by the same copyright terms
+ * except that the holder is Tim Hudson (tjh@mincom.oz.au).
+ *
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.
+ * If this package is used in a product, Eric Young should be given attribution
+ * as the author of the parts of the library used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ *
+ * 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 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * "This product includes cryptographic software written by
+ * Eric Young (eay@mincom.oz.au)"
+ * The word 'cryptographic' can be left out if the rouines from the library
+ * being used are not cryptographic related :-).
+ * 4. If you include any Windows specific code (or a derivative thereof) from
+ * the apps directory (application code) you must include an acknowledgement:
+ * "This product includes software written by Tim Hudson (tjh@mincom.oz.au)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``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.
+ *
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed. i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+
+/* @(#)des.h 2.2 88/08/10 4.0 RPCSRC; from 2.7 88/02/08 SMI */
+/*
+ * Copyright (c) 2010, Oracle America, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of the "Oracle America, Inc." 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT HOLDER 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.
+ */
+
+/*
+ * Generic DES driver interface
+ * Keep this file hardware independent!
+ */
+
+#define DES_MAXLEN 65536 /* maximum # of bytes to encrypt */
+#define DES_QUICKLEN 16 /* maximum # of bytes to encrypt quickly */
+
+#ifdef HEADER_DES_H
+#undef ENCRYPT
+#undef DECRYPT
+#endif
+
+enum desdir { ENCRYPT, DECRYPT };
+enum desmode { CBC, ECB };
+
+/*
+ * parameters to ioctl call
+ */
+struct desparams {
+ unsigned char des_key[8]; /* key (with low bit parity) */
+ enum desdir des_dir; /* direction */
+ enum desmode des_mode; /* mode */
+ unsigned char des_ivec[8]; /* input vector */
+ unsigned int des_len; /* number of bytes to crypt */
+ union {
+ unsigned char UDES_data[DES_QUICKLEN];
+ unsigned char *UDES_buf;
+ } UDES;
+# define des_data UDES.UDES_data /* direct data here if quick */
+# define des_buf UDES.UDES_buf /* otherwise, pointer to data */
+};
+
+/*
+ * Encrypt an arbitrary sized buffer
+ */
+#define DESIOCBLOCK _IOWR(d, 6, struct desparams)
+
+/*
+ * Encrypt of small amount of data, quickly
+ */
+#define DESIOCQUICK _IOWR(d, 7, struct desparams)
+
diff --git a/include/rpc/rpc_msg.h b/include/rpc/rpc_msg.h
new file mode 100644
index 0000000..1e40dbe
--- /dev/null
+++ b/include/rpc/rpc_msg.h
@@ -0,0 +1,200 @@
+/* $OpenBSD: rpc_msg.h,v 1.7 2014/10/29 04:34:21 guenther Exp $ */
+/* $NetBSD: rpc_msg.h,v 1.5 1995/04/29 05:28:00 cgd Exp $ */
+
+/*
+ * Copyright (c) 2010, Oracle America, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of the "Oracle America, Inc." 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT HOLDER 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: @(#)rpc_msg.h 1.7 86/07/16 SMI
+ * @(#)rpc_msg.h 2.1 88/07/29 4.0 RPCSRC
+ */
+
+/*
+ * rpc_msg.h
+ * rpc message definition
+ */
+
+#ifndef _RPC_RPCMSG_H
+#define _RPC_RPCMSG_H
+
+#define RPC_MSG_VERSION ((unsigned long) 2)
+#define RPC_SERVICE_PORT ((unsigned short) 2048)
+
+/*
+ * Bottom up definition of an rpc message.
+ * NOTE: call and reply use the same overall struct but
+ * different parts of unions within it.
+ */
+
+enum msg_type {
+ CALL=0,
+ REPLY=1
+};
+
+enum reply_stat {
+ MSG_ACCEPTED=0,
+ MSG_DENIED=1
+};
+
+enum accept_stat {
+ SUCCESS=0,
+ PROG_UNAVAIL=1,
+ PROG_MISMATCH=2,
+ PROC_UNAVAIL=3,
+ GARBAGE_ARGS=4,
+ SYSTEM_ERR=5
+};
+
+enum reject_stat {
+ RPC_MISMATCH=0,
+ AUTH_ERROR=1
+};
+
+/*
+ * Reply part of an rpc exchange
+ */
+
+/*
+ * Reply to an rpc request that was accepted by the server.
+ * Note: there could be an error even though the request was
+ * accepted.
+ */
+struct accepted_reply {
+ struct opaque_auth ar_verf;
+ enum accept_stat ar_stat;
+ union {
+ struct {
+ u_int32_t low;
+ u_int32_t high;
+ } AR_versions;
+ struct {
+ caddr_t where;
+ xdrproc_t proc;
+ } AR_results;
+ /* and many other null cases */
+ } ru;
+#define ar_results ru.AR_results
+#define ar_vers ru.AR_versions
+};
+
+/*
+ * Reply to an rpc request that was rejected by the server.
+ */
+struct rejected_reply {
+ enum reject_stat rj_stat;
+ union {
+ struct {
+ u_int32_t low;
+ u_int32_t high;
+ } RJ_versions;
+ enum auth_stat RJ_why; /* why authentication did not work */
+ } ru;
+#define rj_vers ru.RJ_versions
+#define rj_why ru.RJ_why
+};
+
+/*
+ * Body of a reply to an rpc request.
+ */
+struct reply_body {
+ enum reply_stat rp_stat;
+ union {
+ struct accepted_reply RP_ar;
+ struct rejected_reply RP_dr;
+ } ru;
+#define rp_acpt ru.RP_ar
+#define rp_rjct ru.RP_dr
+};
+
+/*
+ * Body of an rpc request call.
+ */
+struct call_body {
+ u_int32_t cb_rpcvers; /* must be equal to two */
+ u_int32_t cb_prog;
+ u_int32_t cb_vers;
+ u_int32_t cb_proc;
+ struct opaque_auth cb_cred;
+ struct opaque_auth cb_verf; /* protocol specific - provided by client */
+};
+
+/*
+ * The rpc message
+ */
+struct rpc_msg {
+ u_int32_t rm_xid;
+ enum msg_type rm_direction;
+ union {
+ struct call_body RM_cmb;
+ struct reply_body RM_rmb;
+ } ru;
+#define rm_call ru.RM_cmb
+#define rm_reply ru.RM_rmb
+};
+#define acpted_rply ru.RM_rmb.ru.RP_ar
+#define rjcted_rply ru.RM_rmb.ru.RP_dr
+
+__BEGIN_DECLS
+/*
+ * XDR routine to handle a rpc message.
+ * xdr_callmsg(xdrs, cmsg)
+ * XDR *xdrs;
+ * struct rpc_msg *cmsg;
+ */
+extern bool_t xdr_callmsg(XDR *, struct rpc_msg *);
+
+/*
+ * XDR routine to pre-serialize the static part of a rpc message.
+ * xdr_callhdr(xdrs, cmsg)
+ * XDR *xdrs;
+ * struct rpc_msg *cmsg;
+ */
+extern bool_t xdr_callhdr(XDR *, struct rpc_msg *);
+
+/*
+ * XDR routine to handle a rpc reply.
+ * xdr_replymsg(xdrs, rmsg)
+ * XDR *xdrs;
+ * struct rpc_msg *rmsg;
+ */
+extern bool_t xdr_replymsg(XDR *, struct rpc_msg *);
+
+extern bool_t xdr_accepted_reply(XDR *, struct accepted_reply *);
+extern bool_t xdr_rejected_reply(XDR *, struct rejected_reply *);
+
+/*
+ * Fills in the error part of a reply message.
+ * _seterr_reply(msg, error)
+ * struct rpc_msg *msg;
+ * struct rpc_err *error;
+ */
+extern void _seterr_reply(struct rpc_msg *, struct rpc_err *);
+__END_DECLS
+
+#endif /* !_RPC_RPCMSG_H */
diff --git a/include/rpc/svc.h b/include/rpc/svc.h
new file mode 100644
index 0000000..7402420
--- /dev/null
+++ b/include/rpc/svc.h
@@ -0,0 +1,326 @@
+/* $OpenBSD: svc.h,v 1.16 2016/08/27 04:28:28 guenther Exp $ */
+/* $NetBSD: svc.h,v 1.9 1995/04/29 05:28:01 cgd Exp $ */
+
+/*
+ * Copyright (c) 2010, Oracle America, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of the "Oracle America, Inc." 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT HOLDER 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: @(#)svc.h 1.20 88/02/08 SMI
+ * @(#)svc.h 2.2 88/07/29 4.0 RPCSRC
+ */
+
+/*
+ * svc.h, Server-side remote procedure call interface.
+ */
+
+#ifndef _RPC_SVC_H
+#define _RPC_SVC_H
+#include <sys/cdefs.h>
+#include <poll.h>
+
+/*
+ * This interface must manage two items concerning remote procedure calling:
+ *
+ * 1) An arbitrary number of transport connections upon which rpc requests
+ * are received. The two most notable transports are TCP and UDP; they are
+ * created and registered by routines in svc_tcp.c and svc_udp.c, respectively;
+ * they in turn call xprt_register and xprt_unregister.
+ *
+ * 2) An arbitrary number of locally registered services. Services are
+ * described by the following four data: program number, version number,
+ * "service dispatch" function, a transport handle, and a boolean that
+ * indicates whether or not the exported program should be registered with a
+ * local binder service; if true the program's number and version and the
+ * port number from the transport handle are registered with the binder.
+ * These data are registered with the rpc svc system via svc_register.
+ *
+ * A service's dispatch function is called whenever an rpc request comes in
+ * on a transport. The request's program and version numbers must match
+ * those of the registered service. The dispatch function is passed two
+ * parameters, struct svc_req * and SVCXPRT *, defined below.
+ */
+
+enum xprt_stat {
+ XPRT_DIED,
+ XPRT_MOREREQS,
+ XPRT_IDLE
+};
+
+/*
+ * Server side transport handle
+ */
+typedef struct __rpc_svcxprt {
+ int xp_sock;
+ unsigned short xp_port; /* associated port number */
+ struct xp_ops {
+ /* receive incoming requests */
+ bool_t (*xp_recv)(struct __rpc_svcxprt *,
+ struct rpc_msg *);
+ /* get transport status */
+ enum xprt_stat (*xp_stat)(struct __rpc_svcxprt *);
+ /* get arguments */
+ bool_t (*xp_getargs)(struct __rpc_svcxprt *, xdrproc_t,
+ caddr_t);
+ /* send reply */
+ bool_t (*xp_reply)(struct __rpc_svcxprt *, struct rpc_msg *);
+ /* free mem allocated for args */
+ bool_t (*xp_freeargs)(struct __rpc_svcxprt *, xdrproc_t,
+ caddr_t);
+ /* destroy this struct */
+ void (*xp_destroy)(struct __rpc_svcxprt *);
+ } *xp_ops;
+ socklen_t xp_addrlen; /* length of remote address */
+ struct sockaddr_in xp_raddr; /* remote address */
+ struct opaque_auth xp_verf; /* raw response verifier */
+ caddr_t xp_p1; /* private */
+ caddr_t xp_p2; /* private */
+} SVCXPRT;
+
+/*
+ * Approved way of getting address of caller
+ */
+#define svc_getcaller(x) (&(x)->xp_raddr)
+
+/*
+ * Operations defined on an SVCXPRT handle
+ *
+ * SVCXPRT *xprt;
+ * struct rpc_msg *msg;
+ * xdrproc_t xargs;
+ * caddr_t argsp;
+ */
+#define SVC_RECV(xprt, msg) \
+ (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
+#define svc_recv(xprt, msg) \
+ (*(xprt)->xp_ops->xp_recv)((xprt), (msg))
+
+#define SVC_STAT(xprt) \
+ (*(xprt)->xp_ops->xp_stat)(xprt)
+#define svc_stat(xprt) \
+ (*(xprt)->xp_ops->xp_stat)(xprt)
+
+#define SVC_GETARGS(xprt, xargs, argsp) \
+ (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
+#define svc_getargs(xprt, xargs, argsp) \
+ (*(xprt)->xp_ops->xp_getargs)((xprt), (xargs), (argsp))
+
+#define SVC_REPLY(xprt, msg) \
+ (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
+#define svc_reply(xprt, msg) \
+ (*(xprt)->xp_ops->xp_reply) ((xprt), (msg))
+
+#define SVC_FREEARGS(xprt, xargs, argsp) \
+ (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
+#define svc_freeargs(xprt, xargs, argsp) \
+ (*(xprt)->xp_ops->xp_freeargs)((xprt), (xargs), (argsp))
+
+#define SVC_DESTROY(xprt) \
+ (*(xprt)->xp_ops->xp_destroy)(xprt)
+#define svc_destroy(xprt) \
+ (*(xprt)->xp_ops->xp_destroy)(xprt)
+
+
+/*
+ * Service request
+ */
+struct svc_req {
+ u_int32_t rq_prog; /* service program number */
+ u_int32_t rq_vers; /* service protocol version */
+ u_int32_t rq_proc; /* the desired procedure */
+ struct opaque_auth rq_cred; /* raw creds from the wire */
+ caddr_t rq_clntcred; /* read only cooked cred */
+ SVCXPRT *rq_xprt; /* associated transport */
+};
+
+
+/*
+ * Service registration
+ *
+ * svc_register(xprt, prog, vers, dispatch, protocol)
+ * SVCXPRT *xprt;
+ * unsigned long prog;
+ * unsigned long vers;
+ * void (*dispatch)();
+ * int protocol; like TCP or UDP, zero means do not register
+ */
+__BEGIN_DECLS
+extern bool_t svc_register(SVCXPRT *, unsigned long, unsigned long,
+ void (*)(struct svc_req *, SVCXPRT *), int);
+__END_DECLS
+
+/*
+ * Service un-registration
+ *
+ * svc_unregister(prog, vers)
+ * unsigned long prog;
+ * unsigned long vers;
+ */
+__BEGIN_DECLS
+extern void svc_unregister(unsigned long, unsigned long);
+__END_DECLS
+
+/*
+ * Transport registration.
+ *
+ * xprt_register(xprt)
+ * SVCXPRT *xprt;
+ */
+__BEGIN_DECLS
+extern void xprt_register(SVCXPRT *);
+__END_DECLS
+
+/*
+ * Transport un-register
+ *
+ * xprt_unregister(xprt)
+ * SVCXPRT *xprt;
+ */
+__BEGIN_DECLS
+extern void xprt_unregister(SVCXPRT *);
+__END_DECLS
+
+
+
+
+/*
+ * When the service routine is called, it must first check to see if it
+ * knows about the procedure; if not, it should call svcerr_noproc
+ * and return. If so, it should deserialize its arguments via
+ * SVC_GETARGS (defined above). If the deserialization does not work,
+ * svcerr_decode should be called followed by a return. Successful
+ * decoding of the arguments should be followed the execution of the
+ * procedure's code and a call to svc_sendreply.
+ *
+ * Also, if the service refuses to execute the procedure due to too-
+ * weak authentication parameters, svcerr_weakauth should be called.
+ * Note: do not confuse access-control failure with weak authentication!
+ *
+ * NB: In pure implementations of rpc, the caller always waits for a reply
+ * msg. This message is sent when svc_sendreply is called.
+ * Therefore pure service implementations should always call
+ * svc_sendreply even if the function logically returns void; use
+ * xdr.h - xdr_void for the xdr routine. HOWEVER, tcp based rpc allows
+ * for the abuse of pure rpc via batched calling or pipelining. In the
+ * case of a batched call, svc_sendreply should NOT be called since
+ * this would send a return message, which is what batching tries to avoid.
+ * It is the service/protocol writer's responsibility to know which calls are
+ * batched and which are not. Warning: responding to batch calls may
+ * deadlock the caller and server processes!
+ */
+
+__BEGIN_DECLS
+extern bool_t svc_sendreply(SVCXPRT *, xdrproc_t, char *);
+extern void svcerr_decode(SVCXPRT *);
+extern void svcerr_weakauth(SVCXPRT *);
+extern void svcerr_noproc(SVCXPRT *);
+extern void svcerr_progvers(SVCXPRT *, unsigned long, unsigned long);
+extern void svcerr_auth(SVCXPRT *, enum auth_stat);
+extern void svcerr_noprog(SVCXPRT *);
+extern void svcerr_systemerr(SVCXPRT *);
+__END_DECLS
+
+/*
+ * Lowest level dispatching -OR- who owns this process anyway.
+ * Somebody has to wait for incoming requests and then call the correct
+ * service routine. The routine svc_run does infinite waiting; i.e.,
+ * svc_run never returns.
+ * Since another (co-existent) package may wish to selectively wait for
+ * incoming calls or other events outside of the rpc architecture, the
+ * routine svc_getreq is provided. It must be passed readfds, the
+ * "in-place" results of a select system call (see select, section 2).
+ */
+
+/*
+ * Global keeper of rpc service descriptors in use
+ * dynamic; must be inspected before each call to select
+ */
+#include <sys/select.h> /* for fd_set */
+extern fd_set svc_fdset;
+#define svc_fds svc_fdset.fds_bits[0] /* compatibility */
+extern struct pollfd *svc_pollfd;
+extern int svc_max_pollfd;
+extern int svc_maxfd; /* non-standard */
+
+/*
+ * a small program implemented by the svc_rpc implementation itself;
+ * also see clnt.h for protocol numbers.
+ */
+extern void rpctest_service(); /* XXX relic? */
+
+__BEGIN_DECLS
+extern void svc_getreq(int);
+extern void svc_getreq_common(int);
+extern void svc_getreq_poll(struct pollfd *, const int);
+extern void svc_getreqset(fd_set *);
+extern void svc_getreqset2(fd_set *, int);
+extern void svc_run(void);
+__END_DECLS
+
+/*
+ * Socket to use on svcxxx_create call to get default socket
+ */
+#define RPC_ANYSOCK -1
+
+/*
+ * These are the existing service side transport implementations
+ */
+
+/*
+ * Memory based rpc for testing and timing.
+ */
+__BEGIN_DECLS
+extern SVCXPRT *svcraw_create(void);
+__END_DECLS
+
+
+/*
+ * Udp based rpc.
+ */
+__BEGIN_DECLS
+extern SVCXPRT *svcudp_create(int);
+extern SVCXPRT *svcudp_bufcreate(int, unsigned int, unsigned int);
+extern int svcudp_enablecache(SVCXPRT *, u_long);
+__END_DECLS
+
+
+/*
+ * Tcp based rpc.
+ */
+__BEGIN_DECLS
+extern SVCXPRT *svctcp_create(int, unsigned int, unsigned int);
+__END_DECLS
+
+/*
+ * Fd based rpc.
+ */
+__BEGIN_DECLS
+extern SVCXPRT *svcfd_create(int, unsigned int, unsigned int);
+__END_DECLS
+
+#endif /* !_RPC_SVC_H */
diff --git a/include/rpc/svc_auth.h b/include/rpc/svc_auth.h
new file mode 100644
index 0000000..cc6b56d
--- /dev/null
+++ b/include/rpc/svc_auth.h
@@ -0,0 +1 @@
+/* this file intentionally left blank */
diff --git a/include/rpc/types.h b/include/rpc/types.h
new file mode 100644
index 0000000..b904831
--- /dev/null
+++ b/include/rpc/types.h
@@ -0,0 +1,66 @@
+/* $OpenBSD: types.h,v 1.3 2010/09/01 14:43:34 millert Exp $ */
+/* $NetBSD: types.h,v 1.8 1995/04/29 05:28:05 cgd Exp $ */
+
+/*
+ * Copyright (c) 2010, Oracle America, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of the "Oracle America, Inc." 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT HOLDER 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: @(#)types.h 1.18 87/07/24 SMI
+ * @(#)types.h 2.3 88/08/15 4.0 RPCSRC
+ */
+
+/*
+ * Rpc additions to <sys/types.h>
+ */
+#ifndef _RPC_TYPES_H
+#define _RPC_TYPES_H
+
+#define bool_t int32_t
+#define enum_t int32_t
+#define __dontcare__ -1
+
+#ifndef FALSE
+# define FALSE (0)
+#endif
+#ifndef TRUE
+# define TRUE (1)
+#endif
+#ifndef NULL
+# define NULL 0
+#endif
+
+#define mem_alloc(bsize) malloc(bsize)
+#define mem_free(ptr, bsize) free(ptr)
+
+#ifndef makedev /* ie, we haven't already included it */
+#include <sys/types.h>
+#endif
+#include <sys/time.h>
+
+#endif /* !_RPC_TYPES_H */
diff --git a/include/rpc/xdr.h b/include/rpc/xdr.h
new file mode 100644
index 0000000..1f0532a
--- /dev/null
+++ b/include/rpc/xdr.h
@@ -0,0 +1,316 @@
+/* $OpenBSD: xdr.h,v 1.12 2010/09/01 14:43:34 millert Exp $ */
+/* $NetBSD: xdr.h,v 1.7 1995/04/29 05:28:06 cgd Exp $ */
+
+/*
+ * Copyright (c) 2010, Oracle America, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * 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.
+ * * Neither the name of the "Oracle America, Inc." 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT HOLDER 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: @(#)xdr.h 1.19 87/04/22 SMI
+ * @(#)xdr.h 2.2 88/07/29 4.0 RPCSRC
+ */
+
+/*
+ * xdr.h, External Data Representation Serialization Routines.
+ */
+
+#ifndef _RPC_XDR_H
+#define _RPC_XDR_H
+#include <sys/cdefs.h>
+
+/*
+ * XDR provides a conventional way for converting between C data
+ * types and an external bit-string representation. Library supplied
+ * routines provide for the conversion on built-in C data types. These
+ * routines and utility routines defined here are used to help implement
+ * a type encode/decode routine for each user-defined type.
+ *
+ * Each data type provides a single procedure which takes two arguments:
+ *
+ * bool_t
+ * xdrproc(xdrs, argresp)
+ * XDR *xdrs;
+ * <type> *argresp;
+ *
+ * xdrs is an instance of a XDR handle, to which or from which the data
+ * type is to be converted. argresp is a pointer to the structure to be
+ * converted. The XDR handle contains an operation field which indicates
+ * which of the operations (ENCODE, DECODE * or FREE) is to be performed.
+ *
+ * XDR_DECODE may allocate space if the pointer argresp is null. This
+ * data can be freed with the XDR_FREE operation.
+ *
+ * We write only one procedure per data type to make it easy
+ * to keep the encode and decode procedures for a data type consistent.
+ * In many cases the same code performs all operations on a user defined type,
+ * because all the hard work is done in the component type routines.
+ * decode as a series of calls on the nested data types.
+ */
+
+/*
+ * Xdr operations. XDR_ENCODE causes the type to be encoded into the
+ * stream. XDR_DECODE causes the type to be extracted from the stream.
+ * XDR_FREE can be used to release the space allocated by an XDR_DECODE
+ * request.
+ */
+enum xdr_op {
+ XDR_ENCODE=0,
+ XDR_DECODE=1,
+ XDR_FREE=2
+};
+
+/*
+ * This is the number of bytes per unit of external data.
+ */
+#define BYTES_PER_XDR_UNIT (4)
+#define RNDUP(x) ((((x) + BYTES_PER_XDR_UNIT - 1) / BYTES_PER_XDR_UNIT) \
+ * BYTES_PER_XDR_UNIT)
+
+/*
+ * The XDR handle.
+ * Contains operation which is being applied to the stream,
+ * an operations vector for the paticular implementation (e.g. see xdr_mem.c),
+ * and two private fields for the use of the particular impelementation.
+ */
+typedef struct __rpc_xdr {
+ enum xdr_op x_op; /* operation; fast additional param */
+ struct xdr_ops {
+ /* get a long from underlying stream */
+ bool_t (*x_getlong)(struct __rpc_xdr *, long *);
+ /* put a long to " */
+ bool_t (*x_putlong)(struct __rpc_xdr *, long *);
+ /* get some bytes from " */
+ bool_t (*x_getbytes)(struct __rpc_xdr *, caddr_t,
+ unsigned int);
+ /* put some bytes to " */
+ bool_t (*x_putbytes)(struct __rpc_xdr *, caddr_t,
+ unsigned int);
+ /* returns bytes off from beginning */
+ unsigned int (*x_getpostn)(struct __rpc_xdr *);
+ /* lets you reposition the stream */
+ bool_t (*x_setpostn)(struct __rpc_xdr *, unsigned int);
+ /* buf quick ptr to buffered data */
+ int32_t *(*x_inline)(struct __rpc_xdr *, unsigned int);
+ /* free privates of this xdr_stream */
+ void (*x_destroy)(struct __rpc_xdr *);
+ bool_t (*x_control)(struct __rpc_xdr *, int, void *);
+ } *x_ops;
+ caddr_t x_public; /* users' data */
+ caddr_t x_private; /* pointer to private data */
+ caddr_t x_base; /* private used for position info */
+ unsigned int x_handy; /* extra private word */
+} XDR;
+
+/*
+ * A xdrproc_t exists for each data type which is to be encoded or decoded.
+ *
+ * The second argument to the xdrproc_t is a pointer to an opaque pointer.
+ * The opaque pointer generally points to a structure of the data type
+ * to be decoded. If this pointer is 0, then the type routines should
+ * allocate dynamic storage of the appropriate size and return it.
+ *
+ * XXX can't actually prototype it, because some take three args!!!
+ */
+typedef bool_t (*xdrproc_t)(/* XDR *, void *, unsigned int */);
+
+/*
+ * Operations defined on a XDR handle
+ *
+ * XDR *xdrs;
+ * long *longp;
+ * caddr_t addr;
+ * unsigned int len;
+ * unsigned int pos;
+ */
+#define XDR_GETLONG(xdrs, longp) \
+ (*(xdrs)->x_ops->x_getlong)(xdrs, longp)
+#define xdr_getlong(xdrs, longp) \
+ (*(xdrs)->x_ops->x_getlong)(xdrs, longp)
+
+#define XDR_PUTLONG(xdrs, longp) \
+ (*(xdrs)->x_ops->x_putlong)(xdrs, longp)
+#define xdr_putlong(xdrs, longp) \
+ (*(xdrs)->x_ops->x_putlong)(xdrs, longp)
+
+#define XDR_GETBYTES(xdrs, addr, len) \
+ (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
+#define xdr_getbytes(xdrs, addr, len) \
+ (*(xdrs)->x_ops->x_getbytes)(xdrs, addr, len)
+
+#define XDR_PUTBYTES(xdrs, addr, len) \
+ (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
+#define xdr_putbytes(xdrs, addr, len) \
+ (*(xdrs)->x_ops->x_putbytes)(xdrs, addr, len)
+
+#define XDR_GETPOS(xdrs) \
+ (*(xdrs)->x_ops->x_getpostn)(xdrs)
+#define xdr_getpos(xdrs) \
+ (*(xdrs)->x_ops->x_getpostn)(xdrs)
+
+#define XDR_SETPOS(xdrs, pos) \
+ (*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
+#define xdr_setpos(xdrs, pos) \
+ (*(xdrs)->x_ops->x_setpostn)(xdrs, pos)
+
+#define XDR_INLINE(xdrs, len) \
+ (*(xdrs)->x_ops->x_inline)(xdrs, len)
+#define xdr_inline(xdrs, len) \
+ (*(xdrs)->x_ops->x_inline)(xdrs, len)
+
+#define XDR_DESTROY(xdrs) \
+ if ((xdrs)->x_ops->x_destroy) \
+ (*(xdrs)->x_ops->x_destroy)(xdrs)
+#define xdr_destroy(xdrs) \
+ if ((xdrs)->x_ops->x_destroy) \
+ (*(xdrs)->x_ops->x_destroy)(xdrs)
+
+/*
+ * Support struct for discriminated unions.
+ * You create an array of xdrdiscrim structures, terminated with
+ * a entry with a null procedure pointer. The xdr_union routine gets
+ * the discriminant value and then searches the array of structures
+ * for a matching value. If a match is found the associated xdr routine
+ * is called to handle that part of the union. If there is
+ * no match, then a default routine may be called.
+ * If there is no match and no default routine it is an error.
+ */
+#define NULL_xdrproc_t ((xdrproc_t)0)
+struct xdr_discrim {
+ int value;
+ xdrproc_t proc;
+};
+
+/*
+ * In-line routines for fast encode/decode of primitive data types.
+ * Caveat emptor: these use single memory cycles to get the
+ * data from the underlying buffer, and will fail to operate
+ * properly if the data is not aligned. The standard way to use these
+ * is to say:
+ * if ((buf = XDR_INLINE(xdrs, count)) == NULL)
+ * return (FALSE);
+ * <<< macro calls >>>
+ * where ``count'' is the number of bytes of data occupied
+ * by the primitive data types.
+ *
+ * N.B. and frozen for all time: each data type here uses 4 bytes
+ * of external representation.
+ */
+#define IXDR_GET_LONG(buf) ((long)ntohl((unsigned long)*(buf)++))
+#define IXDR_PUT_LONG(buf, v) (*(buf)++ = (long)htonl((unsigned long)v))
+
+#define IXDR_GET_BOOL(buf) ((bool_t)IXDR_GET_LONG(buf))
+#define IXDR_GET_ENUM(buf, t) ((t)IXDR_GET_LONG(buf))
+#define IXDR_GET_U_LONG(buf) ((unsigned long)IXDR_GET_LONG(buf))
+#define IXDR_GET_SHORT(buf) ((short)IXDR_GET_LONG(buf))
+#define IXDR_GET_U_SHORT(buf) ((unsigned short)IXDR_GET_LONG(buf))
+
+#define IXDR_PUT_BOOL(buf, v) IXDR_PUT_LONG((buf), ((long)(v)))
+#define IXDR_PUT_ENUM(buf, v) IXDR_PUT_LONG((buf), ((long)(v)))
+#define IXDR_PUT_U_LONG(buf, v) IXDR_PUT_LONG((buf), ((long)(v)))
+#define IXDR_PUT_SHORT(buf, v) IXDR_PUT_LONG((buf), ((long)(v)))
+#define IXDR_PUT_U_SHORT(buf, v) IXDR_PUT_LONG((buf), ((long)(v)))
+
+/*
+ * These are the "generic" xdr routines.
+ */
+__BEGIN_DECLS
+extern bool_t xdr_void(void);
+extern bool_t xdr_int(XDR *, int *);
+extern bool_t xdr_u_int(XDR *, unsigned int *);
+extern bool_t xdr_long(XDR *, long *);
+extern bool_t xdr_u_long(XDR *, unsigned long *);
+extern bool_t xdr_short(XDR *, short *);
+extern bool_t xdr_u_short(XDR *, unsigned short *);
+extern bool_t xdr_int16_t(XDR *, int16_t *);
+extern bool_t xdr_u_int16_t(XDR *, u_int16_t *);
+extern bool_t xdr_int32_t(XDR *, int32_t *);
+extern bool_t xdr_u_int32_t(XDR *, u_int32_t *);
+extern bool_t xdr_int64_t(XDR *, int64_t *);
+extern bool_t xdr_u_int64_t(XDR *, u_int64_t *);
+extern bool_t xdr_bool(XDR *, bool_t *);
+extern bool_t xdr_enum(XDR *, enum_t *);
+extern bool_t xdr_array(XDR *, char **, unsigned int *, unsigned int,
+ unsigned int, xdrproc_t);
+extern bool_t xdr_bytes(XDR *, char **, unsigned int *, unsigned int);
+extern bool_t xdr_opaque(XDR *, caddr_t, unsigned int);
+extern bool_t xdr_string(XDR *, char **, unsigned int);
+extern bool_t xdr_union(XDR *, enum_t *, char *, struct xdr_discrim *,
+ xdrproc_t);
+extern bool_t xdr_char(XDR *, char *);
+extern bool_t xdr_u_char(XDR *, unsigned char *);
+extern bool_t xdr_vector(XDR *, char *, unsigned int, unsigned int,
+ xdrproc_t);
+extern bool_t xdr_float(XDR *, float *);
+extern bool_t xdr_double(XDR *, double *);
+extern bool_t xdr_reference(XDR *, caddr_t *, unsigned int, xdrproc_t);
+extern bool_t xdr_pointer(XDR *, caddr_t *, unsigned int, xdrproc_t);
+extern bool_t xdr_wrapstring(XDR *, char **);
+extern void xdr_free(xdrproc_t, char *);
+__END_DECLS
+
+/*
+ * Common opaque bytes objects used by many rpc protocols;
+ * declared here due to commonality.
+ */
+#define MAX_NETOBJ_SZ 1024
+struct netobj {
+ unsigned int n_len;
+ char *n_bytes;
+};
+typedef struct netobj netobj;
+extern bool_t xdr_netobj(XDR *, struct netobj *);
+
+/*
+ * These are the public routines for the various implementations of
+ * xdr streams.
+ */
+__BEGIN_DECLS
+/* XDR using memory buffers */
+extern void xdrmem_create(XDR *, char *, unsigned int, enum xdr_op);
+
+#ifdef _STDIO_H_
+/* XDR using stdio library */
+extern void xdrstdio_create(XDR *, FILE *, enum xdr_op);
+#endif
+
+/* XDR pseudo records for tcp */
+extern void xdrrec_create(XDR *, unsigned int, unsigned int, char *,
+ int (*)(caddr_t, caddr_t, int),
+ int (*)(caddr_t, caddr_t, int));
+
+/* make end of xdr record */
+extern bool_t xdrrec_endofrecord(XDR *, int);
+
+/* move to beginning of next record */
+extern bool_t xdrrec_skiprecord(XDR *);
+
+/* true if no more input */
+extern bool_t xdrrec_eof(XDR *);
+__END_DECLS
+
+#endif /* !_RPC_XDR_H */
diff --git a/include/rpcsvc/CVS/Entries b/include/rpcsvc/CVS/Entries
new file mode 100644
index 0000000..9e2706a
--- /dev/null
+++ b/include/rpcsvc/CVS/Entries
@@ -0,0 +1,3 @@
+/yp_prot.h/1.10/Mon May 30 02:53:29 2016//
+/ypclnt.h/1.10/Mon May 30 02:53:29 2016//
+D
diff --git a/include/rpcsvc/CVS/Repository b/include/rpcsvc/CVS/Repository
new file mode 100644
index 0000000..f8b2ea3
--- /dev/null
+++ b/include/rpcsvc/CVS/Repository
@@ -0,0 +1 @@
+src/include/rpcsvc
diff --git a/include/rpcsvc/CVS/Root b/include/rpcsvc/CVS/Root
new file mode 100644
index 0000000..3811072
--- /dev/null
+++ b/include/rpcsvc/CVS/Root
@@ -0,0 +1 @@
+/cvs
diff --git a/include/rpcsvc/yp_prot.h b/include/rpcsvc/yp_prot.h
new file mode 100644
index 0000000..243cf52
--- /dev/null
+++ b/include/rpcsvc/yp_prot.h
@@ -0,0 +1,316 @@
+/* $OpenBSD: yp_prot.h,v 1.10 2016/05/30 02:53:29 guenther Exp $ */
+/* $NetBSD: yp_prot.h,v 1.6 1995/07/14 21:10:58 christos Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993 Theo de Raadt <deraadt@openbsd.org>
+ * 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.
+ */
+
+#ifndef _RPCSVC_YP_PROT_H_
+#define _RPCSVC_YP_PROT_H_
+
+/*
+ * YPSERV PROTOCOL:
+ *
+ * ypserv supports the following procedures:
+ *
+ * YPPROC_NULL takes (void), returns (void).
+ * called to check if server is alive.
+ * YPPROC_DOMAIN takes (char *), returns (bool_t).
+ * true if ypserv serves the named domain.
+ * YPPROC_DOMAIN_NOACK takes (char *), returns (bool_t).
+ * true if ypserv serves the named domain.
+ * used for broadcasts, does not ack if ypserv
+ * doesn't handle named domain.
+ * YPPROC_MATCH takes (struct ypreq_key), returns (struct ypresp_val)
+ * does a lookup.
+ * YPPROC_FIRST takes (struct ypreq_nokey) returns (ypresp_key_val).
+ * gets the first key/datum from the map.
+ * YPPROC_NEXT takes (struct ypreq_key) returns (ypresp_key_val).
+ * gets the next key/datum from the map.
+ * YPPROC_XFR takes (struct ypreq_xfr), returns (void).
+ * tells ypserv to check if there is a new version of
+ * the map.
+ * YPPROC_CLEAR takes (void), returns (void).
+ * tells ypserv to flush it's file cache, so that
+ * newly transferred files will get read.
+ * YPPROC_ALL takes (struct ypreq_nokey), returns (bool_t and
+ * struct ypresp_key_val).
+ * returns an array of data, with the bool_t being
+ * false on the last datum. read the source, it's
+ * convoluted.
+ * YPPROC_MASTER takes (struct ypreq_nokey), returns (ypresp_master).
+ * YPPROC_ORDER takes (struct ypreq_nokey), returns (ypresp_order).
+ * YPPROC_MAPLIST takes (char *), returns (struct ypmaplist *).
+ */
+
+#ifndef BOOL_DEFINED
+typedef unsigned int bool;
+#define BOOL_DEFINED
+#endif
+
+
+/* Program and version symbols, magic numbers */
+#define YPPROG ((unsigned long)100004)
+#define YPVERS ((unsigned long)2)
+#define YPVERS_ORIG ((unsigned long)1)
+#define YPMAXRECORD ((unsigned long)1024)
+#define YPMAXDOMAIN ((unsigned long)64)
+#define YPMAXMAP ((unsigned long)64)
+#define YPMAXPEER ((unsigned long)256)
+
+/*
+ * I don't know if anything of sun's depends on this, or if they
+ * simply defined it so that their own code wouldn't try to send
+ * packets over the ethernet MTU. This YP code doesn't use it.
+ */
+#define YPMSGSZ 1600
+
+#ifndef DATUM
+typedef struct {
+ const char *dptr;
+ int dsize;
+} datum;
+#define DATUM
+#endif
+
+struct ypmap_parms {
+ const char *domain;
+ const char *map;
+ unsigned long ordernum;
+ char *owner;
+};
+
+struct ypreq_key {
+ const char *domain;
+ const char *map;
+ datum keydat;
+};
+
+struct ypreq_nokey {
+ const char *domain;
+ const char *map;
+};
+
+struct ypreq_xfr {
+ struct ypmap_parms map_parms;
+ unsigned long transid;
+ unsigned long proto;
+ unsigned short port;
+};
+#define ypxfr_domain map_parms.domain
+#define ypxfr_map map_parms.map
+#define ypxfr_ordernum map_parms.ordernum
+#define ypxfr_owner map_parms.owner
+
+struct ypresp_val {
+ unsigned long status;
+ datum valdat;
+};
+
+struct ypresp_key_val {
+ unsigned long status;
+ datum keydat;
+ datum valdat;
+};
+
+struct ypresp_master {
+ unsigned long status;
+ char *master;
+};
+
+struct ypresp_order {
+ unsigned long status;
+ unsigned long ordernum;
+};
+
+struct ypresp_all {
+ bool_t more;
+ union {
+ struct ypresp_key_val val;
+ } ypresp_all_u;
+};
+
+struct ypmaplist {
+ char ypml_name[YPMAXMAP + 1];
+ struct ypmaplist *ypml_next;
+};
+
+struct ypresp_maplist {
+ unsigned long status;
+ struct ypmaplist *list;
+};
+
+/* ypserv procedure numbers */
+#define YPPROC_NULL ((unsigned long)0)
+#define YPPROC_DOMAIN ((unsigned long)1)
+#define YPPROC_DOMAIN_NONACK ((unsigned long)2)
+#define YPPROC_MATCH ((unsigned long)3)
+#define YPPROC_FIRST ((unsigned long)4)
+#define YPPROC_NEXT ((unsigned long)5)
+#define YPPROC_XFR ((unsigned long)6)
+#define YPPROC_CLEAR ((unsigned long)7)
+#define YPPROC_ALL ((unsigned long)8)
+#define YPPROC_MASTER ((unsigned long)9)
+#define YPPROC_ORDER ((unsigned long)10)
+#define YPPROC_MAPLIST ((unsigned long)11)
+
+/* ypserv procedure return status values */
+#define YP_TRUE ((unsigned long)1) /* general purpose success code */
+#define YP_NOMORE ((unsigned long)2) /* no more entries in map */
+#define YP_FALSE ((unsigned long)0) /* general purpose failure code */
+#define YP_NOMAP ((unsigned long)-1) /* no such map in domain */
+#define YP_NODOM ((unsigned long)-2) /* domain not supported */
+#define YP_NOKEY ((unsigned long)-3) /* no such key in map */
+#define YP_BADOP ((unsigned long)-4) /* invalid operation */
+#define YP_BADDB ((unsigned long)-5) /* server data base is bad */
+#define YP_YPERR ((unsigned long)-6) /* YP server error */
+#define YP_BADARGS ((unsigned long)-7) /* request arguments bad */
+#define YP_VERS ((unsigned long)-8) /* YP server version mismatch */
+
+/*
+ * YPBIND PROTOCOL:
+ *
+ * ypbind supports the following procedures:
+ *
+ * YPBINDPROC_NULL takes (void), returns (void).
+ * to check if ypbind is running.
+ * YPBINDPROC_DOMAIN takes (char *), returns (struct ypbind_resp).
+ * requests that ypbind start to serve the
+ * named domain (if it doesn't already)
+ * YPBINDPROC_SETDOM takes (struct ypbind_setdom), returns (void).
+ * used by ypset.
+ */
+
+#define YPBINDPROG ((unsigned long)100007)
+#define YPBINDVERS ((unsigned long)2)
+#define YPBINDVERS_ORIG ((unsigned long)1)
+
+/* ypbind procedure numbers */
+#define YPBINDPROC_NULL ((unsigned long)0)
+#define YPBINDPROC_DOMAIN ((unsigned long)1)
+#define YPBINDPROC_SETDOM ((unsigned long)2)
+
+/* error code in ypbind_resp.ypbind_status */
+enum ypbind_resptype {
+ YPBIND_SUCC_VAL = 1,
+ YPBIND_FAIL_VAL = 2
+};
+
+/* network order, of course */
+struct ypbind_binding {
+ struct in_addr ypbind_binding_addr;
+ unsigned short ypbind_binding_port;
+};
+
+struct ypbind_resp {
+ enum ypbind_resptype ypbind_status;
+ union {
+ unsigned long ypbind_error;
+ struct ypbind_binding ypbind_bindinfo;
+ } ypbind_respbody;
+};
+
+/* error code in ypbind_resp.ypbind_respbody.ypbind_error */
+#define YPBIND_ERR_ERR 1 /* internal error */
+#define YPBIND_ERR_NOSERV 2 /* no bound server for passed domain */
+#define YPBIND_ERR_RESC 3 /* system resource allocation failure */
+
+/*
+ * Request data structure for ypbind "Set domain" procedure.
+ */
+struct ypbind_setdom {
+ char ypsetdom_domain[YPMAXDOMAIN + 1];
+ struct ypbind_binding ypsetdom_binding;
+ unsigned short ypsetdom_vers;
+};
+#define ypsetdom_addr ypsetdom_binding.ypbind_binding_addr
+#define ypsetdom_port ypsetdom_binding.ypbind_binding_port
+
+/*
+ * YPPUSH PROTOCOL:
+ *
+ * Sun says:
+ * "Protocol between clients (ypxfr, only) and yppush
+ * yppush speaks a protocol in the transient range, which
+ * is supplied to ypxfr as a command-line parameter when it
+ * is activated by ypserv."
+ *
+ * This protocol is not implemented, naturally, because this YP
+ * implementation only does the client side.
+ */
+#define YPPUSHVERS ((unsigned long)1)
+#define YPPUSHVERS_ORIG ((unsigned long)1)
+
+/* yppush procedure numbers */
+#define YPPUSHPROC_NULL ((unsigned long)0)
+#define YPPUSHPROC_XFRRESP ((unsigned long)1)
+
+struct yppushresp_xfr {
+ unsigned long transid;
+ unsigned long status;
+};
+
+/* yppush status value in yppushresp_xfr.status */
+#define YPPUSH_SUCC ((unsigned long)1) /* Success */
+#define YPPUSH_AGE ((unsigned long)2) /* Master's version not newer */
+#define YPPUSH_NOMAP ((unsigned long)-1) /* Can't find server for map */
+#define YPPUSH_NODOM ((unsigned long)-2) /* Domain not supported */
+#define YPPUSH_RSRC ((unsigned long)-3) /* Local resouce alloc failure */
+#define YPPUSH_RPC ((unsigned long)-4) /* RPC failure talking to server */
+#define YPPUSH_MADDR ((unsigned long)-5) /* Can't get master address */
+#define YPPUSH_YPERR ((unsigned long)-6) /* YP server/map db error */
+#define YPPUSH_BADARGS ((unsigned long)-7) /* Request arguments bad */
+#define YPPUSH_DBM ((unsigned long)-8) /* Local dbm operation failed */
+#define YPPUSH_FILE ((unsigned long)-9) /* Local file I/O operation failed */
+#define YPPUSH_SKEW ((unsigned long)-10) /* Map version skew during transfer */
+#define YPPUSH_CLEAR ((unsigned long)-11) /* Can't send "Clear" req to local ypserv */
+#define YPPUSH_FORCE ((unsigned long)-12) /* No local order number in map - use -f */
+#define YPPUSH_XFRERR ((unsigned long)-13) /* ypxfr error */
+#define YPPUSH_REFUSED ((unsigned long)-14) /* Transfer request refused by ypserv */
+
+__BEGIN_DECLS
+bool_t xdr_domainname(XDR *, char *);
+bool_t xdr_peername(XDR *, char *);
+bool_t xdr_datum(XDR *, datum *);
+bool_t xdr_mapname(XDR *, char *);
+bool_t xdr_ypreq_key(XDR *, struct ypreq_key *);
+bool_t xdr_ypreq_nokey(XDR *, struct ypreq_nokey *);
+bool_t xdr_yp_inaddr(XDR *, struct in_addr *);
+bool_t xdr_ypbind_binding(XDR *, struct ypbind_binding *);
+bool_t xdr_ypbind_resptype(XDR *, enum ypbind_resptype *);
+bool_t xdr_ypstat(XDR *, enum ypbind_resptype *);
+bool_t xdr_ypbind_resp(XDR *, struct ypbind_resp *);
+bool_t xdr_ypresp_val(XDR *, struct ypresp_val *);
+bool_t xdr_ypbind_setdom(XDR *, struct ypbind_setdom *);
+bool_t xdr_ypresp_key_val(XDR *, struct ypresp_key_val *);
+bool_t xdr_ypresp_all(XDR *, struct ypresp_all *);
+bool_t xdr_ypresp_master(XDR *, struct ypresp_master *);
+bool_t xdr_ypmaplist_str(XDR *, char *);
+bool_t xdr_ypmaplist(XDR *, struct ypmaplist *);
+bool_t xdr_ypresp_maplist(XDR *, struct ypresp_maplist *);
+bool_t xdr_ypresp_order(XDR *, struct ypresp_order *);
+__END_DECLS
+
+#endif /* _RPCSVC_YP_PROT_H_ */
diff --git a/include/rpcsvc/ypclnt.h b/include/rpcsvc/ypclnt.h
new file mode 100644
index 0000000..f7af7c3
--- /dev/null
+++ b/include/rpcsvc/ypclnt.h
@@ -0,0 +1,82 @@
+/* $OpenBSD: ypclnt.h,v 1.10 2016/05/30 02:53:29 guenther Exp $ */
+/* $NetBSD: ypclnt.h,v 1.7 1995/07/14 21:11:10 christos Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993 Theo de Raadt <deraadt@openbsd.org>
+ * 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.
+ */
+
+#ifndef _RPCSVC_YPCLNT_H_
+#define _RPCSVC_YPCLNT_H_
+
+#define YPERR_BADARGS 1 /* args to function are bad */
+#define YPERR_RPC 2 /* RPC failure */
+#define YPERR_DOMAIN 3 /* can't bind to a server for domain */
+#define YPERR_MAP 4 /* no such map in server's domain */
+#define YPERR_KEY 5 /* no such key in map */
+#define YPERR_YPERR 6 /* some internal YP server or client error */
+#define YPERR_RESRC 7 /* local resource allocation failure */
+#define YPERR_NOMORE 8 /* no more records in map database */
+#define YPERR_PMAP 9 /* can't communicate with portmapper */
+#define YPERR_YPBIND 10 /* can't communicate with ypbind */
+#define YPERR_YPSERV 11 /* can't communicate with ypserv */
+#define YPERR_NODOM 12 /* local domain name not set */
+#define YPERR_BADDB 13 /* YP data base is bad */
+#define YPERR_VERS 14 /* YP version mismatch */
+#define YPERR_ACCESS 15 /* access violation */
+#define YPERR_BUSY 16 /* database is busy */
+
+/*
+ * Types of update operations
+ */
+#define YPOP_CHANGE 1 /* change, do not add */
+#define YPOP_INSERT 2 /* add, do not change */
+#define YPOP_DELETE 3 /* delete this entry */
+#define YPOP_STORE 4 /* add, or change */
+
+struct ypall_callback {
+ /* return non-0 to stop getting called */
+ int (*foreach)(unsigned long, char *, int, char *, int, void *);
+ char *data; /* opaque pointer for use of callback fn */
+};
+
+__BEGIN_DECLS
+int yp_bind(const char *);
+void yp_unbind(const char *);
+int yp_get_default_domain(char **);
+int yp_match(const char *, const char *, const char *, int , char **,
+ int *);
+int yp_first(const char *, const char *, char **, int *, char **, int *);
+int yp_next(const char *, const char *, const char *, int, char **, int *,
+ char **, int *);
+int yp_master(const char *, const char *, char **);
+int yp_order(const char *, const char *, int *);
+int yp_all(const char *, const char *, struct ypall_callback *);
+char * yperr_string(int);
+int ypprot_err(unsigned int);
+struct ypmaplist;
+int yp_maplist(const char *, struct ypmaplist **);
+__END_DECLS
+
+#endif /* _RPCSVC_YPCLNT_H_ */
diff --git a/include/sched.h b/include/sched.h
new file mode 100644
index 0000000..8e468b4
--- /dev/null
+++ b/include/sched.h
@@ -0,0 +1,75 @@
+/* $OpenBSD: sched.h,v 1.1 2017/10/15 23:40:33 guenther Exp $ */
+
+/* sched.h: POSIX 1003.1b Process Scheduling header */
+
+/*-
+ * Copyright (c) 1996, 1997
+ * HD Associates, 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by HD Associates, Inc
+ * and Jukka Antero Ukkonen.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES 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 HD ASSOCIATES 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 _SCHED_H_
+#define _SCHED_H_
+
+#include <sys/types.h> /* For pid_t */
+#include <time.h> /* Per P1003.4 */
+
+/* Scheduling policies
+ */
+#define SCHED_FIFO 1
+#define SCHED_OTHER 2
+#define SCHED_RR 3
+
+struct sched_param
+{
+ int sched_priority;
+};
+
+__BEGIN_DECLS
+#if 0 /* not yet */
+int sched_setparam(pid_t, const struct sched_param *);
+int sched_getparam(pid_t, struct sched_param *);
+
+int sched_setscheduler(pid_t, int, const struct sched_param *);
+int sched_getscheduler(pid_t);
+#endif
+
+int sched_yield(void);
+int sched_get_priority_max(int);
+int sched_get_priority_min(int);
+
+#if 0 /* not yet */
+struct timespec;
+int sched_rr_get_interval(pid_t, struct timespec *);
+#endif
+__END_DECLS
+
+#endif /* _SCHED_H_ */
diff --git a/include/search.h b/include/search.h
new file mode 100644
index 0000000..37f2e60
--- /dev/null
+++ b/include/search.h
@@ -0,0 +1,57 @@
+/* $OpenBSD: search.h,v 1.10 2014/07/18 04:16:09 matthew Exp $ */
+/* $NetBSD: search.h,v 1.9 1995/08/08 21:14:45 jtc Exp $ */
+
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>
+ * Public domain.
+ */
+
+#ifndef _SEARCH_H_
+#define _SEARCH_H_
+
+#include <sys/cdefs.h>
+#include <machine/_types.h>
+
+#ifndef _SIZE_T_DEFINED_
+#define _SIZE_T_DEFINED_
+typedef __size_t size_t;
+#endif
+
+typedef struct entry {
+ char *key;
+ void *data;
+} ENTRY;
+
+typedef enum {
+ FIND, ENTER
+} ACTION;
+
+typedef enum {
+ preorder,
+ postorder,
+ endorder,
+ leaf
+} VISIT;
+
+__BEGIN_DECLS
+int hcreate(size_t);
+void hdestroy(void);
+ENTRY *hsearch(ENTRY, ACTION);
+
+void *lfind(const void *, const void *, size_t *, size_t,
+ int (*)(const void *, const void *));
+void *lsearch(const void *, void *, size_t *, size_t,
+ int (*)(const void *, const void *));
+void insque(void *, void *);
+void remque(void *);
+
+void *tdelete(const void * __restrict, void ** __restrict,
+ int (*)(const void *, const void *));
+void *tfind(const void *, void * const *,
+ int (*)(const void *, const void *));
+void *tsearch(const void *, void **,
+ int (*)(const void *, const void *));
+void twalk(const void *, void (*)(const void *, VISIT, int));
+__END_DECLS
+
+#endif /* !_SEARCH_H_ */
diff --git a/include/semaphore.h b/include/semaphore.h
new file mode 100644
index 0000000..21dc1a2
--- /dev/null
+++ b/include/semaphore.h
@@ -0,0 +1,62 @@
+/* $OpenBSD: semaphore.h,v 1.1 2017/10/15 23:40:33 guenther Exp $ */
+
+/* semaphore.h: POSIX 1003.1b semaphores */
+
+/*-
+ * Copyright (c) 1996, 1997
+ * HD Associates, 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.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by HD Associates, Inc
+ * 4. Neither the name of the author nor the names of any co-contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY HD ASSOCIATES 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 HD ASSOCIATES 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 _SEMAPHORE_H_
+#define _SEMAPHORE_H_
+
+#include <sys/cdefs.h>
+
+/* Opaque type definition. */
+struct __sem;
+typedef struct __sem *sem_t;
+struct timespec;
+
+#define SEM_FAILED ((sem_t *)0)
+
+__BEGIN_DECLS
+int sem_init(sem_t *, int, unsigned int);
+int sem_destroy(sem_t *);
+sem_t *sem_open(const char *, int, ...);
+int sem_close(sem_t *);
+int sem_unlink(const char *);
+int sem_wait(sem_t *);
+int sem_timedwait(sem_t * __restrict, const struct timespec * __restrict);
+int sem_trywait(sem_t *);
+int sem_post(sem_t *);
+int sem_getvalue(sem_t * __restrict, int * __restrict);
+__END_DECLS
+
+#endif /* _SEMAPHORE_H_ */
diff --git a/include/setjmp.h b/include/setjmp.h
new file mode 100644
index 0000000..c278650
--- /dev/null
+++ b/include/setjmp.h
@@ -0,0 +1,67 @@
+/* $OpenBSD: setjmp.h,v 1.7 2016/05/23 00:18:56 guenther Exp $ */
+/* $NetBSD: setjmp.h,v 1.11 1994/12/20 10:35:44 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)setjmp.h 8.2 (Berkeley) 1/21/94
+ */
+
+#ifndef _SETJMP_H_
+#define _SETJMP_H_
+
+#include <sys/cdefs.h>
+#include <machine/setjmp.h>
+
+#if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE
+typedef long sigjmp_buf[_JBLEN + 1];
+#endif /* __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE */
+
+typedef long jmp_buf[_JBLEN];
+
+__BEGIN_DECLS
+__returns_twice int setjmp(jmp_buf);
+__dead void longjmp(jmp_buf, int);
+
+#if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE
+__returns_twice int sigsetjmp(sigjmp_buf, int);
+__dead void siglongjmp(sigjmp_buf, int);
+#endif /* __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE */
+
+#if __BSD_VISIBLE || __XPG_VISIBLE
+__returns_twice int _setjmp(jmp_buf);
+__dead void _longjmp(jmp_buf, int);
+#endif /* __BSD_VISIBLE || __XPG_VISIBLE */
+__END_DECLS
+
+#endif /* !_SETJMP_H_ */
diff --git a/include/sha1.h b/include/sha1.h
new file mode 100644
index 0000000..f596be6
--- /dev/null
+++ b/include/sha1.h
@@ -0,0 +1,57 @@
+/* $OpenBSD: sha1.h,v 1.24 2012/12/05 23:19:57 deraadt Exp $ */
+
+/*
+ * SHA-1 in C
+ * By Steve Reid <steve@edmweb.com>
+ * 100% Public Domain
+ */
+
+#ifndef _SHA1_H
+#define _SHA1_H
+
+#define SHA1_BLOCK_LENGTH 64
+#define SHA1_DIGEST_LENGTH 20
+#define SHA1_DIGEST_STRING_LENGTH (SHA1_DIGEST_LENGTH * 2 + 1)
+
+typedef struct {
+ u_int32_t state[5];
+ u_int64_t count;
+ u_int8_t buffer[SHA1_BLOCK_LENGTH];
+} SHA1_CTX;
+
+__BEGIN_DECLS
+void SHA1Init(SHA1_CTX *);
+void SHA1Pad(SHA1_CTX *);
+void SHA1Transform(u_int32_t [5], const u_int8_t [SHA1_BLOCK_LENGTH])
+ __attribute__((__bounded__(__minbytes__,1,5)))
+ __attribute__((__bounded__(__minbytes__,2,SHA1_BLOCK_LENGTH)));
+void SHA1Update(SHA1_CTX *, const u_int8_t *, size_t)
+ __attribute__((__bounded__(__string__,2,3)));
+void SHA1Final(u_int8_t [SHA1_DIGEST_LENGTH], SHA1_CTX *)
+ __attribute__((__bounded__(__minbytes__,1,SHA1_DIGEST_LENGTH)));
+char *SHA1End(SHA1_CTX *, char *)
+ __attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH)));
+char *SHA1File(const char *, char *)
+ __attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH)));
+char *SHA1FileChunk(const char *, char *, off_t, off_t)
+ __attribute__((__bounded__(__minbytes__,2,SHA1_DIGEST_STRING_LENGTH)));
+char *SHA1Data(const u_int8_t *, size_t, char *)
+ __attribute__((__bounded__(__string__,1,2)))
+ __attribute__((__bounded__(__minbytes__,3,SHA1_DIGEST_STRING_LENGTH)));
+__END_DECLS
+
+#define HTONDIGEST(x) do { \
+ x[0] = htonl(x[0]); \
+ x[1] = htonl(x[1]); \
+ x[2] = htonl(x[2]); \
+ x[3] = htonl(x[3]); \
+ x[4] = htonl(x[4]); } while (0)
+
+#define NTOHDIGEST(x) do { \
+ x[0] = ntohl(x[0]); \
+ x[1] = ntohl(x[1]); \
+ x[2] = ntohl(x[2]); \
+ x[3] = ntohl(x[3]); \
+ x[4] = ntohl(x[4]); } while (0)
+
+#endif /* _SHA1_H */
diff --git a/include/sha2.h b/include/sha2.h
new file mode 100644
index 0000000..52ddb3f
--- /dev/null
+++ b/include/sha2.h
@@ -0,0 +1,156 @@
+/* $OpenBSD: sha2.h,v 1.10 2016/09/03 17:00:29 tedu Exp $ */
+
+/*
+ * FILE: sha2.h
+ * AUTHOR: Aaron D. Gifford <me@aarongifford.com>
+ *
+ * Copyright (c) 2000-2001, Aaron D. Gifford
+ * 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 copyright holder nor the names of contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``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 CONTRIBUTOR(S) 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: sha2.h,v 1.1 2001/11/08 00:02:01 adg Exp adg $
+ */
+
+#ifndef _SHA2_H
+#define _SHA2_H
+
+
+/*** SHA-256/384/512 Various Length Definitions ***********************/
+#define SHA224_BLOCK_LENGTH 64
+#define SHA224_DIGEST_LENGTH 28
+#define SHA224_DIGEST_STRING_LENGTH (SHA224_DIGEST_LENGTH * 2 + 1)
+#define SHA256_BLOCK_LENGTH 64
+#define SHA256_DIGEST_LENGTH 32
+#define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
+#define SHA384_BLOCK_LENGTH 128
+#define SHA384_DIGEST_LENGTH 48
+#define SHA384_DIGEST_STRING_LENGTH (SHA384_DIGEST_LENGTH * 2 + 1)
+#define SHA512_BLOCK_LENGTH 128
+#define SHA512_DIGEST_LENGTH 64
+#define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1)
+#define SHA512_256_BLOCK_LENGTH 128
+#define SHA512_256_DIGEST_LENGTH 32
+#define SHA512_256_DIGEST_STRING_LENGTH (SHA512_256_DIGEST_LENGTH * 2 + 1)
+
+
+/*** SHA-224/256/384/512 Context Structure *******************************/
+typedef struct _SHA2_CTX {
+ union {
+ u_int32_t st32[8];
+ u_int64_t st64[8];
+ } state;
+ u_int64_t bitcount[2];
+ u_int8_t buffer[SHA512_BLOCK_LENGTH];
+} SHA2_CTX;
+
+__BEGIN_DECLS
+void SHA224Init(SHA2_CTX *);
+void SHA224Transform(u_int32_t state[8], const u_int8_t [SHA224_BLOCK_LENGTH]);
+void SHA224Update(SHA2_CTX *, const u_int8_t *, size_t)
+ __attribute__((__bounded__(__string__,2,3)));
+void SHA224Pad(SHA2_CTX *);
+void SHA224Final(u_int8_t [SHA224_DIGEST_LENGTH], SHA2_CTX *)
+ __attribute__((__bounded__(__minbytes__,1,SHA224_DIGEST_LENGTH)));
+char *SHA224End(SHA2_CTX *, char *)
+ __attribute__((__bounded__(__minbytes__,2,SHA224_DIGEST_STRING_LENGTH)));
+char *SHA224File(const char *, char *)
+ __attribute__((__bounded__(__minbytes__,2,SHA224_DIGEST_STRING_LENGTH)));
+char *SHA224FileChunk(const char *, char *, off_t, off_t)
+ __attribute__((__bounded__(__minbytes__,2,SHA224_DIGEST_STRING_LENGTH)));
+char *SHA224Data(const u_int8_t *, size_t, char *)
+ __attribute__((__bounded__(__string__,1,2)))
+ __attribute__((__bounded__(__minbytes__,3,SHA224_DIGEST_STRING_LENGTH)));
+
+void SHA256Init(SHA2_CTX *);
+void SHA256Transform(u_int32_t state[8], const u_int8_t [SHA256_BLOCK_LENGTH]);
+void SHA256Update(SHA2_CTX *, const u_int8_t *, size_t)
+ __attribute__((__bounded__(__string__,2,3)));
+void SHA256Pad(SHA2_CTX *);
+void SHA256Final(u_int8_t [SHA256_DIGEST_LENGTH], SHA2_CTX *)
+ __attribute__((__bounded__(__minbytes__,1,SHA256_DIGEST_LENGTH)));
+char *SHA256End(SHA2_CTX *, char *)
+ __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH)));
+char *SHA256File(const char *, char *)
+ __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH)));
+char *SHA256FileChunk(const char *, char *, off_t, off_t)
+ __attribute__((__bounded__(__minbytes__,2,SHA256_DIGEST_STRING_LENGTH)));
+char *SHA256Data(const u_int8_t *, size_t, char *)
+ __attribute__((__bounded__(__string__,1,2)))
+ __attribute__((__bounded__(__minbytes__,3,SHA256_DIGEST_STRING_LENGTH)));
+
+void SHA384Init(SHA2_CTX *);
+void SHA384Transform(u_int64_t state[8], const u_int8_t [SHA384_BLOCK_LENGTH]);
+void SHA384Update(SHA2_CTX *, const u_int8_t *, size_t)
+ __attribute__((__bounded__(__string__,2,3)));
+void SHA384Pad(SHA2_CTX *);
+void SHA384Final(u_int8_t [SHA384_DIGEST_LENGTH], SHA2_CTX *)
+ __attribute__((__bounded__(__minbytes__,1,SHA384_DIGEST_LENGTH)));
+char *SHA384End(SHA2_CTX *, char *)
+ __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH)));
+char *SHA384File(const char *, char *)
+ __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH)));
+char *SHA384FileChunk(const char *, char *, off_t, off_t)
+ __attribute__((__bounded__(__minbytes__,2,SHA384_DIGEST_STRING_LENGTH)));
+char *SHA384Data(const u_int8_t *, size_t, char *)
+ __attribute__((__bounded__(__string__,1,2)))
+ __attribute__((__bounded__(__minbytes__,3,SHA384_DIGEST_STRING_LENGTH)));
+
+void SHA512Init(SHA2_CTX *);
+void SHA512Transform(u_int64_t state[8], const u_int8_t [SHA512_BLOCK_LENGTH]);
+void SHA512Update(SHA2_CTX *, const u_int8_t *, size_t)
+ __attribute__((__bounded__(__string__,2,3)));
+void SHA512Pad(SHA2_CTX *);
+void SHA512Final(u_int8_t [SHA512_DIGEST_LENGTH], SHA2_CTX *)
+ __attribute__((__bounded__(__minbytes__,1,SHA512_DIGEST_LENGTH)));
+char *SHA512End(SHA2_CTX *, char *)
+ __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH)));
+char *SHA512File(const char *, char *)
+ __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH)));
+char *SHA512FileChunk(const char *, char *, off_t, off_t)
+ __attribute__((__bounded__(__minbytes__,2,SHA512_DIGEST_STRING_LENGTH)));
+char *SHA512Data(const u_int8_t *, size_t, char *)
+ __attribute__((__bounded__(__string__,1,2)))
+ __attribute__((__bounded__(__minbytes__,3,SHA512_DIGEST_STRING_LENGTH)));
+
+void SHA512_256Init(SHA2_CTX *);
+void SHA512_256Transform(u_int64_t state[8], const u_int8_t [SHA512_256_BLOCK_LENGTH]);
+void SHA512_256Update(SHA2_CTX *, const u_int8_t *, size_t)
+ __attribute__((__bounded__(__string__,2,3)));
+void SHA512_256Pad(SHA2_CTX *);
+void SHA512_256Final(u_int8_t [SHA512_256_DIGEST_LENGTH], SHA2_CTX *)
+ __attribute__((__bounded__(__minbytes__,1,SHA512_256_DIGEST_LENGTH)));
+char *SHA512_256End(SHA2_CTX *, char *)
+ __attribute__((__bounded__(__minbytes__,2,SHA512_256_DIGEST_STRING_LENGTH)));
+char *SHA512_256File(const char *, char *)
+ __attribute__((__bounded__(__minbytes__,2,SHA512_256_DIGEST_STRING_LENGTH)));
+char *SHA512_256FileChunk(const char *, char *, off_t, off_t)
+ __attribute__((__bounded__(__minbytes__,2,SHA512_256_DIGEST_STRING_LENGTH)));
+char *SHA512_256Data(const u_int8_t *, size_t, char *)
+ __attribute__((__bounded__(__string__,1,2)))
+ __attribute__((__bounded__(__minbytes__,3,SHA512_256_DIGEST_STRING_LENGTH)));
+__END_DECLS
+
+#endif /* _SHA2_H */
diff --git a/include/signal.h b/include/signal.h
new file mode 100644
index 0000000..07982bd
--- /dev/null
+++ b/include/signal.h
@@ -0,0 +1,140 @@
+/* $OpenBSD: signal.h,v 1.26 2018/05/30 13:20:38 bluhm Exp $ */
+/* $NetBSD: signal.h,v 1.8 1996/02/29 00:04:57 jtc Exp $ */
+
+/*-
+ * Copyright (c) 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.
+ * 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.
+ *
+ * @(#)signal.h 8.3 (Berkeley) 3/30/94
+ */
+
+#ifndef _USER_SIGNAL_H
+#define _USER_SIGNAL_H
+
+#include <sys/signal.h>
+
+#if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE
+#include <sys/types.h>
+#endif
+
+__BEGIN_DECLS
+#if __BSD_VISIBLE
+extern const char *const sys_signame[_NSIG];
+extern const char *const sys_siglist[_NSIG];
+#endif
+
+int raise(int);
+#if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE
+#if __BSD_VISIBLE || (__XPG_VISIBLE >= 500 && __XPG_VISIBLE < 700)
+void (*bsd_signal(int, void (*)(int)))(int);
+#endif
+int kill(pid_t, int);
+int sigaction(int, const struct sigaction *__restrict,
+ struct sigaction *__restrict);
+int sigaddset(sigset_t *, int);
+int sigdelset(sigset_t *, int);
+int sigemptyset(sigset_t *);
+int sigfillset(sigset_t *);
+int sigismember(const sigset_t *, int);
+int sigpending(sigset_t *);
+int sigprocmask(int, const sigset_t *__restrict, sigset_t *__restrict);
+#if __POSIX_VISIBLE >= 199506
+int pthread_sigmask(int, const sigset_t *__restrict, sigset_t *__restrict);
+#endif
+int sigsuspend(const sigset_t *);
+
+#if !defined(_ANSI_LIBRARY)
+
+extern int *__errno(void);
+
+__only_inline int sigaddset(sigset_t *__set, int __signo)
+{
+ if (__signo <= 0 || __signo >= _NSIG) {
+ *__errno() = 22; /* EINVAL */
+ return -1;
+ }
+ *__set |= (1U << ((__signo)-1)); /* sigmask(__signo) */
+ return (0);
+}
+
+__only_inline int sigdelset(sigset_t *__set, int __signo)
+{
+ if (__signo <= 0 || __signo >= _NSIG) {
+ *__errno() = 22; /* EINVAL */
+ return -1;
+ }
+ *__set &= ~(1U << ((__signo)-1)); /* sigmask(__signo) */
+ return (0);
+}
+
+__only_inline int sigismember(const sigset_t *__set, int __signo)
+{
+ if (__signo <= 0 || __signo >= _NSIG) {
+ *__errno() = 22; /* EINVAL */
+ return -1;
+ }
+ return ((*__set & (1U << ((__signo)-1))) != 0);
+}
+
+__only_inline int sigemptyset(sigset_t *__set)
+{
+ *__set = 0;
+ return (0);
+}
+
+__only_inline int sigfillset(sigset_t *__set)
+{
+ *__set = ~(sigset_t)0;
+ return (0);
+}
+
+#endif /* !_ANSI_LIBRARY */
+
+#if __BSD_VISIBLE || __XPG_VISIBLE >= 420
+int killpg(pid_t, int);
+int siginterrupt(int, int);
+int sigaltstack(const struct sigaltstack *__restrict,
+ struct sigaltstack *__restrict);
+#if __BSD_VISIBLE
+int sigblock(int);
+/* This is the traditional BSD sigpause() and not the XPG/POSIX sigpause(). */
+int sigpause(int);
+int sigsetmask(int);
+int sigvec(int, struct sigvec *, struct sigvec *);
+int thrkill(pid_t _tid, int _signum, void *_tcb);
+#endif
+#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */
+#if __BSD_VISIBLE || __POSIX_VISIBLE >= 199309 || __XPG_VISIBLE >= 500
+int sigwait(const sigset_t *__restrict, int *__restrict);
+#endif
+#if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809
+void psignal(unsigned int, const char *);
+#endif
+#endif /* __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE */
+__END_DECLS
+
+#endif /* !_USER_SIGNAL_H */
diff --git a/include/siphash.h b/include/siphash.h
new file mode 100644
index 0000000..7a5990c
--- /dev/null
+++ b/include/siphash.h
@@ -0,0 +1,83 @@
+/*-
+ * Copyright (c) 2013 Andre Oppermann <andre@FreeBSD.org>
+ * 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 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.
+ *
+ * $OpenBSD: siphash.h,v 1.3 2015/02/20 11:51:03 tedu Exp $
+ */
+
+/*
+ * SipHash is a family of pseudorandom functions (a.k.a. keyed hash functions)
+ * optimized for speed on short messages returning a 64bit hash/digest value.
+ *
+ * The number of rounds is defined during the initialization:
+ * SipHash24_Init() for the fast and resonable strong version
+ * SipHash48_Init() for the strong version (half as fast)
+ *
+ * struct SIPHASH_CTX ctx;
+ * SipHash24_Init(&ctx);
+ * SipHash_SetKey(&ctx, "16bytes long key");
+ * SipHash_Update(&ctx, pointer_to_string, length_of_string);
+ * SipHash_Final(output, &ctx);
+ */
+
+#ifndef _SIPHASH_H_
+#define _SIPHASH_H_
+
+#define SIPHASH_BLOCK_LENGTH 8
+#define SIPHASH_KEY_LENGTH 16
+#define SIPHASH_DIGEST_LENGTH 8
+
+typedef struct _SIPHASH_CTX {
+ uint64_t v[4];
+ uint8_t buf[SIPHASH_BLOCK_LENGTH];
+ uint32_t bytes;
+} SIPHASH_CTX;
+
+typedef struct {
+ uint64_t k0;
+ uint64_t k1;
+} SIPHASH_KEY;
+
+void SipHash_Init(SIPHASH_CTX *, const SIPHASH_KEY *);
+void SipHash_Update(SIPHASH_CTX *, int, int, const void *, size_t);
+uint64_t SipHash_End(SIPHASH_CTX *, int, int);
+void SipHash_Final(void *, SIPHASH_CTX *, int, int);
+uint64_t SipHash(const SIPHASH_KEY *, int, int, const void *, size_t);
+
+#define SipHash24_Init(_c, _k) SipHash_Init((_c), (_k))
+#define SipHash24_Update(_c, _p, _l) SipHash_Update((_c), 2, 4, (_p), (_l))
+#define SipHash24_End(_d) SipHash_End((_d), 2, 4)
+#define SipHash24_Final(_d, _c) SipHash_Final((_d), (_c), 2, 4)
+#define SipHash24(_k, _p, _l) SipHash((_k), 2, 4, (_p), (_l))
+
+#define SipHash48_Init(_c, _k) SipHash_Init((_c), (_k))
+#define SipHash48_Update(_c, _p, _l) SipHash_Update((_c), 4, 8, (_p), (_l))
+#define SipHash48_End(_d) SipHash_End((_d), 4, 8)
+#define SipHash48_Final(_d, _c) SipHash_Final((_d), (_c), 4, 8)
+#define SipHash48(_k, _p, _l) SipHash((_k), 4, 8, (_p), (_l))
+
+#endif /* _SIPHASH_H_ */
diff --git a/include/sndio.h b/include/sndio.h
new file mode 100644
index 0000000..4fed3d5
--- /dev/null
+++ b/include/sndio.h
@@ -0,0 +1,205 @@
+/* $OpenBSD: sndio.h,v 1.10 2020/02/26 13:53:58 ratchov Exp $ */
+/*
+ * Copyright (c) 2008 Alexandre Ratchov <alex@caoua.org>
+ *
+ * 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.
+ */
+#ifndef SNDIO_H
+#define SNDIO_H
+
+#include <sys/types.h>
+
+/*
+ * default audio device and MIDI port
+ */
+#define SIO_DEVANY "default"
+#define MIO_PORTANY "default"
+
+/*
+ * limits
+ */
+#define SIOCTL_NAMEMAX 12 /* max name length */
+
+/*
+ * private ``handle'' structure
+ */
+struct sio_hdl;
+struct mio_hdl;
+struct sioctl_hdl;
+
+/*
+ * parameters of a full-duplex stream
+ */
+struct sio_par {
+ unsigned int bits; /* bits per sample */
+ unsigned int bps; /* bytes per sample */
+ unsigned int sig; /* 1 = signed, 0 = unsigned */
+ unsigned int le; /* 1 = LE, 0 = BE byte order */
+ unsigned int msb; /* 1 = MSB, 0 = LSB aligned */
+ unsigned int rchan; /* number channels for recording direction */
+ unsigned int pchan; /* number channels for playback direction */
+ unsigned int rate; /* frames per second */
+ unsigned int bufsz; /* end-to-end buffer size */
+#define SIO_IGNORE 0 /* pause during xrun */
+#define SIO_SYNC 1 /* resync after xrun */
+#define SIO_ERROR 2 /* terminate on xrun */
+ unsigned int xrun; /* what to do on overruns/underruns */
+ unsigned int round; /* optimal bufsz divisor */
+ unsigned int appbufsz; /* minimum buffer size */
+ int __pad[3]; /* for future use */
+ unsigned int __magic; /* for internal/debug purposes only */
+};
+
+/*
+ * capabilities of a stream
+ */
+struct sio_cap {
+#define SIO_NENC 8
+#define SIO_NCHAN 8
+#define SIO_NRATE 16
+#define SIO_NCONF 4
+ struct sio_enc { /* allowed sample encodings */
+ unsigned int bits;
+ unsigned int bps;
+ unsigned int sig;
+ unsigned int le;
+ unsigned int msb;
+ } enc[SIO_NENC];
+ unsigned int rchan[SIO_NCHAN]; /* allowed values for rchan */
+ unsigned int pchan[SIO_NCHAN]; /* allowed values for pchan */
+ unsigned int rate[SIO_NRATE]; /* allowed rates */
+ int __pad[7]; /* for future use */
+ unsigned int nconf; /* number of elements in confs[] */
+ struct sio_conf {
+ unsigned int enc; /* mask of enc[] indexes */
+ unsigned int rchan; /* mask of chan[] indexes (rec) */
+ unsigned int pchan; /* mask of chan[] indexes (play) */
+ unsigned int rate; /* mask of rate[] indexes */
+ } confs[SIO_NCONF];
+};
+
+#define SIO_XSTRINGS { "ignore", "sync", "error" }
+
+/*
+ * controlled component of the device
+ */
+struct sioctl_node {
+ char name[SIOCTL_NAMEMAX]; /* ex. "spkr" */
+ int unit; /* optional number or -1 */
+};
+
+/*
+ * description of a control (index, value) pair
+ */
+struct sioctl_desc {
+ unsigned int addr; /* control address */
+#define SIOCTL_NONE 0 /* deleted */
+#define SIOCTL_NUM 2 /* integer in the 0..127 range */
+#define SIOCTL_SW 3 /* on/off switch (0 or 1) */
+#define SIOCTL_VEC 4 /* number, element of vector */
+#define SIOCTL_LIST 5 /* switch, element of a list */
+ unsigned int type; /* one of above */
+ char func[SIOCTL_NAMEMAX]; /* function name, ex. "level" */
+ char group[SIOCTL_NAMEMAX]; /* group this control belongs to */
+ struct sioctl_node node0; /* affected node */
+ struct sioctl_node node1; /* dito for SIOCTL_{VEC,LIST} */
+ unsigned int maxval; /* max value for SIOCTL_{NUM,VEC} */
+ int __pad[3];
+};
+
+/*
+ * mode bitmap
+ */
+#define SIO_PLAY 1
+#define SIO_REC 2
+#define MIO_OUT 4
+#define MIO_IN 8
+#define SIOCTL_READ 0x100
+#define SIOCTL_WRITE 0x200
+
+/*
+ * default bytes per sample for the given bits per sample
+ */
+#define SIO_BPS(bits) (((bits) <= 8) ? 1 : (((bits) <= 16) ? 2 : 4))
+
+/*
+ * default value of "sio_par->le" flag
+ */
+#if BYTE_ORDER == LITTLE_ENDIAN
+#define SIO_LE_NATIVE 1
+#else
+#define SIO_LE_NATIVE 0
+#endif
+
+/*
+ * maximum value of volume, eg. for sio_setvol()
+ */
+#define SIO_MAXVOL 127
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct pollfd;
+
+void sio_initpar(struct sio_par *);
+struct sio_hdl *sio_open(const char *, unsigned int, int);
+void sio_close(struct sio_hdl *);
+int sio_setpar(struct sio_hdl *, struct sio_par *);
+int sio_getpar(struct sio_hdl *, struct sio_par *);
+int sio_getcap(struct sio_hdl *, struct sio_cap *);
+void sio_onmove(struct sio_hdl *, void (*)(void *, int), void *);
+size_t sio_write(struct sio_hdl *, const void *, size_t);
+size_t sio_read(struct sio_hdl *, void *, size_t);
+int sio_start(struct sio_hdl *);
+int sio_stop(struct sio_hdl *);
+int sio_nfds(struct sio_hdl *);
+int sio_pollfd(struct sio_hdl *, struct pollfd *, int);
+int sio_revents(struct sio_hdl *, struct pollfd *);
+int sio_eof(struct sio_hdl *);
+int sio_setvol(struct sio_hdl *, unsigned int);
+int sio_onvol(struct sio_hdl *, void (*)(void *, unsigned int), void *);
+
+struct mio_hdl *mio_open(const char *, unsigned int, int);
+void mio_close(struct mio_hdl *);
+size_t mio_write(struct mio_hdl *, const void *, size_t);
+size_t mio_read(struct mio_hdl *, void *, size_t);
+int mio_nfds(struct mio_hdl *);
+int mio_pollfd(struct mio_hdl *, struct pollfd *, int);
+int mio_revents(struct mio_hdl *, struct pollfd *);
+int mio_eof(struct mio_hdl *);
+
+struct sioctl_hdl *sioctl_open(const char *, unsigned int, int);
+void sioctl_close(struct sioctl_hdl *);
+int sioctl_ondesc(struct sioctl_hdl *,
+ void (*)(void *, struct sioctl_desc *, int), void *);
+int sioctl_onval(struct sioctl_hdl *,
+ void (*)(void *, unsigned int, unsigned int), void *);
+int sioctl_setval(struct sioctl_hdl *, unsigned int, unsigned int);
+int sioctl_nfds(struct sioctl_hdl *);
+int sioctl_pollfd(struct sioctl_hdl *, struct pollfd *, int);
+int sioctl_revents(struct sioctl_hdl *, struct pollfd *);
+int sioctl_eof(struct sioctl_hdl *);
+
+int mio_rmidi_getfd(const char *, unsigned int, int);
+struct mio_hdl *mio_rmidi_fdopen(int, unsigned int, int);
+int sio_sun_getfd(const char *, unsigned int, int);
+struct sio_hdl *sio_sun_fdopen(int, unsigned int, int);
+int sioctl_sun_getfd(const char *, unsigned int, int);
+struct sioctl_hdl *sioctl_sun_fdopen(int, unsigned int, int);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* !defined(SNDIO_H) */
diff --git a/include/spawn.h b/include/spawn.h
new file mode 100644
index 0000000..374a18b
--- /dev/null
+++ b/include/spawn.h
@@ -0,0 +1,103 @@
+/* $OpenBSD: spawn.h,v 1.3 2015/05/20 22:50:07 millert Exp $ */
+/*-
+ * Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org>
+ * 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: src/include/spawn.h,v 1.3.2.1.6.1 2010/12/21 17:09:25 kensmith Exp $
+ */
+
+#ifndef _SPAWN_H_
+#define _SPAWN_H_
+
+#include <sys/types.h>
+#include <sys/signal.h>
+
+struct sched_param;
+
+typedef struct __posix_spawnattr *posix_spawnattr_t;
+typedef struct __posix_spawn_file_actions *posix_spawn_file_actions_t;
+
+#define POSIX_SPAWN_RESETIDS 0x01
+#define POSIX_SPAWN_SETPGROUP 0x02
+#define POSIX_SPAWN_SETSCHEDPARAM 0x04
+#define POSIX_SPAWN_SETSCHEDULER 0x08
+#define POSIX_SPAWN_SETSIGDEF 0x10
+#define POSIX_SPAWN_SETSIGMASK 0x20
+
+__BEGIN_DECLS
+/*
+ * Spawn routines
+ *
+ * XXX both arrays should be __restrict, but this does not work when GCC
+ * is invoked with -std=c99.
+ */
+int posix_spawn(pid_t *__restrict, const char *__restrict,
+ const posix_spawn_file_actions_t *, const posix_spawnattr_t *__restrict,
+ char *const [], char *const []);
+int posix_spawnp(pid_t *__restrict, const char *__restrict,
+ const posix_spawn_file_actions_t *, const posix_spawnattr_t *__restrict,
+ char *const [], char *const []);
+
+/*
+ * File descriptor actions
+ */
+int posix_spawn_file_actions_init(posix_spawn_file_actions_t *);
+int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *);
+
+int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *__restrict,
+ int, const char *__restrict, int, mode_t);
+int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *, int, int);
+int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *, int);
+
+/*
+ * Spawn attributes
+ */
+int posix_spawnattr_init(posix_spawnattr_t *);
+int posix_spawnattr_destroy(posix_spawnattr_t *);
+
+int posix_spawnattr_getflags(const posix_spawnattr_t *__restrict,
+ short *__restrict);
+int posix_spawnattr_getpgroup(const posix_spawnattr_t *__restrict,
+ pid_t *__restrict);
+int posix_spawnattr_getschedparam(const posix_spawnattr_t *__restrict,
+ struct sched_param *__restrict);
+int posix_spawnattr_getschedpolicy(const posix_spawnattr_t *__restrict,
+ int *__restrict);
+int posix_spawnattr_getsigdefault(const posix_spawnattr_t *__restrict,
+ sigset_t *__restrict);
+int posix_spawnattr_getsigmask(const posix_spawnattr_t *__restrict,
+ sigset_t *__restrict);
+
+int posix_spawnattr_setflags(posix_spawnattr_t *, short);
+int posix_spawnattr_setpgroup(posix_spawnattr_t *, pid_t);
+int posix_spawnattr_setschedparam(posix_spawnattr_t *__restrict,
+ const struct sched_param *__restrict);
+int posix_spawnattr_setschedpolicy(posix_spawnattr_t *, int);
+int posix_spawnattr_setsigdefault(posix_spawnattr_t *__restrict,
+ const sigset_t *__restrict);
+int posix_spawnattr_setsigmask(posix_spawnattr_t *__restrict,
+ const sigset_t *__restrict);
+__END_DECLS
+
+#endif /* !_SPAWN_H_ */
diff --git a/include/stdbool.h b/include/stdbool.h
new file mode 100644
index 0000000..077c12a
--- /dev/null
+++ b/include/stdbool.h
@@ -0,0 +1,45 @@
+/* $OpenBSD: stdbool.h,v 1.7 2015/09/04 23:47:09 daniel Exp $ */
+
+/*
+ * Written by Marc Espie, September 25, 1999
+ * Public domain.
+ */
+
+#ifndef _STDBOOL_H_
+#define _STDBOOL_H_
+
+#ifndef __cplusplus
+
+#if defined(__GNUC__) || \
+ (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901)
+/* Support for C99: type _Bool is already built-in. */
+#define false 0
+#define true 1
+
+#else
+/* `_Bool' type must promote to `int' or `unsigned int'. */
+typedef enum {
+ false = 0,
+ true = 1
+} _Bool;
+
+/* And those constants must also be available as macros. */
+#define false false
+#define true true
+
+#endif
+
+/* User visible type `bool' is provided as a macro which may be redefined */
+#define bool _Bool
+
+#else /* __cplusplus */
+#define _Bool bool
+#define bool bool
+#define false false
+#define true true
+#endif /* __cplusplus */
+
+/* Inform that everything is fine */
+#define __bool_true_false_are_defined 1
+
+#endif /* _STDBOOL_H_ */
diff --git a/include/stddef.h b/include/stddef.h
new file mode 100644
index 0000000..391fbc2
--- /dev/null
+++ b/include/stddef.h
@@ -0,0 +1,84 @@
+/* $OpenBSD: stddef.h,v 1.14 2017/01/06 14:36:50 kettenis Exp $ */
+/* $NetBSD: stddef.h,v 1.4 1994/10/26 00:56:26 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1990 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.
+ *
+ * @(#)stddef.h 5.5 (Berkeley) 4/3/91
+ */
+
+#ifndef _STDDEF_H_
+#define _STDDEF_H_
+
+#include <sys/cdefs.h>
+#include <sys/_null.h>
+#include <sys/_types.h>
+
+#ifndef _PTRDIFF_T_DEFINED_
+#define _PTRDIFF_T_DEFINED_
+typedef __ptrdiff_t ptrdiff_t;
+#endif
+
+#ifndef _SIZE_T_DEFINED_
+#define _SIZE_T_DEFINED_
+typedef __size_t size_t;
+#endif
+
+/* in C++, wchar_t is a built-in type */
+#if !defined(_WCHAR_T_DEFINED_) && !defined(__cplusplus)
+#define _WCHAR_T_DEFINED_
+typedef __wchar_t wchar_t;
+#endif
+
+#ifndef _WINT_T_DEFINED_
+#define _WINT_T_DEFINED_
+typedef __wint_t wint_t;
+#endif
+
+#ifndef _MBSTATE_T_DEFINED_
+#define _MBSTATE_T_DEFINED_
+typedef __mbstate_t mbstate_t;
+#endif
+
+#if __GNUC_PREREQ__(4, 0)
+#define offsetof(type, member) __builtin_offsetof(type, member)
+#else
+#define offsetof(type, member) ((size_t)(&((type *)0)->member))
+#endif
+
+#if __ISO_C_VISIBLE >= 2011 || __cplusplus >= 201103
+#ifndef __CLANG_MAX_ALIGN_T_DEFINED
+#define __CLANG_MAX_ALIGN_T_DEFINED
+typedef struct {
+ long long __max_align_ll __aligned(__alignof__(long long));
+ long double __max_align_ld __aligned(__alignof__(long double));
+} max_align_t;
+#endif
+#endif
+
+#endif /* _STDDEF_H_ */
diff --git a/include/stdio.h b/include/stdio.h
new file mode 100644
index 0000000..3f39a21
--- /dev/null
+++ b/include/stdio.h
@@ -0,0 +1,435 @@
+/* $OpenBSD: stdio.h,v 1.53 2016/09/09 18:12:37 millert Exp $ */
+/* $NetBSD: stdio.h,v 1.18 1996/04/25 18:29:21 jtc Exp $ */
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * 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.
+ *
+ * @(#)stdio.h 5.17 (Berkeley) 6/3/91
+ */
+
+#ifndef _STDIO_H_
+#define _STDIO_H_
+
+#include <sys/cdefs.h>
+#include <sys/_null.h>
+#include <sys/_types.h>
+
+#if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE
+#include <sys/types.h> /* XXX should be removed */
+#endif
+
+#ifndef _SIZE_T_DEFINED_
+#define _SIZE_T_DEFINED_
+typedef __size_t size_t;
+#endif
+
+#ifndef _OFF_T_DEFINED_
+#define _OFF_T_DEFINED_
+typedef __off_t off_t;
+#endif
+
+#define _FSTDIO /* Define for new stdio with functions. */
+
+typedef off_t fpos_t; /* stdio file position type */
+
+/*
+ * NB: to fit things in six character monocase externals, the stdio
+ * code uses the prefix `__s' for stdio objects, typically followed
+ * by a three-character attempt at a mnemonic.
+ */
+
+/* stdio buffers */
+struct __sbuf {
+ unsigned char *_base;
+ int _size;
+};
+
+/*
+ * stdio state variables.
+ *
+ * The following always hold:
+ *
+ * if (_flags&(__SLBF|__SWR)) == (__SLBF|__SWR),
+ * _lbfsize is -_bf._size, else _lbfsize is 0
+ * if _flags&__SRD, _w is 0
+ * if _flags&__SWR, _r is 0
+ *
+ * This ensures that the getc and putc macros (or inline functions) never
+ * try to write or read from a file that is in `read' or `write' mode.
+ * (Moreover, they can, and do, automatically switch from read mode to
+ * write mode, and back, on "r+" and "w+" files.)
+ *
+ * _lbfsize is used only to make the inline line-buffered output stream
+ * code as compact as possible.
+ *
+ * _ub, _up, and _ur are used when ungetc() pushes back more characters
+ * than fit in the current _bf, or when ungetc() pushes back a character
+ * that does not match the previous one in _bf. When this happens,
+ * _ub._base becomes non-nil (i.e., a stream has ungetc() data iff
+ * _ub._base!=NULL) and _up and _ur save the current values of _p and _r.
+ */
+typedef struct __sFILE {
+ unsigned char *_p; /* current position in (some) buffer */
+ int _r; /* read space left for getc() */
+ int _w; /* write space left for putc() */
+ short _flags; /* flags, below; this FILE is free if 0 */
+ short _file; /* fileno, if Unix descriptor, else -1 */
+ struct __sbuf _bf; /* the buffer (at least 1 byte, if !NULL) */
+ int _lbfsize; /* 0 or -_bf._size, for inline putc */
+
+ /* operations */
+ void *_cookie; /* cookie passed to io functions */
+ int (*_close)(void *);
+ int (*_read)(void *, char *, int);
+ fpos_t (*_seek)(void *, fpos_t, int);
+ int (*_write)(void *, const char *, int);
+
+ /* extension data, to avoid further ABI breakage */
+ struct __sbuf _ext;
+ /* data for long sequences of ungetc() */
+ unsigned char *_up; /* saved _p when _p is doing ungetc data */
+ int _ur; /* saved _r when _r is counting ungetc data */
+
+ /* tricks to meet minimum requirements even when malloc() fails */
+ unsigned char _ubuf[3]; /* guarantee an ungetc() buffer */
+ unsigned char _nbuf[1]; /* guarantee a getc() buffer */
+
+ /* separate buffer for fgetln() when line crosses buffer boundary */
+ struct __sbuf _lb; /* buffer for fgetln() */
+
+ /* Unix stdio files get aligned to block boundaries on fseek() */
+ int _blksize; /* stat.st_blksize (may be != _bf._size) */
+ fpos_t _offset; /* current lseek offset */
+} FILE;
+
+__BEGIN_DECLS
+extern FILE __sF[];
+__END_DECLS
+
+#define __SLBF 0x0001 /* line buffered */
+#define __SNBF 0x0002 /* unbuffered */
+#define __SRD 0x0004 /* OK to read */
+#define __SWR 0x0008 /* OK to write */
+ /* RD and WR are never simultaneously asserted */
+#define __SRW 0x0010 /* open for reading & writing */
+#define __SEOF 0x0020 /* found EOF */
+#define __SERR 0x0040 /* found error */
+#define __SMBF 0x0080 /* _buf is from malloc */
+#define __SAPP 0x0100 /* fdopen()ed in append mode */
+#define __SSTR 0x0200 /* this is an sprintf/snprintf string */
+#define __SOPT 0x0400 /* do fseek() optimisation */
+#define __SNPT 0x0800 /* do not do fseek() optimisation */
+#define __SOFF 0x1000 /* set iff _offset is in fact correct */
+#define __SMOD 0x2000 /* true => fgetln modified _p text */
+#define __SALC 0x4000 /* allocate string space dynamically */
+#define __SIGN 0x8000 /* ignore this file in _fwalk */
+
+/*
+ * The following three definitions are for ANSI C, which took them
+ * from System V, which brilliantly took internal interface macros and
+ * made them official arguments to setvbuf(), without renaming them.
+ * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
+ *
+ * Although numbered as their counterparts above, the implementation
+ * does not rely on this.
+ */
+#define _IOFBF 0 /* setvbuf should set fully buffered */
+#define _IOLBF 1 /* setvbuf should set line buffered */
+#define _IONBF 2 /* setvbuf should set unbuffered */
+
+#define BUFSIZ 1024 /* size of buffer used by setbuf */
+
+#define EOF (-1)
+
+/*
+ * FOPEN_MAX is a minimum maximum, and should be the number of descriptors
+ * that the kernel can provide without allocation of a resource that can
+ * fail without the process sleeping. Do not use this for anything.
+ */
+#define FOPEN_MAX 20 /* must be <= OPEN_MAX <sys/syslimits.h> */
+#define FILENAME_MAX 1024 /* must be <= PATH_MAX <sys/syslimits.h> */
+
+/* System V/ANSI C; this is the wrong way to do this, do *not* use these. */
+#if __BSD_VISIBLE || __XPG_VISIBLE
+#define P_tmpdir "/tmp/"
+#endif
+#define L_tmpnam 1024 /* XXX must be == PATH_MAX */
+#define TMP_MAX 0x7fffffff /* more, but don't overflow int */
+
+#ifndef SEEK_SET
+#define SEEK_SET 0 /* set file offset to offset */
+#endif
+#ifndef SEEK_CUR
+#define SEEK_CUR 1 /* set file offset to current plus offset */
+#endif
+#ifndef SEEK_END
+#define SEEK_END 2 /* set file offset to EOF plus offset */
+#endif
+
+#define stdin (&__sF[0])
+#define stdout (&__sF[1])
+#define stderr (&__sF[2])
+
+/*
+ * Functions defined in ANSI C standard.
+ */
+__BEGIN_DECLS
+void clearerr(FILE *);
+#if __POSIX_VISIBLE >= 200809
+int dprintf(int, const char * __restrict, ...);
+#endif
+int fclose(FILE *);
+int feof(FILE *);
+int ferror(FILE *);
+int fflush(FILE *);
+int fgetc(FILE *);
+int fgetpos(FILE *, fpos_t *);
+char *fgets(char *, int, FILE *)
+ __attribute__((__bounded__ (__string__,1,2)));
+FILE *fopen(const char *, const char *);
+int fprintf(FILE *, const char *, ...);
+int fputc(int, FILE *);
+int fputs(const char *, FILE *);
+size_t fread(void *, size_t, size_t, FILE *)
+ __attribute__((__bounded__ (__size__,1,3,2)));
+FILE *freopen(const char *, const char *, FILE *);
+int fscanf(FILE *, const char *, ...);
+int fseek(FILE *, long, int);
+int fseeko(FILE *, off_t, int);
+int fsetpos(FILE *, const fpos_t *);
+long ftell(FILE *);
+off_t ftello(FILE *);
+size_t fwrite(const void *, size_t, size_t, FILE *)
+ __attribute__((__bounded__ (__size__,1,3,2)));
+int getc(FILE *);
+int getchar(void);
+#if __POSIX_VISIBLE >= 200809
+ssize_t getdelim(char ** __restrict, size_t * __restrict, int,
+ FILE * __restrict);
+ssize_t getline(char ** __restrict, size_t * __restrict,
+ FILE * __restrict);
+#endif
+#if __BSD_VISIBLE && !defined(__SYS_ERRLIST)
+#define __SYS_ERRLIST
+
+extern int sys_nerr; /* perror(3) external variables */
+extern char *sys_errlist[];
+#endif
+void perror(const char *);
+int printf(const char *, ...);
+int putc(int, FILE *);
+int putchar(int);
+int puts(const char *);
+int remove(const char *);
+int rename(const char *, const char *);
+#if __POSIX_VISIBLE >= 200809
+int renameat(int, const char *, int, const char *);
+#endif
+void rewind(FILE *);
+int scanf(const char *, ...);
+void setbuf(FILE *, char *);
+int setvbuf(FILE *, char *, int, size_t);
+int sprintf(char *, const char *, ...);
+int sscanf(const char *, const char *, ...);
+FILE *tmpfile(void);
+char *tmpnam(char *);
+int ungetc(int, FILE *);
+int vfprintf(FILE *, const char *, __va_list);
+int vprintf(const char *, __va_list);
+int vsprintf(char *, const char *, __va_list);
+#if __POSIX_VISIBLE >= 200809
+int vdprintf(int, const char * __restrict, __va_list);
+#endif
+
+#if __ISO_C_VISIBLE >= 1999 || __XPG_VISIBLE >= 500 || __BSD_VISIBLE
+int snprintf(char *, size_t, const char *, ...)
+ __attribute__((__format__ (printf, 3, 4)))
+ __attribute__((__nonnull__ (3)))
+ __attribute__((__bounded__ (__string__,1,2)));
+int vsnprintf(char *, size_t, const char *, __va_list)
+ __attribute__((__format__ (printf, 3, 0)))
+ __attribute__((__nonnull__ (3)))
+ __attribute__((__bounded__(__string__,1,2)));
+#endif /* __ISO_C_VISIBLE >= 1999 || __XPG_VISIBLE >= 500 || __BSD_VISIBLE */
+
+#if __ISO_C_VISIBLE >= 1999 || __BSD_VISIBLE
+int vfscanf(FILE *, const char *, __va_list)
+ __attribute__((__format__ (scanf, 2, 0)))
+ __attribute__((__nonnull__ (2)));
+int vscanf(const char *, __va_list)
+ __attribute__((__format__ (scanf, 1, 0)))
+ __attribute__((__nonnull__ (1)));
+int vsscanf(const char *, const char *, __va_list)
+ __attribute__((__format__ (scanf, 2, 0)))
+ __attribute__((__nonnull__ (2)));
+#endif /* __ISO_C_VISIBLE >= 1999 || __BSD_VISIBLE */
+
+__END_DECLS
+
+
+/*
+ * Functions defined in POSIX 1003.1.
+ */
+#if __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE
+#define L_ctermid 1024 /* size for ctermid(); PATH_MAX */
+
+__BEGIN_DECLS
+char *ctermid(char *);
+FILE *fdopen(int, const char *);
+int fileno(FILE *);
+
+#if __POSIX_VISIBLE >= 199209
+int pclose(FILE *);
+FILE *popen(const char *, const char *);
+#endif
+
+#if __POSIX_VISIBLE >= 199506
+void flockfile(FILE *);
+int ftrylockfile(FILE *);
+void funlockfile(FILE *);
+
+/*
+ * These are normally used through macros as defined below, but POSIX
+ * requires functions as well.
+ */
+int getc_unlocked(FILE *);
+int getchar_unlocked(void);
+int putc_unlocked(int, FILE *);
+int putchar_unlocked(int);
+#endif /* __POSIX_VISIBLE >= 199506 */
+
+#if __POSIX_VISIBLE >= 200809
+FILE *fmemopen(void *, size_t, const char *);
+FILE *open_memstream(char **, size_t *);
+#endif /* __POSIX_VISIBLE >= 200809 */
+
+#if __XPG_VISIBLE
+char *tempnam(const char *, const char *);
+#endif
+__END_DECLS
+
+#endif /* __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE */
+
+/*
+ * Routines that are purely local.
+ */
+#if __BSD_VISIBLE
+__BEGIN_DECLS
+int asprintf(char **, const char *, ...)
+ __attribute__((__format__ (printf, 2, 3)))
+ __attribute__((__nonnull__ (2)));
+char *fgetln(FILE *, size_t *);
+int fpurge(FILE *);
+int getw(FILE *);
+int putw(int, FILE *);
+void setbuffer(FILE *, char *, int);
+int setlinebuf(FILE *);
+int vasprintf(char **, const char *, __va_list)
+ __attribute__((__format__ (printf, 2, 0)))
+ __attribute__((__nonnull__ (2)));
+__END_DECLS
+
+/*
+ * Stdio function-access interface.
+ */
+__BEGIN_DECLS
+FILE *funopen(const void *,
+ int (*)(void *, char *, int),
+ int (*)(void *, const char *, int),
+ fpos_t (*)(void *, fpos_t, int),
+ int (*)(void *));
+__END_DECLS
+#define fropen(cookie, fn) funopen(cookie, fn, 0, 0, 0)
+#define fwopen(cookie, fn) funopen(cookie, 0, fn, 0, 0)
+#endif /* __BSD_VISIBLE */
+
+/*
+ * Functions internal to the implementation.
+ */
+__BEGIN_DECLS
+int __srget(FILE *);
+int __swbuf(int, FILE *);
+__END_DECLS
+
+/*
+ * The __sfoo macros are here so that we can
+ * define function versions in the C library.
+ */
+#define __sgetc(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
+static __inline int __sputc(int _c, FILE *_p) {
+ if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
+ return (*_p->_p++ = _c);
+ else
+ return (__swbuf(_c, _p));
+}
+
+#define __sfeof(p) (((p)->_flags & __SEOF) != 0)
+#define __sferror(p) (((p)->_flags & __SERR) != 0)
+#define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF)))
+#define __sfileno(p) ((p)->_file)
+
+extern int __isthreaded;
+
+#define feof(p) (!__isthreaded ? __sfeof(p) : (feof)(p))
+#define ferror(p) (!__isthreaded ? __sferror(p) : (ferror)(p))
+#define clearerr(p) (!__isthreaded ? __sclearerr(p) : (clearerr)(p))
+
+#if __POSIX_VISIBLE
+#define fileno(p) (!__isthreaded ? __sfileno(p) : (fileno)(p))
+#endif
+
+#define getc(fp) (!__isthreaded ? __sgetc(fp) : (getc)(fp))
+
+#if __BSD_VISIBLE
+/*
+ * The macro implementations of putc and putc_unlocked are not
+ * fully POSIX compliant; they do not set errno on failure
+ */
+#define putc(x, fp) (!__isthreaded ? __sputc(x, fp) : (putc)(x, fp))
+#endif /* __BSD_VISIBLE */
+
+#if __POSIX_VISIBLE >= 199506
+#define getc_unlocked(fp) __sgetc(fp)
+/*
+ * The macro implementations of putc and putc_unlocked are not
+ * fully POSIX compliant; they do not set errno on failure
+ */
+#if __BSD_VISIBLE
+#define putc_unlocked(x, fp) __sputc(x, fp)
+#endif /* __BSD_VISIBLE */
+#endif /* __POSIX_VISIBLE >= 199506 */
+
+#define getchar() getc(stdin)
+#define putchar(x) putc(x, stdout)
+#define getchar_unlocked() getc_unlocked(stdin)
+#define putchar_unlocked(c) putc_unlocked(c, stdout)
+
+#endif /* _STDIO_H_ */
diff --git a/include/stdlib.h b/include/stdlib.h
new file mode 100644
index 0000000..652bba4
--- /dev/null
+++ b/include/stdlib.h
@@ -0,0 +1,12 @@
+#include_next <stdlib.h>
+#include <stdint.h>
+void freezero(void *, size_t);
+void *reallocarray(void *, size_t, size_t);
+void *recallocarray(void *, size_t, size_t, size_t);
+long long strtonum(const char *, long long, long long, const char **);
+uint32_t arc4random(void);
+uint32_t arc4random_uniform(uint32_t);
+void arc4random_buf(void *, size_t);
+void setprogname(const char *);
+const char *getprogname(void);
+extern char *__progname;
diff --git a/include/string.h b/include/string.h
new file mode 100644
index 0000000..9cf9ac9
--- /dev/null
+++ b/include/string.h
@@ -0,0 +1,5 @@
+#include_next <string.h>
+char *strcasestr(const char *, const char *);
+void strmode(int, char *);
+int timingsafe_memcmp(const void *, const void *, size_t);
+int timingsafe_bcmp(const void *, const void *, size_t);
diff --git a/include/strings.h b/include/strings.h
new file mode 100644
index 0000000..e72fb77
--- /dev/null
+++ b/include/strings.h
@@ -0,0 +1,83 @@
+/* $OpenBSD: strings.h,v 1.6 2017/09/10 21:50:36 schwarze Exp $ */
+
+/*-
+ * Copyright (c) 1990 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.
+ *
+ * @(#)strings.h 5.8 (Berkeley) 5/15/90
+ */
+
+#ifndef _STRINGS_H_
+#define _STRINGS_H_
+
+#include <sys/cdefs.h>
+#include <machine/_types.h>
+
+/*
+ * POSIX mandates that certain string functions not present in ISO C
+ * be prototyped in strings.h.
+ */
+
+#ifndef _SIZE_T_DEFINED_
+#define _SIZE_T_DEFINED_
+typedef __size_t size_t;
+#endif
+
+#if __POSIX_VISIBLE >= 200809
+#ifndef _LOCALE_T_DEFINED_
+#define _LOCALE_T_DEFINED_
+typedef void *locale_t;
+#endif
+#endif
+
+__BEGIN_DECLS
+#if __BSD_VISIBLE || (__XPG_VISIBLE >= 420 && __POSIX_VISIBLE <= 200112)
+/*
+ * The following functions were removed from IEEE Std 1003.1-2008
+ */
+int bcmp(const void *, const void *, size_t);
+void bcopy(const void *, void *, size_t)
+ __attribute__ ((__bounded__(__buffer__,1,3)))
+ __attribute__ ((__bounded__(__buffer__,2,3)));
+void bzero(void *, size_t)
+ __attribute__ ((__bounded__(__buffer__,1,2)));
+char *index(const char *, int);
+char *rindex(const char *, int);
+#endif
+
+#if __XPG_VISIBLE >= 420
+int ffs(int);
+int strcasecmp(const char *, const char *);
+int strncasecmp(const char *, const char *, size_t);
+#endif
+#if __POSIX_VISIBLE >= 200809
+int strcasecmp_l(const char *, const char *, locale_t);
+int strncasecmp_l(const char *, const char *, size_t, locale_t);
+#endif
+__END_DECLS
+
+#endif /* _STRINGS_H_ */
diff --git a/include/sys/cdefs.h b/include/sys/cdefs.h
new file mode 100644
index 0000000..70258b8
--- /dev/null
+++ b/include/sys/cdefs.h
@@ -0,0 +1,5 @@
+/* only needed for C++ */
+#define __BEGIN_DECLS
+#define __END_DECLS
+
+#define __dead __attribute__((__noreturn__))
diff --git a/include/sys/param.h b/include/sys/param.h
new file mode 100644
index 0000000..3167713
--- /dev/null
+++ b/include/sys/param.h
@@ -0,0 +1,3 @@
+#include_next <sys/param.h>
+#define ALIGNBYTES (sizeof(uintptr_t) - 1)
+#define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) &~ ALIGNBYTES)
diff --git a/include/sys/time.h b/include/sys/time.h
new file mode 100644
index 0000000..f4f151f
--- /dev/null
+++ b/include/sys/time.h
@@ -0,0 +1,14 @@
+#include_next <sys/time.h>
+#define timespeccmp(tsp, usp, cmp) \
+ (((tsp)->tv_sec == (usp)->tv_sec) ? \
+ ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \
+ ((tsp)->tv_sec cmp (usp)->tv_sec))
+#define timespecsub(tsp, usp, vsp) \
+ do { \
+ (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
+ (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
+ if ((vsp)->tv_nsec < 0) { \
+ (vsp)->tv_sec--; \
+ (vsp)->tv_nsec += 1000000000L; \
+ } \
+ } while (0)
diff --git a/include/sysexits.h b/include/sysexits.h
new file mode 100644
index 0000000..e244836
--- /dev/null
+++ b/include/sysexits.h
@@ -0,0 +1,119 @@
+/* $OpenBSD: sysexits.h,v 1.5 2003/06/02 19:34:12 millert Exp $ */
+/* $NetBSD: sysexits.h,v 1.4 1994/10/26 00:56:33 cgd Exp $ */
+
+/*
+ * Copyright (c) 1987 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.
+ *
+ * @(#)sysexits.h 4.8 (Berkeley) 4/3/91
+ */
+
+#ifndef _SYSEXITS_H_
+#define _SYSEXITS_H_
+
+/*
+ * SYSEXITS.H -- Exit status codes for system programs.
+ *
+ * This include file attempts to categorize possible error
+ * exit statuses for system programs, notably delivermail
+ * and the Berkeley network.
+ *
+ * Error numbers begin at EX__BASE to reduce the possibility of
+ * clashing with other exit statuses that random programs may
+ * already return. The meaning of the codes is approximately
+ * as follows:
+ *
+ * EX_USAGE -- The command was used incorrectly, e.g., with
+ * the wrong number of arguments, a bad flag, a bad
+ * syntax in a parameter, or whatever.
+ * EX_DATAERR -- The input data was incorrect in some way.
+ * This should only be used for user's data & not
+ * system files.
+ * EX_NOINPUT -- An input file (not a system file) did not
+ * exist or was not readable. This could also include
+ * errors like "No message" to a mailer (if it cared
+ * to catch it).
+ * EX_NOUSER -- The user specified did not exist. This might
+ * be used for mail addresses or remote logins.
+ * EX_NOHOST -- The host specified did not exist. This is used
+ * in mail addresses or network requests.
+ * EX_UNAVAILABLE -- A service is unavailable. This can occur
+ * if a support program or file does not exist. This
+ * can also be used as a catchall message when something
+ * you wanted to do doesn't work, but you don't know
+ * why.
+ * EX_SOFTWARE -- An internal software error has been detected.
+ * This should be limited to non-operating system related
+ * errors as possible.
+ * EX_OSERR -- An operating system error has been detected.
+ * This is intended to be used for such things as "cannot
+ * fork", "cannot create pipe", or the like. It includes
+ * things like getuid returning a user that does not
+ * exist in the passwd file.
+ * EX_OSFILE -- Some system file (e.g., /etc/passwd, /var/run/utmp,
+ * etc.) does not exist, cannot be opened, or has some
+ * sort of error (e.g., syntax error).
+ * EX_CANTCREAT -- A (user specified) output file cannot be
+ * created.
+ * EX_IOERR -- An error occurred while doing I/O on some file.
+ * EX_TEMPFAIL -- temporary failure, indicating something that
+ * is not really an error. In sendmail, this means
+ * that a mailer (e.g.) could not create a connection,
+ * and the request should be reattempted later.
+ * EX_PROTOCOL -- the remote system returned something that
+ * was "not possible" during a protocol exchange.
+ * EX_NOPERM -- You did not have sufficient permission to
+ * perform the operation. This is not intended for
+ * file system problems, which should use EX_NOINPUT or
+ * EX_CANTCREAT, but rather for higher level permissions.
+ * EX_CONFIG -- Something was found in an unconfigured or
+ * misconfigured state.
+ */
+
+#define EX_OK 0 /* successful termination */
+
+#define EX__BASE 64 /* base value for error messages */
+
+#define EX_USAGE 64 /* command line usage error */
+#define EX_DATAERR 65 /* data format error */
+#define EX_NOINPUT 66 /* cannot open input */
+#define EX_NOUSER 67 /* addressee unknown */
+#define EX_NOHOST 68 /* host name unknown */
+#define EX_UNAVAILABLE 69 /* service unavailable */
+#define EX_SOFTWARE 70 /* internal software error */
+#define EX_OSERR 71 /* system error (e.g., can't fork) */
+#define EX_OSFILE 72 /* critical OS file missing */
+#define EX_CANTCREAT 73 /* can't create (user) output file */
+#define EX_IOERR 74 /* input/output error */
+#define EX_TEMPFAIL 75 /* temp failure; user is invited to retry */
+#define EX_PROTOCOL 76 /* remote error in protocol */
+#define EX_NOPERM 77 /* permission denied */
+#define EX_CONFIG 78 /* configuration error */
+
+#define EX__MAX 78 /* maximum listed value */
+
+#endif /* !_SYSEXITS_H_ */
diff --git a/include/tar.h b/include/tar.h
new file mode 100644
index 0000000..17f5124
--- /dev/null
+++ b/include/tar.h
@@ -0,0 +1,66 @@
+/* $OpenBSD: tar.h,v 1.3 2008/06/26 05:42:04 ray Exp $ */
+/* $NetBSD: tar.h,v 1.1 1996/02/05 22:34:13 jtc Exp $ */
+
+/*-
+ * Copyright (c) 1996 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by J.T. Conklin.
+ *
+ * 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 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 _TAR_H_
+#define _TAR_H_
+
+#define TMAGIC "ustar"
+#define TMAGLEN 6
+#define TVERSION "00"
+#define TVERSLEN 2
+
+/* Typeflag field definitions */
+#define REGTYPE '0'
+#define AREGTYPE '\0'
+#define LNKTYPE '1'
+#define SYMTYPE '2'
+#define CHRTYPE '3'
+#define BLKTYPE '4'
+#define DIRTYPE '5'
+#define FIFOTYPE '6'
+#define CONTTYPE '7'
+
+/* Mode field bit definitions */
+#define TSUID 04000
+#define TSGID 02000
+#define TSVTX 01000
+#define TUREAD 00400
+#define TUWRITE 00200
+#define TUEXEC 00100
+#define TGREAD 00040
+#define TGWRITE 00020
+#define TGEXEC 00010
+#define TOREAD 00004
+#define TOWRITE 00002
+#define TOEXEC 00001
+
+#endif /* _TAR_H_ */
diff --git a/include/tgmath.h b/include/tgmath.h
new file mode 100644
index 0000000..46fade4
--- /dev/null
+++ b/include/tgmath.h
@@ -0,0 +1,169 @@
+/* $OpenBSD: tgmath.h,v 1.1 2011/07/08 19:28:06 martynas Exp $ */
+
+/*-
+ * Copyright (c) 2004 Stefan Farfeleder.
+ * 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: src/include/tgmath.h,v 1.5 2007/02/02 18:30:23 schweikh Exp $
+ */
+
+#ifndef _TGMATH_H_
+#define _TGMATH_H_
+
+#include <complex.h>
+#include <math.h>
+
+/*
+ * This implementation of <tgmath.h> requires two implementation-dependent
+ * macros to be defined:
+ * __tg_impl_simple(x, y, z, fn, fnf, fnl, ...)
+ * Invokes fnl() if the corresponding real type of x, y or z is long
+ * double, fn() if it is double or any has an integer type, and fnf()
+ * otherwise.
+ * __tg_impl_full(x, y, z, fn, fnf, fnl, cfn, cfnf, cfnl, ...)
+ * Invokes [c]fnl() if the corresponding real type of x, y or z is long
+ * double, [c]fn() if it is double or any has an integer type, and
+ * [c]fnf() otherwise. The function with the 'c' prefix is called if
+ * any of x, y or z is a complex number.
+ * Both macros call the chosen function with all additional arguments passed
+ * to them, as given by __VA_ARGS__.
+ *
+ * Note that these macros cannot be implemented with C's ?: operator,
+ * because the return type of the whole expression would incorrectly be long
+ * double complex regardless of the argument types.
+ */
+
+#if __GNUC_PREREQ__(3, 1)
+#define __tg_type(e, t) __builtin_types_compatible_p(__typeof__(e), t)
+#define __tg_type3(e1, e2, e3, t) \
+ (__tg_type(e1, t) || __tg_type(e2, t) || __tg_type(e3, t))
+#define __tg_type_corr(e1, e2, e3, t) \
+ (__tg_type3(e1, e2, e3, t) || __tg_type3(e1, e2, e3, t _Complex))
+#define __tg_integer(e1, e2, e3) \
+ (((__typeof__(e1))1.5 == 1) || ((__typeof__(e2))1.5 == 1) || \
+ ((__typeof__(e3))1.5 == 1))
+#define __tg_is_complex(e1, e2, e3) \
+ (__tg_type3(e1, e2, e3, float _Complex) || \
+ __tg_type3(e1, e2, e3, double _Complex) || \
+ __tg_type3(e1, e2, e3, long double _Complex) || \
+ __tg_type3(e1, e2, e3, __typeof__(_Complex_I)))
+
+#define __tg_impl_simple(x, y, z, fn, fnf, fnl, ...) \
+ __builtin_choose_expr(__tg_type_corr(x, y, z, long double), \
+ fnl(__VA_ARGS__), __builtin_choose_expr( \
+ __tg_type_corr(x, y, z, double) || __tg_integer(x, y, z),\
+ fn(__VA_ARGS__), fnf(__VA_ARGS__)))
+
+#define __tg_impl_full(x, y, z, fn, fnf, fnl, cfn, cfnf, cfnl, ...) \
+ __builtin_choose_expr(__tg_is_complex(x, y, z), \
+ __tg_impl_simple(x, y, z, cfn, cfnf, cfnl, __VA_ARGS__), \
+ __tg_impl_simple(x, y, z, fn, fnf, fnl, __VA_ARGS__))
+
+#else /* __GNUC__ */
+#error "<tgmath.h> not implemented for this compiler"
+#endif /* !__GNUC__ */
+
+/* Macros to save lots of repetition below */
+#define __tg_simple(x, fn) \
+ __tg_impl_simple(x, x, x, fn, fn##f, fn##l, x)
+#define __tg_simple2(x, y, fn) \
+ __tg_impl_simple(x, x, y, fn, fn##f, fn##l, x, y)
+#define __tg_simplev(x, fn, ...) \
+ __tg_impl_simple(x, x, x, fn, fn##f, fn##l, __VA_ARGS__)
+#define __tg_full(x, fn) \
+ __tg_impl_full(x, x, x, fn, fn##f, fn##l, c##fn, c##fn##f, c##fn##l, x)
+
+/* 7.22#4 -- These macros expand to real or complex functions, depending on
+ * the type of their arguments. */
+#define acos(x) __tg_full(x, acos)
+#define asin(x) __tg_full(x, asin)
+#define atan(x) __tg_full(x, atan)
+#define acosh(x) __tg_full(x, acosh)
+#define asinh(x) __tg_full(x, asinh)
+#define atanh(x) __tg_full(x, atanh)
+#define cos(x) __tg_full(x, cos)
+#define sin(x) __tg_full(x, sin)
+#define tan(x) __tg_full(x, tan)
+#define cosh(x) __tg_full(x, cosh)
+#define sinh(x) __tg_full(x, sinh)
+#define tanh(x) __tg_full(x, tanh)
+#define exp(x) __tg_full(x, exp)
+#define log(x) __tg_full(x, log)
+#define pow(x, y) __tg_impl_full(x, x, y, pow, powf, powl, \
+ cpow, cpowf, cpowl, x, y)
+#define sqrt(x) __tg_full(x, sqrt)
+
+/* "The corresponding type-generic macro for fabs and cabs is fabs." */
+#define fabs(x) __tg_impl_full(x, x, x, fabs, fabsf, fabsl, \
+ cabs, cabsf, cabsl, x)
+
+/* 7.22#5 -- These macros are only defined for arguments with real type. */
+#define atan2(x, y) __tg_simple2(x, y, atan2)
+#define cbrt(x) __tg_simple(x, cbrt)
+#define ceil(x) __tg_simple(x, ceil)
+#define copysign(x, y) __tg_simple2(x, y, copysign)
+#define erf(x) __tg_simple(x, erf)
+#define erfc(x) __tg_simple(x, erfc)
+#define exp2(x) __tg_simple(x, exp2)
+#define expm1(x) __tg_simple(x, expm1)
+#define fdim(x, y) __tg_simple2(x, y, fdim)
+#define floor(x) __tg_simple(x, floor)
+#define fma(x, y, z) __tg_impl_simple(x, y, z, fma, fmaf, fmal, x, y, z)
+#define fmax(x, y) __tg_simple2(x, y, fmax)
+#define fmin(x, y) __tg_simple2(x, y, fmin)
+#define fmod(x, y) __tg_simple2(x, y, fmod)
+#define frexp(x, y) __tg_simplev(x, frexp, x, y)
+#define hypot(x, y) __tg_simple2(x, y, hypot)
+#define ilogb(x) __tg_simple(x, ilogb)
+#define ldexp(x, y) __tg_simplev(x, ldexp, x, y)
+#define lgamma(x) __tg_simple(x, lgamma)
+#define llrint(x) __tg_simple(x, llrint)
+#define llround(x) __tg_simple(x, llround)
+#define log10(x) __tg_simple(x, log10)
+#define log1p(x) __tg_simple(x, log1p)
+#define log2(x) __tg_simple(x, log2)
+#define logb(x) __tg_simple(x, logb)
+#define lrint(x) __tg_simple(x, lrint)
+#define lround(x) __tg_simple(x, lround)
+#define nearbyint(x) __tg_simple(x, nearbyint)
+#define nextafter(x, y) __tg_simple2(x, y, nextafter)
+#define nexttoward(x, y) __tg_simplev(x, nexttoward, x, y)
+#define remainder(x, y) __tg_simple2(x, y, remainder)
+#define remquo(x, y, z) __tg_impl_simple(x, x, y, remquo, remquof, \
+ remquol, x, y, z)
+#define rint(x) __tg_simple(x, rint)
+#define round(x) __tg_simple(x, round)
+#define scalbn(x, y) __tg_simplev(x, scalbn, x, y)
+#define scalbln(x, y) __tg_simplev(x, scalbln, x, y)
+#define tgamma(x) __tg_simple(x, tgamma)
+#define trunc(x) __tg_simple(x, trunc)
+
+/* 7.22#6 -- These macros always expand to complex functions. */
+#define carg(x) __tg_simple(x, carg)
+#define cimag(x) __tg_simple(x, cimag)
+#define conj(x) __tg_simple(x, conj)
+#define cproj(x) __tg_simple(x, cproj)
+#define creal(x) __tg_simple(x, creal)
+
+#endif /* !_TGMATH_H_ */
diff --git a/include/tib.h b/include/tib.h
new file mode 100644
index 0000000..8d9216f
--- /dev/null
+++ b/include/tib.h
@@ -0,0 +1,258 @@
+/* $OpenBSD: tib.h,v 1.7 2019/05/10 13:29:21 guenther Exp $ */
+/*
+ * Copyright (c) 2011,2014 Philip Guenther <guenther@openbsd.org>
+ *
+ * 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.
+ */
+
+/*
+ * Thread Information Block (TIB) and Thread Local Storage (TLS) handling
+ * (the TCB, Thread Control Block, is part of the TIB)
+ */
+
+#ifndef _TIB_H_
+#define _TIB_H_
+
+#include <sys/types.h>
+#include <machine/tcb.h>
+
+#include <stddef.h>
+
+
+/*
+ * This header defines struct tib and at least eight macros:
+ * TLS_VARIANT
+ * Either 1 or 2 (Actually defined by <machine/tcb.h>)
+ *
+ * TCB_SET(tcb)
+ * Set the TCB pointer for this thread to 'tcb'
+ *
+ * TCB_GET()
+ * Return the TCB pointer for this thread
+ *
+ * TCB_TO_TIB(tcb)
+ * Given a TCB pointer, return the matching TIB pointer
+ *
+ * TIB_TO_TCB(tib)
+ * Given a TIB pointer, return the matching TCB pointer
+ *
+ * TIB_INIT(tib, dtv, thread)
+ * Initializes a TIB for a new thread, using the supplied
+ * values for its dtv and thread pointers
+ *
+ * TIB_GET()
+ * Short-hand for TCB_TO_TIB(TCB_GET())
+ *
+ * TIB_EXTRA_ALIGN
+ * On TLS varaint 2 archs, what alignment is sufficient
+ * for the extra space that will be used for struct pthread?
+ *
+ * The following functions are provided by either ld.so (dynamic) or
+ * libc (static) for allocating and freeing a common memory block that
+ * will hold both the TIB and the pthread structure:
+ * _dl_allocate_tib(sizeof(struct pthread))
+ * Allocates a combined TIB and pthread memory region.
+ * The argument is the amount of space to reserve
+ * for the pthread structure. Returns a pointer to
+ * the TIB inside the allocated block.
+ *
+ * _dl_free_tib(tib, sizeof(struct pthread))
+ * Frees a TIB and pthread block previously allocated
+ * with _dl_allocate_tib(). Must be passed the return
+ * value of that previous call.
+ */
+
+/*
+ * Regarding <machine/tcb.h>:
+ * - it must define the TLS_VARIANT macro
+ * - it may define TCB_OFFSET if the TCB address in the kernel and/or
+ * register is offset from the actual TCB address. TCB_OFFSET > 0
+ * means the kernel/register points to *after* the real data.
+ * - if there's a faster way to get or set the TCB pointer for the thread
+ * than the __{get,set}_tcb() syscalls, it should define either or both
+ * the TCB_{GET,SET} macros to do so.
+ */
+
+
+/* All archs but mips64 have fast TCB_GET() and don't need caching */
+#ifndef __mips64__
+# define TCB_HAVE_MD_GET 1
+#endif
+#ifdef TCB_SET
+# define TCB_HAVE_MD_SET 1
+#else
+# define TCB_SET(tcb) __set_tcb(tcb)
+#endif
+#ifndef TCB_OFFSET
+# define TCB_OFFSET 0
+#endif
+
+/*
+ * tib_cantcancel values is non-zero if the thread should skip all
+ * cancellation processing
+ */
+#define CANCEL_DISABLED 1
+#define CANCEL_DYING 2
+
+/*
+ * tib_cancel_point is non-zero if we're in a cancel point; its modified
+ * by the cancel point code and read by the cancellation signal handler
+ */
+#define CANCEL_POINT 1
+#define CANCEL_POINT_DELAYED 2
+
+
+#if TLS_VARIANT == 1
+/*
+ * ABI specifies that the static TLS data starts two words after the
+ * (notional) thread pointer, with the first of those two words being
+ * the TLS dtv pointer. The other (second) word is reserved for the
+ * implementation, so we place the pointer to the thread structure there,
+ * but we place our actual thread bits before the TCB, at negative offsets
+ * from the TCB pointer. Ergo, memory is laid out, low to high, as:
+ *
+ * [pthread structure]
+ * TIB {
+ * ...cancelation and other int-sized info...
+ * int errno
+ * void *locale
+ * TCB (- TCB_OFFSET) {
+ * void *dtv
+ * struct pthread *thread
+ * }
+ * }
+ * static TLS data
+ */
+
+struct tib {
+ void *tib_atexit;
+ int tib_thread_flags; /* internal to libpthread */
+ pid_t tib_tid;
+ int tib_cantcancel;
+ int tib_cancel_point;
+ int tib_canceled;
+ int tib_errno;
+ void *tib_locale;
+ void *tib_dtv; /* internal to the runtime linker */
+ void *tib_thread;
+};
+
+
+#elif TLS_VARIANT == 2
+/*
+ * ABI specifies that the static TLS data occupies the memory before
+ * the TCB pointer, at negative offsets, and that on i386 and amd64
+ * the word the TCB points to contains a pointer to itself. So,
+ * we place errno and our thread bits after that. Memory is laid
+ * out, low to high, as:
+ * static TLS data
+ * TIB {
+ * TCB (- TCB_OFFSET) {
+ * self pointer [i386/amd64 only]
+ * void *dtv
+ * }
+ * struct pthread *thread
+ * void *locale
+ * int errno
+ * ...cancelation and other int-sized info...
+ * }
+ * [pthread structure]
+ */
+
+struct tib {
+#if defined(__i386) || defined(__amd64)
+ struct tib *__tib_self;
+# define __tib_tcb __tib_self
+#endif
+ void *tib_dtv; /* internal to the runtime linker */
+ void *tib_thread;
+ void *tib_locale;
+ int tib_errno;
+ int tib_canceled;
+ int tib_cancel_point;
+ int tib_cantcancel;
+ pid_t tib_tid;
+ int tib_thread_flags; /* internal to libpthread */
+ void *tib_atexit;
+};
+
+#if defined(__i386) || defined(__amd64)
+# define _TIB_PREP(tib) \
+ ((void)((tib)->__tib_self = (tib)))
+#endif
+
+#define TIB_EXTRA_ALIGN sizeof(void *)
+
+#else
+# error "unknown TLS variant"
+#endif
+
+/* nothing to do by default */
+#ifndef _TIB_PREP
+# define _TIB_PREP(tib) ((void)0)
+#endif
+
+#define TIB_INIT(tib, dtv, thread) do { \
+ (tib)->tib_thread = (thread); \
+ (tib)->tib_atexit = NULL; \
+ (tib)->tib_locale = NULL; \
+ (tib)->tib_cantcancel = 0; \
+ (tib)->tib_cancel_point = 0; \
+ (tib)->tib_canceled = 0; \
+ (tib)->tib_dtv = (dtv); \
+ (tib)->tib_errno = 0; \
+ _TIB_PREP(tib); \
+ } while (0)
+
+#ifndef __tib_tcb
+# define __tib_tcb tib_dtv
+#endif
+#define _TIBO_TCB (offsetof(struct tib, __tib_tcb) + TCB_OFFSET)
+
+#define TCB_TO_TIB(tcb) ((struct tib *)((char *)(tcb) - _TIBO_TCB))
+#define TIB_TO_TCB(tib) ((char *)(tib) + _TIBO_TCB)
+#define TIB_GET() TCB_TO_TIB(TCB_GET())
+
+
+__BEGIN_DECLS
+struct dl_info;
+struct dl_phdr_info;
+struct dl_cb_0 {
+ void *(*dl_allocate_tib)(size_t);
+ void (*dl_free_tib)(void *, size_t);
+ void (*dl_clean_boot)(void);
+ void *(*dlopen)(const char *, int);
+ int (*dlclose)(void *);
+ void *(*dlsym)(void *, const char *);
+ int (*dladdr)(const void *, struct dl_info *);
+ int (*dlctl)(void *, int, void *);
+ char *(*dlerror)(void);
+ int (*dl_iterate_phdr)(int (*)(struct dl_phdr_info *,
+ size_t, void *), void *);
+};
+
+#define DL_CB_CUR 0
+typedef struct dl_cb_0 dl_cb;
+
+/* type of function passed to init functions that returns a dl_cb */
+typedef const void *dl_cb_cb(int _version);
+
+void *_dl_allocate_tib(size_t _extra) __dso_public;
+void _dl_free_tib(void *_tib, size_t _extra) __dso_public;
+
+/* The actual syscalls */
+void *__get_tcb(void);
+void __set_tcb(void *_tcb);
+__END_DECLS
+
+#endif /* _TIB_H_ */
diff --git a/include/time.h b/include/time.h
new file mode 100644
index 0000000..51bee8f
--- /dev/null
+++ b/include/time.h
@@ -0,0 +1,191 @@
+/* $OpenBSD: time.h,v 1.31 2018/10/30 16:28:42 guenther Exp $ */
+/* $NetBSD: time.h,v 1.9 1994/10/26 00:56:35 cgd Exp $ */
+
+/*
+ * Copyright (c) 1989 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)time.h 5.12 (Berkeley) 3/9/91
+ */
+
+#ifndef _TIME_H_
+#define _TIME_H_
+
+#include <sys/cdefs.h>
+#include <sys/_null.h>
+#include <sys/_types.h>
+
+#ifndef _CLOCK_T_DEFINED_
+#define _CLOCK_T_DEFINED_
+typedef __clock_t clock_t;
+#endif
+
+#ifndef _TIME_T_DEFINED_
+#define _TIME_T_DEFINED_
+typedef __time_t time_t;
+#endif
+
+#ifndef _SIZE_T_DEFINED_
+#define _SIZE_T_DEFINED_
+typedef __size_t size_t;
+#endif
+
+#if __POSIX_VISIBLE > 0 && __POSIX_VISIBLE < 200112 || __BSD_VISIBLE
+/*
+ * Frequency of the clock ticks reported by times(). Deprecated - use
+ * sysconf(_SC_CLK_TCK) instead. (Removed in 1003.1-2001.)
+ */
+#define CLK_TCK 100
+#endif
+
+#define CLOCKS_PER_SEC 100 /* frequency of ticks reported by clock(). */
+
+#if __POSIX_VISIBLE >= 199309 || __ISO_C_VISIBLE >= 2011
+#ifndef _TIMESPEC_DECLARED
+#define _TIMESPEC_DECLARED
+struct timespec {
+ time_t tv_sec; /* seconds */
+ long tv_nsec; /* and nanoseconds */
+};
+#endif
+#endif
+
+#if __POSIX_VISIBLE >= 199309
+#include <sys/_time.h>
+
+#ifndef _CLOCKID_T_DEFINED_
+#define _CLOCKID_T_DEFINED_
+typedef __clockid_t clockid_t;
+#endif
+
+#ifndef _TIMER_T_DEFINED_
+#define _TIMER_T_DEFINED_
+typedef __timer_t timer_t;
+#endif
+#endif
+
+#if __POSIX_VISIBLE >= 200112
+#ifndef _PID_T_DEFINED_
+#define _PID_T_DEFINED_
+typedef __pid_t pid_t;
+#endif
+#endif
+
+#if __POSIX_VISIBLE >= 200809
+#ifndef _LOCALE_T_DEFINED_
+#define _LOCALE_T_DEFINED_
+typedef void *locale_t;
+#endif
+#endif
+
+struct tm {
+ int tm_sec; /* seconds after the minute [0-60] */
+ int tm_min; /* minutes after the hour [0-59] */
+ int tm_hour; /* hours since midnight [0-23] */
+ int tm_mday; /* day of the month [1-31] */
+ int tm_mon; /* months since January [0-11] */
+ int tm_year; /* years since 1900 */
+ int tm_wday; /* days since Sunday [0-6] */
+ int tm_yday; /* days since January 1 [0-365] */
+ int tm_isdst; /* Daylight Saving Time flag */
+ long tm_gmtoff; /* offset from UTC in seconds */
+ char *tm_zone; /* timezone abbreviation */
+};
+
+__BEGIN_DECLS
+char *asctime(const struct tm *);
+clock_t clock(void);
+char *ctime(const time_t *);
+double difftime(time_t, time_t);
+struct tm *gmtime(const time_t *);
+struct tm *localtime(const time_t *);
+time_t mktime(struct tm *);
+size_t strftime(char *__restrict, size_t, const char *__restrict,
+ const struct tm *__restrict)
+ __attribute__ ((__bounded__(__string__,1,2)));
+time_t time(time_t *);
+
+#if __XPG_VISIBLE >= 300
+extern int daylight;
+extern long timezone;
+#endif
+#if __XPG_VISIBLE >= 400
+char *strptime(const char *__restrict, const char *__restrict,
+ struct tm *__restrict);
+#endif
+
+#if __POSIX_VISIBLE >= 199506
+char *asctime_r(const struct tm *__restrict, char *__restrict)
+ __attribute__ ((__bounded__(__minbytes__,2,26)));
+char *ctime_r(const time_t *, char *)
+ __attribute__ ((__bounded__(__minbytes__,2,26)));
+struct tm *gmtime_r(const time_t *__restrict, struct tm *__restrict);
+struct tm *localtime_r(const time_t *__restrict, struct tm *__restrict);
+#endif
+
+#if __POSIX_VISIBLE
+extern char *tzname[2];
+void tzset(void);
+#endif
+
+#if __POSIX_VISIBLE >= 199309
+int clock_getres(clockid_t, struct timespec *);
+int clock_gettime(clockid_t, struct timespec *);
+int clock_settime(clockid_t, const struct timespec *);
+int nanosleep(const struct timespec *, struct timespec *);
+#endif
+
+#if __POSIX_VISIBLE >= 200112
+int clock_getcpuclockid(pid_t, clockid_t *);
+#endif
+
+#if __POSIX_VISIBLE >= 200809
+size_t strftime_l(char *__restrict, size_t, const char *__restrict,
+ const struct tm *__restrict, locale_t)
+ __attribute__ ((__bounded__(__string__,1,2)));
+#endif
+
+#if __ISO_C_VISIBLE >= 2011
+#define TIME_UTC 1 /* time elapsed since epoch */
+int timespec_get(struct timespec *_ts, int _base);
+#endif
+
+#if __BSD_VISIBLE
+void tzsetwall(void);
+time_t timelocal(struct tm *);
+time_t timegm(struct tm *);
+time_t timeoff(struct tm *, const long);
+#endif
+__END_DECLS
+
+#endif /* !_TIME_H_ */
diff --git a/include/ttyent.h b/include/ttyent.h
new file mode 100644
index 0000000..406d466
--- /dev/null
+++ b/include/ttyent.h
@@ -0,0 +1,73 @@
+/* $OpenBSD: ttyent.h,v 1.4 2003/06/02 19:34:12 millert Exp $ */
+/* $NetBSD: ttyent.h,v 1.5 1994/10/26 00:56:36 cgd Exp $ */
+
+/*
+ * Copyright (c) 1989 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.
+ *
+ * @(#)ttyent.h 5.7 (Berkeley) 4/3/91
+ */
+
+#ifndef _TTYENT_H_
+#define _TTYENT_H_
+
+#define _PATH_TTYS "/etc/ttys"
+
+#define _TTYS_OFF "off"
+#define _TTYS_ON "on"
+#define _TTYS_SECURE "secure"
+#define _TTYS_WINDOW "window"
+#define _TTYS_LOCAL "local"
+#define _TTYS_RTSCTS "rtscts"
+#define _TTYS_SOFTCAR "softcar"
+#define _TTYS_MDMBUF "mdmbuf"
+
+struct ttyent {
+ char *ty_name; /* terminal device name */
+ char *ty_getty; /* command to execute, usually getty */
+ char *ty_type; /* terminal type for termcap */
+#define TTY_ON 0x01 /* enable logins (start ty_getty program) */
+#define TTY_SECURE 0x02 /* allow uid of 0 to login */
+#define TTY_LOCAL 0x04 /* set 'CLOCAL' on open (dev. specific) */
+#define TTY_RTSCTS 0x08 /* set 'CRTSCTS' on open (dev. specific) */
+#define TTY_SOFTCAR 0x10 /* ignore hardware carrier (dev. spec.) */
+#define TTY_MDMBUF 0x20 /* set 'MDMBUF' on open (dev. specific) */
+ int ty_status; /* status flags */
+ char *ty_window; /* command to start up window manager */
+ char *ty_comment; /* comment field */
+};
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+struct ttyent *getttyent(void);
+struct ttyent *getttynam(const char *);
+int setttyent(void);
+int endttyent(void);
+__END_DECLS
+
+#endif /* !_TTYENT_H_ */
diff --git a/include/unistd.h b/include/unistd.h
new file mode 100644
index 0000000..a715077
--- /dev/null
+++ b/include/unistd.h
@@ -0,0 +1,3 @@
+#include_next <unistd.h>
+#define pledge(request, paths) 0 /* linux doesn't have pledge */
+#define unveil(path, permissions) 0 /* linux doesn't have unveil */
diff --git a/include/utime.h b/include/utime.h
new file mode 100644
index 0000000..f617865
--- /dev/null
+++ b/include/utime.h
@@ -0,0 +1,55 @@
+/* $OpenBSD: utime.h,v 1.7 2013/04/02 05:16:14 guenther Exp $ */
+/* $NetBSD: utime.h,v 1.3 1994/10/26 00:56:39 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1990 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.
+ *
+ * @(#)utime.h 5.4 (Berkeley) 4/3/91
+ */
+
+#ifndef _UTIME_H_
+#define _UTIME_H_
+
+#include <sys/cdefs.h>
+#include <sys/_types.h>
+
+#ifndef _TIME_T_DEFINED_
+#define _TIME_T_DEFINED_
+typedef __time_t time_t;
+#endif
+
+struct utimbuf {
+ time_t actime; /* Access time */
+ time_t modtime; /* Modification time */
+};
+
+__BEGIN_DECLS
+int utime(const char *, const struct utimbuf *);
+__END_DECLS
+
+#endif /* !_UTIME_H_ */
diff --git a/include/utmp.h b/include/utmp.h
new file mode 100644
index 0000000..b946a2d
--- /dev/null
+++ b/include/utmp.h
@@ -0,0 +1,69 @@
+/* $OpenBSD: utmp.h,v 1.6 2014/01/08 06:50:57 guenther Exp $ */
+/* $NetBSD: utmp.h,v 1.6 1994/10/26 00:56:40 cgd Exp $ */
+
+/*
+ * Copyright (c) 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)utmp.h 8.2 (Berkeley) 1/21/94
+ */
+
+#ifndef _UTMP_H_
+#define _UTMP_H_
+
+#define _PATH_UTMP "/var/run/utmp"
+#define _PATH_WTMP "/var/log/wtmp"
+#define _PATH_LASTLOG "/var/log/lastlog"
+
+#define UT_NAMESIZE 32
+#define UT_LINESIZE 8
+#define UT_HOSTSIZE 256
+
+/*
+ * Note that these are *not* C strings and thus are not
+ * guaranteed to be NUL-terminated.
+ */
+
+struct lastlog {
+ time_t ll_time;
+ char ll_line[UT_LINESIZE];
+ char ll_host[UT_HOSTSIZE];
+};
+
+struct utmp {
+ char ut_line[UT_LINESIZE];
+ char ut_name[UT_NAMESIZE];
+ char ut_host[UT_HOSTSIZE];
+ time_t ut_time;
+};
+
+#endif /* !_UTMP_H_ */
diff --git a/include/uuid.h b/include/uuid.h
new file mode 100644
index 0000000..3e10b9e
--- /dev/null
+++ b/include/uuid.h
@@ -0,0 +1,69 @@
+/* $OpenBSD: uuid.h,v 1.1 2014/08/31 09:36:36 miod Exp $ */
+/* $NetBSD: uuid.h,v 1.2 2008/04/23 07:52:32 plunky Exp $ */
+
+/*
+ * Copyright (c) 2002 Marcel Moolenaar
+ * Copyright (c) 2002 Hiten Mahesh Pandya
+ * 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: src/include/uuid.h,v 1.2 2002/11/05 10:55:16 jmallett Exp $
+ */
+
+#ifndef _UUID_H_
+#define _UUID_H_
+
+#include <sys/types.h>
+#include <sys/uuid.h>
+
+/* Status codes returned by the functions. */
+#define uuid_s_ok 0
+#define uuid_s_bad_version 1
+#define uuid_s_invalid_string_uuid 2
+#define uuid_s_no_memory 3
+
+/* Length of a printed UUID. */
+#define UUID_BUF_LEN _UUID_BUF_LEN
+
+/* Length of a UUID. */
+#define UUID_STR_LEN 36
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+int32_t uuid_compare(const uuid_t *, const uuid_t *, uint32_t *);
+void uuid_create(uuid_t *, uint32_t *);
+void uuid_create_nil(uuid_t *, uint32_t *);
+int32_t uuid_equal(const uuid_t *, const uuid_t *, uint32_t *);
+void uuid_from_string(const char *, uuid_t *, uint32_t *);
+uint16_t uuid_hash(const uuid_t *, uint32_t *);
+int32_t uuid_is_nil(const uuid_t *, uint32_t *);
+void uuid_to_string(const uuid_t *, char **, uint32_t *);
+
+void uuid_enc_le(void *, const uuid_t *);
+void uuid_dec_le(const void *, uuid_t *);
+void uuid_enc_be(void *, const uuid_t *);
+void uuid_dec_be(const void *, uuid_t *);
+__END_DECLS
+
+#endif /* _UUID_H_ */
diff --git a/include/vis.h b/include/vis.h
new file mode 100644
index 0000000..8804417
--- /dev/null
+++ b/include/vis.h
@@ -0,0 +1,93 @@
+/* $OpenBSD: vis.h,v 1.15 2015/07/20 01:52:27 millert Exp $ */
+/* $NetBSD: vis.h,v 1.4 1994/10/26 00:56:41 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1990 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.
+ *
+ * @(#)vis.h 5.9 (Berkeley) 4/3/91
+ */
+
+#ifndef _VIS_H_
+#define _VIS_H_
+
+/*
+ * to select alternate encoding format
+ */
+#define VIS_OCTAL 0x01 /* use octal \ddd format */
+#define VIS_CSTYLE 0x02 /* use \[nrft0..] where appropriate */
+
+/*
+ * to alter set of characters encoded (default is to encode all
+ * non-graphic except space, tab, and newline).
+ */
+#define VIS_SP 0x04 /* also encode space */
+#define VIS_TAB 0x08 /* also encode tab */
+#define VIS_NL 0x10 /* also encode newline */
+#define VIS_WHITE (VIS_SP | VIS_TAB | VIS_NL)
+#define VIS_SAFE 0x20 /* only encode "unsafe" characters */
+#define VIS_DQ 0x200 /* backslash-escape double quotes */
+#define VIS_ALL 0x400 /* encode all characters */
+
+/*
+ * other
+ */
+#define VIS_NOSLASH 0x40 /* inhibit printing '\' */
+#define VIS_GLOB 0x100 /* encode glob(3) magics and '#' */
+
+/*
+ * unvis return codes
+ */
+#define UNVIS_VALID 1 /* character valid */
+#define UNVIS_VALIDPUSH 2 /* character valid, push back passed char */
+#define UNVIS_NOCHAR 3 /* valid sequence, no character produced */
+#define UNVIS_SYNBAD -1 /* unrecognized escape sequence */
+#define UNVIS_ERROR -2 /* decoder in unknown state (unrecoverable) */
+
+/*
+ * unvis flags
+ */
+#define UNVIS_END 1 /* no more characters */
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+char *vis(char *, int, int, int);
+int strvis(char *, const char *, int);
+int stravis(char **, const char *, int);
+int strnvis(char *, const char *, size_t, int)
+ __attribute__ ((__bounded__(__string__,1,3)));
+int strvisx(char *, const char *, size_t, int)
+ __attribute__ ((__bounded__(__string__,1,3)));
+int strunvis(char *, const char *);
+int unvis(char *, char, int *, int);
+ssize_t strnunvis(char *, const char *, size_t)
+ __attribute__ ((__bounded__(__string__,1,3)));
+
+__END_DECLS
+
+#endif /* !_VIS_H_ */
diff --git a/include/wchar.h b/include/wchar.h
new file mode 100644
index 0000000..309f812
--- /dev/null
+++ b/include/wchar.h
@@ -0,0 +1,239 @@
+/* $OpenBSD: wchar.h,v 1.31 2017/09/05 03:16:13 schwarze Exp $ */
+/* $NetBSD: wchar.h,v 1.16 2003/03/07 07:11:35 tshiozak Exp $ */
+
+/*-
+ * Copyright (c)1999 Citrus Project,
+ * 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.
+ */
+
+/*-
+ * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Julian Coleman.
+ *
+ * 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.
+ */
+
+#ifndef _WCHAR_H_
+#define _WCHAR_H_
+
+#include <sys/cdefs.h>
+#include <sys/_null.h>
+#include <sys/_types.h>
+
+#include <stdio.h> /* for FILE* */
+
+#if !defined(_WCHAR_T_DEFINED_) && !defined(__cplusplus)
+#define _WCHAR_T_DEFINED_
+typedef __wchar_t wchar_t;
+#endif
+
+#ifndef _MBSTATE_T_DEFINED_
+#define _MBSTATE_T_DEFINED_
+typedef __mbstate_t mbstate_t;
+#endif
+
+#ifndef _WINT_T_DEFINED_
+#define _WINT_T_DEFINED_
+typedef __wint_t wint_t;
+#endif
+
+#ifndef _SIZE_T_DEFINED_
+#define _SIZE_T_DEFINED_
+typedef __size_t size_t;
+#endif
+
+#ifndef WEOF
+#define WEOF ((wint_t)-1)
+#endif
+
+#ifndef WCHAR_MIN
+#define WCHAR_MIN (-0x7fffffff - 1)
+#endif
+#ifndef WCHAR_MAX
+#define WCHAR_MAX 0x7fffffff
+#endif
+
+#if __POSIX_VISIBLE >= 200809
+#ifndef _LOCALE_T_DEFINED_
+#define _LOCALE_T_DEFINED_
+typedef void *locale_t;
+#endif
+#endif
+
+__BEGIN_DECLS
+wint_t btowc(int);
+size_t mbrlen(const char * __restrict, size_t, mbstate_t * __restrict);
+size_t mbrtowc(wchar_t * __restrict, const char * __restrict, size_t,
+ mbstate_t * __restrict);
+int mbsinit(const mbstate_t *);
+size_t mbsrtowcs(wchar_t * __restrict, const char ** __restrict, size_t,
+ mbstate_t * __restrict)
+ __attribute__ ((__bounded__(__wcstring__,1,3)));
+size_t wcrtomb(char * __restrict, wchar_t, mbstate_t * __restrict);
+wchar_t *wcscat(wchar_t * __restrict, const wchar_t * __restrict);
+wchar_t *wcschr(const wchar_t *, wchar_t);
+int wcscmp(const wchar_t *, const wchar_t *);
+int wcscoll(const wchar_t *, const wchar_t *);
+wchar_t *wcscpy(wchar_t * __restrict, const wchar_t * __restrict);
+size_t wcscspn(const wchar_t *, const wchar_t *);
+size_t wcslen(const wchar_t *);
+wchar_t *wcsncat(wchar_t * __restrict, const wchar_t * __restrict,
+ size_t)
+ __attribute__ ((__bounded__(__wcstring__,1,3)));
+int wcsncmp(const wchar_t *, const wchar_t *, size_t);
+wchar_t *wcsncpy(wchar_t * __restrict , const wchar_t * __restrict,
+ size_t)
+ __attribute__ ((__bounded__(__wcstring__,1,3)));
+wchar_t *wcspbrk(const wchar_t *, const wchar_t *);
+wchar_t *wcsrchr(const wchar_t *, wchar_t);
+size_t wcsrtombs(char * __restrict, const wchar_t ** __restrict, size_t,
+ mbstate_t * __restrict)
+ __attribute__ ((__bounded__(__wcstring__,1,3)));
+size_t wcsspn(const wchar_t *, const wchar_t *);
+wchar_t *wcsstr(const wchar_t *, const wchar_t *);
+wchar_t *wcstok(wchar_t * __restrict, const wchar_t * __restrict,
+ wchar_t ** __restrict);
+size_t wcsxfrm(wchar_t *, const wchar_t *, size_t);
+wchar_t *wcswcs(const wchar_t *, const wchar_t *);
+wchar_t *wmemchr(const wchar_t *, wchar_t, size_t);
+int wmemcmp(const wchar_t *, const wchar_t *, size_t);
+wchar_t *wmemcpy(wchar_t * __restrict, const wchar_t * __restrict,
+ size_t)
+ __attribute__ ((__bounded__(__wcstring__,1,3)))
+ __attribute__ ((__bounded__(__wcstring__,2,3)));
+wchar_t *wmemmove(wchar_t *, const wchar_t *, size_t)
+ __attribute__ ((__bounded__(__wcstring__,1,3)))
+ __attribute__ ((__bounded__(__wcstring__,2,3)));
+wchar_t *wmemset(wchar_t *, wchar_t, size_t)
+ __attribute__ ((__bounded__(__wcstring__,1,3)));
+
+int wcswidth(const wchar_t *, size_t);
+int wctob(wint_t);
+int wcwidth(wchar_t);
+
+double wcstod(const wchar_t * __restrict, wchar_t ** __restrict);
+long int wcstol(const wchar_t * __restrict, wchar_t ** __restrict, int base);
+unsigned long int wcstoul(const wchar_t * __restrict, wchar_t ** __restrict,
+ int base);
+
+#if __POSIX_VISIBLE >= 200809
+FILE *open_wmemstream(wchar_t **, size_t *);
+
+int wcscoll_l(const wchar_t *, const wchar_t *, locale_t);
+wchar_t *wcsdup(const wchar_t *);
+int wcscasecmp(const wchar_t *, const wchar_t *);
+int wcscasecmp_l(const wchar_t *, const wchar_t *, locale_t);
+int wcsncasecmp(const wchar_t *, const wchar_t *, size_t);
+int wcsncasecmp_l(const wchar_t *, const wchar_t *, size_t, locale_t);
+size_t wcsxfrm_l(wchar_t *, const wchar_t *, size_t, locale_t);
+
+size_t mbsnrtowcs(wchar_t * __restrict, const char ** __restrict, size_t,
+ size_t, mbstate_t * __restrict)
+ __attribute__ ((__bounded__(__wcstring__,1,4)));
+size_t wcsnrtombs(char * __restrict, const wchar_t ** __restrict, size_t,
+ size_t, mbstate_t * __restrict)
+ __attribute__ ((__bounded__(__wcstring__,1,4)));
+#endif
+
+#if __ISO_C_VISIBLE >= 1999
+float wcstof(const wchar_t * __restrict, wchar_t ** __restrict);
+long double wcstold(const wchar_t * __restrict, wchar_t ** __restrict);
+
+struct tm;
+size_t wcsftime(wchar_t * __restrict, size_t, const wchar_t *__restrict,
+ const struct tm *__restrict);
+#endif
+
+#if !defined(__STRICT_ANSI__) || __ISO_C_VISIBLE >= 1999
+long long int wcstoll(const wchar_t * __restrict,
+ wchar_t ** __restrict, int base);
+unsigned long long int wcstoull(const wchar_t * __restrict,
+ wchar_t ** __restrict, int base);
+#endif
+
+wint_t ungetwc(wint_t, FILE *);
+wint_t fgetwc(FILE *);
+wchar_t *fgetws(wchar_t * __restrict, int, FILE * __restrict)
+ __attribute__ ((__bounded__(__wcstring__,1,2)));
+wint_t getwc(FILE *);
+wint_t getwchar(void);
+wint_t fputwc(wchar_t, FILE *);
+int fputws(const wchar_t * __restrict, FILE * __restrict);
+wint_t putwc(wchar_t, FILE *);
+wint_t putwchar(wchar_t);
+
+int fwide(FILE *, int);
+
+int fwprintf(FILE * __restrict, const wchar_t * __restrict, ...);
+int swprintf(wchar_t * __restrict, size_t, const wchar_t * __restrict, ...);
+int vfwprintf(FILE * __restrict, const wchar_t * __restrict, __va_list);
+int vswprintf(wchar_t * __restrict, size_t, const wchar_t * __restrict,
+ __va_list);
+int vwprintf(const wchar_t * __restrict, __va_list);
+int wprintf(const wchar_t * __restrict, ...);
+
+int fwscanf(FILE * __restrict, const wchar_t * __restrict, ...);
+int swscanf(const wchar_t * __restrict, const wchar_t * __restrict, ...);
+int vfwscanf(FILE * __restrict, const wchar_t * __restrict, __va_list);
+int vswscanf(const wchar_t * __restrict, const wchar_t * __restrict, __va_list);
+int vwscanf(const wchar_t * __restrict, __va_list);
+int wscanf(const wchar_t * __restrict, ...);
+
+#if __BSD_VISIBLE
+wchar_t *fgetwln(FILE * __restrict, size_t * __restrict);
+size_t wcslcat(wchar_t *, const wchar_t *, size_t)
+ __attribute__ ((__bounded__(__wcstring__,1,3)));
+size_t wcslcpy(wchar_t *, const wchar_t *, size_t)
+ __attribute__ ((__bounded__(__wcstring__,1,3)));
+#endif
+
+#define getwc(f) fgetwc(f)
+#define getwchar() getwc(stdin)
+#define putwc(wc, f) fputwc((wc), (f))
+#define putwchar(wc) putwc((wc), stdout)
+__END_DECLS
+
+#endif /* !_WCHAR_H_ */
diff --git a/include/wctype.h b/include/wctype.h
new file mode 100644
index 0000000..bf61d25
--- /dev/null
+++ b/include/wctype.h
@@ -0,0 +1,107 @@
+/* $OpenBSD: wctype.h,v 1.6 2017/09/05 03:16:13 schwarze Exp $ */
+/* $NetBSD: wctype.h,v 1.5 2003/03/02 22:18:11 tshiozak Exp $ */
+
+/*-
+ * Copyright (c)1999 Citrus Project,
+ * 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.
+ *
+ * citrus Id: wctype.h,v 1.4 2000/12/21 01:50:21 itojun Exp
+ */
+
+#ifndef _WCTYPE_H_
+#define _WCTYPE_H_
+
+#include <sys/cdefs.h>
+#include <machine/_types.h>
+
+#ifndef _WINT_T_DEFINED_
+#define _WINT_T_DEFINED_
+typedef __wint_t wint_t;
+#endif
+
+#ifndef _WCTRANS_T_DEFINED_
+#define _WCTRANS_T_DEFINED_
+typedef __wctrans_t wctrans_t;
+#endif
+
+#ifndef _WCTYPE_T_DEFINED_
+#define _WCTYPE_T_DEFINED_
+typedef __wctype_t wctype_t;
+#endif
+
+#ifndef WEOF
+#define WEOF ((wint_t)-1)
+#endif
+
+#if __POSIX_VISIBLE >= 200809
+#ifndef _LOCALE_T_DEFINED_
+#define _LOCALE_T_DEFINED_
+typedef void *locale_t;
+#endif
+#endif
+
+__BEGIN_DECLS
+int iswalnum(wint_t);
+int iswalpha(wint_t);
+int iswblank(wint_t);
+int iswcntrl(wint_t);
+int iswdigit(wint_t);
+int iswgraph(wint_t);
+int iswlower(wint_t);
+int iswprint(wint_t);
+int iswpunct(wint_t);
+int iswspace(wint_t);
+int iswupper(wint_t);
+int iswxdigit(wint_t);
+int iswctype(wint_t, wctype_t);
+wint_t towctrans(wint_t, wctrans_t);
+wint_t towlower(wint_t);
+wint_t towupper(wint_t);
+wctrans_t wctrans(const char *);
+wctype_t wctype(const char *);
+
+#if __POSIX_VISIBLE >= 200809
+int iswalnum_l(wint_t, locale_t);
+int iswalpha_l(wint_t, locale_t);
+int iswblank_l(wint_t, locale_t);
+int iswcntrl_l(wint_t, locale_t);
+int iswdigit_l(wint_t, locale_t);
+int iswgraph_l(wint_t, locale_t);
+int iswlower_l(wint_t, locale_t);
+int iswprint_l(wint_t, locale_t);
+int iswpunct_l(wint_t, locale_t);
+int iswspace_l(wint_t, locale_t);
+int iswupper_l(wint_t, locale_t);
+int iswxdigit_l(wint_t, locale_t);
+int iswctype_l(wint_t, wctype_t, locale_t);
+wint_t towctrans_l(wint_t, wctrans_t, locale_t);
+wint_t towlower_l(wint_t, locale_t);
+wint_t towupper_l(wint_t, locale_t);
+wctrans_t wctrans_l(const char *, locale_t);
+wctype_t wctype_l(const char *, locale_t);
+#endif
+
+__END_DECLS
+
+#endif /* _WCTYPE_H_ */
diff --git a/includedir/err.h b/includedir/err.h
new file mode 100644
index 0000000..c537811
--- /dev/null
+++ b/includedir/err.h
@@ -0,0 +1,3 @@
+#include_next <err.h>
+void warnc(int, const char *, ...) __attribute__((__format__ (printf, 2, 3)));
+void vwarnc(int, const char *, va_list) __attribute__((__format__ (printf, 2, 0)));
diff --git a/includedir/grp.h b/includedir/grp.h
new file mode 100644
index 0000000..c59cf96
--- /dev/null
+++ b/includedir/grp.h
@@ -0,0 +1,4 @@
+#include_next <grp.h>
+#define setgroupent(n) setgrent()
+const char *group_from_gid(gid_t, int);
+int gid_from_group(const char *, gid_t *);
diff --git a/includedir/machine/endian.h b/includedir/machine/endian.h
new file mode 100644
index 0000000..2dc4d83
--- /dev/null
+++ b/includedir/machine/endian.h
@@ -0,0 +1 @@
+#include <endian.h>
diff --git a/includedir/netinet/ip.h b/includedir/netinet/ip.h
new file mode 100644
index 0000000..238358c
--- /dev/null
+++ b/includedir/netinet/ip.h
@@ -0,0 +1,9 @@
+#include_next <netinet/ip.h>
+#define IPTOS_DSCP_CS0 0x00
+#define IPTOS_DSCP_CS1 0x20
+#define IPTOS_DSCP_CS2 0x40
+#define IPTOS_DSCP_CS3 0x60
+#define IPTOS_DSCP_CS4 0x80
+#define IPTOS_DSCP_CS5 0xa0
+#define IPTOS_DSCP_CS6 0xc0
+#define IPTOS_DSCP_CS7 0xe0
diff --git a/includedir/pwd.h b/includedir/pwd.h
new file mode 100644
index 0000000..c1aabba
--- /dev/null
+++ b/includedir/pwd.h
@@ -0,0 +1,4 @@
+#include_next <pwd.h>
+#define setpassent(n) setpwent()
+const char *user_from_uid(uid_t, int);
+int uid_from_user(const char *, uid_t *);
diff --git a/includedir/readpassphrase.h b/includedir/readpassphrase.h
new file mode 100644
index 0000000..cef36f0
--- /dev/null
+++ b/includedir/readpassphrase.h
@@ -0,0 +1,40 @@
+/* $OpenBSD: readpassphrase.h,v 1.5 2003/06/17 21:56:23 millert Exp $ */
+
+/*
+ * Copyright (c) 2000, 2002 Todd C. Miller <Todd.Miller@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.
+ *
+ * Sponsored in part by the Defense Advanced Research Projects
+ * Agency (DARPA) and Air Force Research Laboratory, Air Force
+ * Materiel Command, USAF, under agreement number F39502-99-1-0512.
+ */
+
+#ifndef _READPASSPHRASE_H_
+#define _READPASSPHRASE_H_
+
+#define RPP_ECHO_OFF 0x00 /* Turn off echo (default). */
+#define RPP_ECHO_ON 0x01 /* Leave echo on. */
+#define RPP_REQUIRE_TTY 0x02 /* Fail if there is no tty. */
+#define RPP_FORCELOWER 0x04 /* Force input to lower case. */
+#define RPP_FORCEUPPER 0x08 /* Force input to upper case. */
+#define RPP_SEVENBIT 0x10 /* Strip the high bit from input. */
+#define RPP_STDIN 0x20 /* Read from stdin, not /dev/tty */
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+char * readpassphrase(const char *, char *, size_t, int);
+__END_DECLS
+
+#endif /* !_READPASSPHRASE_H_ */
diff --git a/includedir/resolv.h b/includedir/resolv.h
new file mode 100644
index 0000000..23f19f9
--- /dev/null
+++ b/includedir/resolv.h
@@ -0,0 +1,3 @@
+#include_next <resolv.h>
+int b64_ntop(unsigned char const *, size_t, char *, size_t);
+int b64_pton(char const *, unsigned char *, size_t);
diff --git a/includedir/stdlib.h b/includedir/stdlib.h
new file mode 100644
index 0000000..652bba4
--- /dev/null
+++ b/includedir/stdlib.h
@@ -0,0 +1,12 @@
+#include_next <stdlib.h>
+#include <stdint.h>
+void freezero(void *, size_t);
+void *reallocarray(void *, size_t, size_t);
+void *recallocarray(void *, size_t, size_t, size_t);
+long long strtonum(const char *, long long, long long, const char **);
+uint32_t arc4random(void);
+uint32_t arc4random_uniform(uint32_t);
+void arc4random_buf(void *, size_t);
+void setprogname(const char *);
+const char *getprogname(void);
+extern char *__progname;
diff --git a/includedir/string.h b/includedir/string.h
new file mode 100644
index 0000000..9cf9ac9
--- /dev/null
+++ b/includedir/string.h
@@ -0,0 +1,5 @@
+#include_next <string.h>
+char *strcasestr(const char *, const char *);
+void strmode(int, char *);
+int timingsafe_memcmp(const void *, const void *, size_t);
+int timingsafe_bcmp(const void *, const void *, size_t);
diff --git a/includedir/sys/cdefs.h b/includedir/sys/cdefs.h
new file mode 100644
index 0000000..70258b8
--- /dev/null
+++ b/includedir/sys/cdefs.h
@@ -0,0 +1,5 @@
+/* only needed for C++ */
+#define __BEGIN_DECLS
+#define __END_DECLS
+
+#define __dead __attribute__((__noreturn__))
diff --git a/includedir/sys/compat.h b/includedir/sys/compat.h
new file mode 100644
index 0000000..af03c4f
--- /dev/null
+++ b/includedir/sys/compat.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2015, Adrián Pérez de Castro <aperez@igalia.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.
+ */
+
+#ifndef COMPAT_H
+#define COMPAT_H
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1
+#endif /* !_GNU_SOURCE */
+
+#ifndef COMPAT_BOUNDS_CHECKING
+#define __bounded__(a, b, c)
+#endif /* !COMPAT_BOUNDS_CHECKING */
+
+#ifndef __dead
+#if defined(__GNUC__) && (__GNUC__ > 3)
+#define __dead __attribute__((noreturn))
+#else
+#define __dead
+#endif
+#endif /* !__dead */
+
+#define DEF_WEAK(x)
+#define MAKE_CLONE(dst, src) typeof(dst) dst \
+ __attribute__((alias (#src)))
+
+#define u_int8_t uint8_t
+#define u_int16_t uint16_t
+#define u_int32_t uint32_t
+#define u_int64_t uint64_t
+
+#include <stdint.h>
+#include <stddef.h>
+
+extern int timingsafe_bcmp(const void *b1, const void *b2, size_t n);
+extern int pledge (const char *promises, const char *execpromises);
+extern int bcrypt_pbkdf(const char *pass, size_t passlen,
+ const uint8_t *salt, size_t saltlen,
+ uint8_t *key, size_t keylen,
+ unsigned int rounds);
+
+#ifdef BUNDLED_BZERO
+extern void explicit_bzero(void *buf, size_t len);
+#endif /* BUNDLED_BZERO */
+
+#endif /* !COMPAT_H */
diff --git a/includedir/sys/param.h b/includedir/sys/param.h
new file mode 100644
index 0000000..3167713
--- /dev/null
+++ b/includedir/sys/param.h
@@ -0,0 +1,3 @@
+#include_next <sys/param.h>
+#define ALIGNBYTES (sizeof(uintptr_t) - 1)
+#define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) &~ ALIGNBYTES)
diff --git a/includedir/sys/time.h b/includedir/sys/time.h
new file mode 100644
index 0000000..f4f151f
--- /dev/null
+++ b/includedir/sys/time.h
@@ -0,0 +1,14 @@
+#include_next <sys/time.h>
+#define timespeccmp(tsp, usp, cmp) \
+ (((tsp)->tv_sec == (usp)->tv_sec) ? \
+ ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \
+ ((tsp)->tv_sec cmp (usp)->tv_sec))
+#define timespecsub(tsp, usp, vsp) \
+ do { \
+ (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
+ (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
+ if ((vsp)->tv_nsec < 0) { \
+ (vsp)->tv_sec--; \
+ (vsp)->tv_nsec += 1000000000L; \
+ } \
+ } while (0)
diff --git a/includedir/unistd.h b/includedir/unistd.h
new file mode 100644
index 0000000..a715077
--- /dev/null
+++ b/includedir/unistd.h
@@ -0,0 +1,3 @@
+#include_next <unistd.h>
+#define pledge(request, paths) 0 /* linux doesn't have pledge */
+#define unveil(path, permissions) 0 /* linux doesn't have unveil */
diff --git a/lib/libc/crypt/arc4random.c b/lib/libc/crypt/arc4random.c
new file mode 100644
index 0000000..1a16bd3
--- /dev/null
+++ b/lib/libc/crypt/arc4random.c
@@ -0,0 +1,198 @@
+/* $OpenBSD: arc4random.c,v 1.55 2019/03/24 17:56:54 deraadt Exp $ */
+
+/*
+ * Copyright (c) 1996, David Mazieres <dm@uun.org>
+ * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
+ * Copyright (c) 2013, Markus Friedl <markus@openbsd.org>
+ * Copyright (c) 2014, Theo de Raadt <deraadt@openbsd.org>
+ *
+ * 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.
+ */
+
+/*
+ * ChaCha based random number generator for OpenBSD.
+ */
+
+#include <fcntl.h>
+#include <limits.h>
+#include <signal.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/time.h>
+
+#define KEYSTREAM_ONLY
+#include "chacha_private.h"
+
+#define minimum(a, b) ((a) < (b) ? (a) : (b))
+
+#if defined(__GNUC__) || defined(_MSC_VER)
+#define inline __inline
+#else /* __GNUC__ || _MSC_VER */
+#define inline
+#endif /* !__GNUC__ && !_MSC_VER */
+
+#define KEYSZ 32
+#define IVSZ 8
+#define BLOCKSZ 64
+#define RSBUFSZ (16*BLOCKSZ)
+
+/* Marked MAP_INHERIT_ZERO, so zero'd out in fork children. */
+static struct _rs {
+ size_t rs_have; /* valid bytes at end of rs_buf */
+ size_t rs_count; /* bytes till reseed */
+} *rs;
+
+/* Maybe be preserved in fork children, if _rs_allocate() decides. */
+static struct _rsx {
+ chacha_ctx rs_chacha; /* chacha context for random keystream */
+ u_char rs_buf[RSBUFSZ]; /* keystream blocks */
+} *rsx;
+
+static inline int _rs_allocate(struct _rs **, struct _rsx **);
+static inline void _rs_forkdetect(void);
+#include "arc4random.h"
+
+static inline void _rs_rekey(u_char *dat, size_t datlen);
+
+static inline void
+_rs_init(u_char *buf, size_t n)
+{
+ if (n < KEYSZ + IVSZ)
+ return;
+
+ if (rs == NULL) {
+ if (_rs_allocate(&rs, &rsx) == -1)
+ _exit(1);
+ }
+
+ chacha_keysetup(&rsx->rs_chacha, buf, KEYSZ * 8, 0);
+ chacha_ivsetup(&rsx->rs_chacha, buf + KEYSZ);
+}
+
+static void
+_rs_stir(void)
+{
+ u_char rnd[KEYSZ + IVSZ];
+
+ if (getentropy(rnd, sizeof rnd) == -1)
+ _getentropy_fail();
+
+ if (!rs)
+ _rs_init(rnd, sizeof(rnd));
+ else
+ _rs_rekey(rnd, sizeof(rnd));
+ explicit_bzero(rnd, sizeof(rnd)); /* discard source seed */
+
+ /* invalidate rs_buf */
+ rs->rs_have = 0;
+ memset(rsx->rs_buf, 0, sizeof(rsx->rs_buf));
+
+ rs->rs_count = 1600000;
+}
+
+static inline void
+_rs_stir_if_needed(size_t len)
+{
+ _rs_forkdetect();
+ if (!rs || rs->rs_count <= len)
+ _rs_stir();
+ if (rs->rs_count <= len)
+ rs->rs_count = 0;
+ else
+ rs->rs_count -= len;
+}
+
+static inline void
+_rs_rekey(u_char *dat, size_t datlen)
+{
+#ifndef KEYSTREAM_ONLY
+ memset(rsx->rs_buf, 0, sizeof(rsx->rs_buf));
+#endif
+ /* fill rs_buf with the keystream */
+ chacha_encrypt_bytes(&rsx->rs_chacha, rsx->rs_buf,
+ rsx->rs_buf, sizeof(rsx->rs_buf));
+ /* mix in optional user provided data */
+ if (dat) {
+ size_t i, m;
+
+ m = minimum(datlen, KEYSZ + IVSZ);
+ for (i = 0; i < m; i++)
+ rsx->rs_buf[i] ^= dat[i];
+ }
+ /* immediately reinit for backtracking resistance */
+ _rs_init(rsx->rs_buf, KEYSZ + IVSZ);
+ memset(rsx->rs_buf, 0, KEYSZ + IVSZ);
+ rs->rs_have = sizeof(rsx->rs_buf) - KEYSZ - IVSZ;
+}
+
+static inline void
+_rs_random_buf(void *_buf, size_t n)
+{
+ u_char *buf = (u_char *)_buf;
+ u_char *keystream;
+ size_t m;
+
+ _rs_stir_if_needed(n);
+ while (n > 0) {
+ if (rs->rs_have > 0) {
+ m = minimum(n, rs->rs_have);
+ keystream = rsx->rs_buf + sizeof(rsx->rs_buf)
+ - rs->rs_have;
+ memcpy(buf, keystream, m);
+ memset(keystream, 0, m);
+ buf += m;
+ n -= m;
+ rs->rs_have -= m;
+ }
+ if (rs->rs_have == 0)
+ _rs_rekey(NULL, 0);
+ }
+}
+
+static inline void
+_rs_random_u32(uint32_t *val)
+{
+ u_char *keystream;
+
+ _rs_stir_if_needed(sizeof(*val));
+ if (rs->rs_have < sizeof(*val))
+ _rs_rekey(NULL, 0);
+ keystream = rsx->rs_buf + sizeof(rsx->rs_buf) - rs->rs_have;
+ memcpy(val, keystream, sizeof(*val));
+ memset(keystream, 0, sizeof(*val));
+ rs->rs_have -= sizeof(*val);
+}
+
+uint32_t
+arc4random(void)
+{
+ uint32_t val;
+
+ _ARC4_LOCK();
+ _rs_random_u32(&val);
+ _ARC4_UNLOCK();
+ return val;
+}
+DEF_WEAK(arc4random);
+
+void
+arc4random_buf(void *buf, size_t n)
+{
+ _ARC4_LOCK();
+ _rs_random_buf(buf, n);
+ _ARC4_UNLOCK();
+}
+DEF_WEAK(arc4random_buf);
diff --git a/lib/libc/crypt/arc4random_uniform.c b/lib/libc/crypt/arc4random_uniform.c
new file mode 100644
index 0000000..a18b5b1
--- /dev/null
+++ b/lib/libc/crypt/arc4random_uniform.c
@@ -0,0 +1,57 @@
+/* $OpenBSD: arc4random_uniform.c,v 1.3 2019/01/20 02:59:07 bcook Exp $ */
+
+/*
+ * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
+ *
+ * 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 <stdint.h>
+#include <stdlib.h>
+
+/*
+ * Calculate a uniformly distributed random number less than upper_bound
+ * avoiding "modulo bias".
+ *
+ * Uniformity is achieved by generating new random numbers until the one
+ * returned is outside the range [0, 2**32 % upper_bound). This
+ * guarantees the selected random number will be inside
+ * [2**32 % upper_bound, 2**32) which maps back to [0, upper_bound)
+ * after reduction modulo upper_bound.
+ */
+uint32_t
+arc4random_uniform(uint32_t upper_bound)
+{
+ uint32_t r, min;
+
+ if (upper_bound < 2)
+ return 0;
+
+ /* 2**32 % x == (2**32 - x) % x */
+ min = -upper_bound % upper_bound;
+
+ /*
+ * This could theoretically loop forever but each retry has
+ * p > 0.5 (worst case, usually far better) of selecting a
+ * number inside the range we need, so it should rarely need
+ * to re-roll.
+ */
+ for (;;) {
+ r = arc4random();
+ if (r >= min)
+ break;
+ }
+
+ return r % upper_bound;
+}
+DEF_WEAK(arc4random_uniform);
diff --git a/lib/libc/crypt/blowfish.c b/lib/libc/crypt/blowfish.c
new file mode 100644
index 0000000..a658e60
--- /dev/null
+++ b/lib/libc/crypt/blowfish.c
@@ -0,0 +1,698 @@
+/* $OpenBSD: blowfish.c,v 1.19 2015/09/11 09:18:27 guenther Exp $ */
+/*
+ * Blowfish block cipher for OpenBSD
+ * Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
+ * All rights reserved.
+ *
+ * Implementation advice by David Mazieres <dm@lcs.mit.edu>.
+ *
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Niels Provos.
+ * 4. 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.
+ */
+
+/*
+ * This code is derived from section 14.3 and the given source
+ * in section V of Applied Cryptography, second edition.
+ * Blowfish is an unpatented fast block cipher designed by
+ * Bruce Schneier.
+ */
+
+#if 0
+#include <stdio.h> /* used for debugging */
+#include <string.h>
+#endif
+
+#include <sys/types.h>
+#include <blf.h>
+
+#undef inline
+#ifdef __GNUC__
+#define inline __inline
+#else /* !__GNUC__ */
+#define inline
+#endif /* !__GNUC__ */
+
+/* Function for Feistel Networks */
+
+#define F(s, x) ((((s)[ (((x)>>24)&0xFF)] \
+ + (s)[0x100 + (((x)>>16)&0xFF)]) \
+ ^ (s)[0x200 + (((x)>> 8)&0xFF)]) \
+ + (s)[0x300 + ( (x) &0xFF)])
+
+#define BLFRND(s,p,i,j,n) (i ^= F(s,j) ^ (p)[n])
+
+void
+Blowfish_encipher(blf_ctx *c, u_int32_t *xl, u_int32_t *xr)
+{
+ u_int32_t Xl;
+ u_int32_t Xr;
+ u_int32_t *s = c->S[0];
+ u_int32_t *p = c->P;
+
+ Xl = *xl;
+ Xr = *xr;
+
+ Xl ^= p[0];
+ BLFRND(s, p, Xr, Xl, 1); BLFRND(s, p, Xl, Xr, 2);
+ BLFRND(s, p, Xr, Xl, 3); BLFRND(s, p, Xl, Xr, 4);
+ BLFRND(s, p, Xr, Xl, 5); BLFRND(s, p, Xl, Xr, 6);
+ BLFRND(s, p, Xr, Xl, 7); BLFRND(s, p, Xl, Xr, 8);
+ BLFRND(s, p, Xr, Xl, 9); BLFRND(s, p, Xl, Xr, 10);
+ BLFRND(s, p, Xr, Xl, 11); BLFRND(s, p, Xl, Xr, 12);
+ BLFRND(s, p, Xr, Xl, 13); BLFRND(s, p, Xl, Xr, 14);
+ BLFRND(s, p, Xr, Xl, 15); BLFRND(s, p, Xl, Xr, 16);
+
+ *xl = Xr ^ p[17];
+ *xr = Xl;
+}
+DEF_WEAK(Blowfish_encipher);
+
+void
+Blowfish_decipher(blf_ctx *c, u_int32_t *xl, u_int32_t *xr)
+{
+ u_int32_t Xl;
+ u_int32_t Xr;
+ u_int32_t *s = c->S[0];
+ u_int32_t *p = c->P;
+
+ Xl = *xl;
+ Xr = *xr;
+
+ Xl ^= p[17];
+ BLFRND(s, p, Xr, Xl, 16); BLFRND(s, p, Xl, Xr, 15);
+ BLFRND(s, p, Xr, Xl, 14); BLFRND(s, p, Xl, Xr, 13);
+ BLFRND(s, p, Xr, Xl, 12); BLFRND(s, p, Xl, Xr, 11);
+ BLFRND(s, p, Xr, Xl, 10); BLFRND(s, p, Xl, Xr, 9);
+ BLFRND(s, p, Xr, Xl, 8); BLFRND(s, p, Xl, Xr, 7);
+ BLFRND(s, p, Xr, Xl, 6); BLFRND(s, p, Xl, Xr, 5);
+ BLFRND(s, p, Xr, Xl, 4); BLFRND(s, p, Xl, Xr, 3);
+ BLFRND(s, p, Xr, Xl, 2); BLFRND(s, p, Xl, Xr, 1);
+
+ *xl = Xr ^ p[0];
+ *xr = Xl;
+}
+DEF_WEAK(Blowfish_decipher);
+
+void
+Blowfish_initstate(blf_ctx *c)
+{
+ /* P-box and S-box tables initialized with digits of Pi */
+
+ static const blf_ctx initstate =
+ { {
+ {
+ 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
+ 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
+ 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
+ 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
+ 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
+ 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
+ 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
+ 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
+ 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
+ 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
+ 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
+ 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
+ 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
+ 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
+ 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
+ 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
+ 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
+ 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
+ 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
+ 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
+ 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
+ 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
+ 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
+ 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
+ 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
+ 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
+ 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
+ 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
+ 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
+ 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
+ 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
+ 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
+ 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
+ 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
+ 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
+ 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
+ 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
+ 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
+ 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
+ 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
+ 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
+ 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
+ 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
+ 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
+ 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
+ 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
+ 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
+ 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
+ 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
+ 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
+ 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
+ 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
+ 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
+ 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
+ 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
+ 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
+ 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
+ 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
+ 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
+ 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
+ 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
+ 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
+ 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
+ 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a},
+ {
+ 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
+ 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
+ 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
+ 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
+ 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
+ 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
+ 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
+ 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
+ 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
+ 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
+ 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
+ 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
+ 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
+ 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
+ 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
+ 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
+ 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
+ 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
+ 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
+ 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
+ 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
+ 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
+ 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
+ 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
+ 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
+ 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
+ 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
+ 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
+ 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
+ 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
+ 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
+ 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
+ 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
+ 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
+ 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
+ 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
+ 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
+ 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
+ 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
+ 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
+ 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
+ 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
+ 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
+ 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
+ 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
+ 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
+ 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
+ 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
+ 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
+ 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
+ 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
+ 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
+ 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
+ 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
+ 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
+ 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
+ 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
+ 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
+ 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
+ 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
+ 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
+ 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
+ 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
+ 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7},
+ {
+ 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
+ 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
+ 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
+ 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
+ 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
+ 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
+ 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
+ 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
+ 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
+ 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
+ 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
+ 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
+ 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
+ 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
+ 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
+ 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
+ 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
+ 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
+ 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
+ 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
+ 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
+ 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
+ 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
+ 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
+ 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
+ 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
+ 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
+ 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
+ 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
+ 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
+ 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
+ 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
+ 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
+ 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
+ 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
+ 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
+ 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
+ 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
+ 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
+ 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
+ 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
+ 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
+ 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
+ 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
+ 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
+ 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
+ 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
+ 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
+ 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
+ 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
+ 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
+ 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
+ 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
+ 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
+ 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
+ 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
+ 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
+ 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
+ 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
+ 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
+ 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
+ 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
+ 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
+ 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0},
+ {
+ 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
+ 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
+ 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
+ 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
+ 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
+ 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
+ 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
+ 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
+ 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
+ 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
+ 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
+ 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
+ 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
+ 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
+ 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
+ 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
+ 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
+ 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
+ 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
+ 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
+ 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
+ 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
+ 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
+ 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
+ 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
+ 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
+ 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
+ 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
+ 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
+ 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
+ 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
+ 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
+ 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
+ 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
+ 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
+ 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
+ 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
+ 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
+ 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
+ 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
+ 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
+ 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
+ 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
+ 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
+ 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
+ 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
+ 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
+ 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
+ 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
+ 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
+ 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
+ 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
+ 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
+ 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
+ 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
+ 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
+ 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
+ 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
+ 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
+ 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
+ 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
+ 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
+ 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
+ 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6}
+ },
+ {
+ 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
+ 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
+ 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
+ 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
+ 0x9216d5d9, 0x8979fb1b
+ } };
+
+ *c = initstate;
+}
+DEF_WEAK(Blowfish_initstate);
+
+u_int32_t
+Blowfish_stream2word(const u_int8_t *data, u_int16_t databytes,
+ u_int16_t *current)
+{
+ u_int8_t i;
+ u_int16_t j;
+ u_int32_t temp;
+
+ temp = 0x00000000;
+ j = *current;
+
+ for (i = 0; i < 4; i++, j++) {
+ if (j >= databytes)
+ j = 0;
+ temp = (temp << 8) | data[j];
+ }
+
+ *current = j;
+ return temp;
+}
+DEF_WEAK(Blowfish_stream2word);
+
+void
+Blowfish_expand0state(blf_ctx *c, const u_int8_t *key, u_int16_t keybytes)
+{
+ u_int16_t i;
+ u_int16_t j;
+ u_int16_t k;
+ u_int32_t temp;
+ u_int32_t datal;
+ u_int32_t datar;
+
+ j = 0;
+ for (i = 0; i < BLF_N + 2; i++) {
+ /* Extract 4 int8 to 1 int32 from keystream */
+ temp = Blowfish_stream2word(key, keybytes, &j);
+ c->P[i] = c->P[i] ^ temp;
+ }
+
+ j = 0;
+ datal = 0x00000000;
+ datar = 0x00000000;
+ for (i = 0; i < BLF_N + 2; i += 2) {
+ Blowfish_encipher(c, &datal, &datar);
+
+ c->P[i] = datal;
+ c->P[i + 1] = datar;
+ }
+
+ for (i = 0; i < 4; i++) {
+ for (k = 0; k < 256; k += 2) {
+ Blowfish_encipher(c, &datal, &datar);
+
+ c->S[i][k] = datal;
+ c->S[i][k + 1] = datar;
+ }
+ }
+}
+DEF_WEAK(Blowfish_expand0state);
+
+
+void
+Blowfish_expandstate(blf_ctx *c, const u_int8_t *data, u_int16_t databytes,
+ const u_int8_t *key, u_int16_t keybytes)
+{
+ u_int16_t i;
+ u_int16_t j;
+ u_int16_t k;
+ u_int32_t temp;
+ u_int32_t datal;
+ u_int32_t datar;
+
+ j = 0;
+ for (i = 0; i < BLF_N + 2; i++) {
+ /* Extract 4 int8 to 1 int32 from keystream */
+ temp = Blowfish_stream2word(key, keybytes, &j);
+ c->P[i] = c->P[i] ^ temp;
+ }
+
+ j = 0;
+ datal = 0x00000000;
+ datar = 0x00000000;
+ for (i = 0; i < BLF_N + 2; i += 2) {
+ datal ^= Blowfish_stream2word(data, databytes, &j);
+ datar ^= Blowfish_stream2word(data, databytes, &j);
+ Blowfish_encipher(c, &datal, &datar);
+
+ c->P[i] = datal;
+ c->P[i + 1] = datar;
+ }
+
+ for (i = 0; i < 4; i++) {
+ for (k = 0; k < 256; k += 2) {
+ datal ^= Blowfish_stream2word(data, databytes, &j);
+ datar ^= Blowfish_stream2word(data, databytes, &j);
+ Blowfish_encipher(c, &datal, &datar);
+
+ c->S[i][k] = datal;
+ c->S[i][k + 1] = datar;
+ }
+ }
+
+}
+DEF_WEAK(Blowfish_expandstate);
+
+void
+blf_key(blf_ctx *c, const u_int8_t *k, u_int16_t len)
+{
+ /* Initialize S-boxes and subkeys with Pi */
+ Blowfish_initstate(c);
+
+ /* Transform S-boxes and subkeys with key */
+ Blowfish_expand0state(c, k, len);
+}
+DEF_WEAK(blf_key);
+
+void
+blf_enc(blf_ctx *c, u_int32_t *data, u_int16_t blocks)
+{
+ u_int32_t *d;
+ u_int16_t i;
+
+ d = data;
+ for (i = 0; i < blocks; i++) {
+ Blowfish_encipher(c, d, d + 1);
+ d += 2;
+ }
+}
+DEF_WEAK(blf_enc);
+
+void
+blf_dec(blf_ctx *c, u_int32_t *data, u_int16_t blocks)
+{
+ u_int32_t *d;
+ u_int16_t i;
+
+ d = data;
+ for (i = 0; i < blocks; i++) {
+ Blowfish_decipher(c, d, d + 1);
+ d += 2;
+ }
+}
+DEF_WEAK(blf_dec);
+
+void
+blf_ecb_encrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
+{
+ u_int32_t l, r;
+ u_int32_t i;
+
+ for (i = 0; i < len; i += 8) {
+ l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
+ r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
+ Blowfish_encipher(c, &l, &r);
+ data[0] = l >> 24 & 0xff;
+ data[1] = l >> 16 & 0xff;
+ data[2] = l >> 8 & 0xff;
+ data[3] = l & 0xff;
+ data[4] = r >> 24 & 0xff;
+ data[5] = r >> 16 & 0xff;
+ data[6] = r >> 8 & 0xff;
+ data[7] = r & 0xff;
+ data += 8;
+ }
+}
+DEF_WEAK(blf_ecb_encrypt);
+
+void
+blf_ecb_decrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
+{
+ u_int32_t l, r;
+ u_int32_t i;
+
+ for (i = 0; i < len; i += 8) {
+ l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
+ r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
+ Blowfish_decipher(c, &l, &r);
+ data[0] = l >> 24 & 0xff;
+ data[1] = l >> 16 & 0xff;
+ data[2] = l >> 8 & 0xff;
+ data[3] = l & 0xff;
+ data[4] = r >> 24 & 0xff;
+ data[5] = r >> 16 & 0xff;
+ data[6] = r >> 8 & 0xff;
+ data[7] = r & 0xff;
+ data += 8;
+ }
+}
+DEF_WEAK(blf_ecb_decrypt);
+
+void
+blf_cbc_encrypt(blf_ctx *c, u_int8_t *iv, u_int8_t *data, u_int32_t len)
+{
+ u_int32_t l, r;
+ u_int32_t i, j;
+
+ for (i = 0; i < len; i += 8) {
+ for (j = 0; j < 8; j++)
+ data[j] ^= iv[j];
+ l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
+ r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
+ Blowfish_encipher(c, &l, &r);
+ data[0] = l >> 24 & 0xff;
+ data[1] = l >> 16 & 0xff;
+ data[2] = l >> 8 & 0xff;
+ data[3] = l & 0xff;
+ data[4] = r >> 24 & 0xff;
+ data[5] = r >> 16 & 0xff;
+ data[6] = r >> 8 & 0xff;
+ data[7] = r & 0xff;
+ iv = data;
+ data += 8;
+ }
+}
+DEF_WEAK(blf_cbc_encrypt);
+
+void
+blf_cbc_decrypt(blf_ctx *c, u_int8_t *iva, u_int8_t *data, u_int32_t len)
+{
+ u_int32_t l, r;
+ u_int8_t *iv;
+ u_int32_t i, j;
+
+ iv = data + len - 16;
+ data = data + len - 8;
+ for (i = len - 8; i >= 8; i -= 8) {
+ l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
+ r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
+ Blowfish_decipher(c, &l, &r);
+ data[0] = l >> 24 & 0xff;
+ data[1] = l >> 16 & 0xff;
+ data[2] = l >> 8 & 0xff;
+ data[3] = l & 0xff;
+ data[4] = r >> 24 & 0xff;
+ data[5] = r >> 16 & 0xff;
+ data[6] = r >> 8 & 0xff;
+ data[7] = r & 0xff;
+ for (j = 0; j < 8; j++)
+ data[j] ^= iv[j];
+ iv -= 8;
+ data -= 8;
+ }
+ l = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
+ r = data[4] << 24 | data[5] << 16 | data[6] << 8 | data[7];
+ Blowfish_decipher(c, &l, &r);
+ data[0] = l >> 24 & 0xff;
+ data[1] = l >> 16 & 0xff;
+ data[2] = l >> 8 & 0xff;
+ data[3] = l & 0xff;
+ data[4] = r >> 24 & 0xff;
+ data[5] = r >> 16 & 0xff;
+ data[6] = r >> 8 & 0xff;
+ data[7] = r & 0xff;
+ for (j = 0; j < 8; j++)
+ data[j] ^= iva[j];
+}
+DEF_WEAK(blf_cbc_decrypt);
+
+#if 0
+void
+report(u_int32_t data[], u_int16_t len)
+{
+ u_int16_t i;
+ for (i = 0; i < len; i += 2)
+ printf("Block %0hd: %08lx %08lx.\n",
+ i / 2, data[i], data[i + 1]);
+}
+void
+main(void)
+{
+
+ blf_ctx c;
+ char key[] = "AAAAA";
+ char key2[] = "abcdefghijklmnopqrstuvwxyz";
+
+ u_int32_t data[10];
+ u_int32_t data2[] =
+ {0x424c4f57l, 0x46495348l};
+
+ u_int16_t i;
+
+ /* First test */
+ for (i = 0; i < 10; i++)
+ data[i] = i;
+
+ blf_key(&c, (u_int8_t *) key, 5);
+ blf_enc(&c, data, 5);
+ blf_dec(&c, data, 1);
+ blf_dec(&c, data + 2, 4);
+ printf("Should read as 0 - 9.\n");
+ report(data, 10);
+
+ /* Second test */
+ blf_key(&c, (u_int8_t *) key2, strlen(key2));
+ blf_enc(&c, data2, 1);
+ printf("\nShould read as: 0x324ed0fe 0xf413a203.\n");
+ report(data2, 2);
+ blf_dec(&c, data2, 1);
+ report(data2, 2);
+}
+#endif
diff --git a/lib/libc/crypt/chacha_private.h b/lib/libc/crypt/chacha_private.h
new file mode 100644
index 0000000..7c3680f
--- /dev/null
+++ b/lib/libc/crypt/chacha_private.h
@@ -0,0 +1,222 @@
+/*
+chacha-merged.c version 20080118
+D. J. Bernstein
+Public domain.
+*/
+
+/* $OpenBSD: chacha_private.h,v 1.2 2013/10/04 07:02:27 djm Exp $ */
+
+typedef unsigned char u8;
+typedef unsigned int u32;
+
+typedef struct
+{
+ u32 input[16]; /* could be compressed */
+} chacha_ctx;
+
+#define U8C(v) (v##U)
+#define U32C(v) (v##U)
+
+#define U8V(v) ((u8)(v) & U8C(0xFF))
+#define U32V(v) ((u32)(v) & U32C(0xFFFFFFFF))
+
+#define ROTL32(v, n) \
+ (U32V((v) << (n)) | ((v) >> (32 - (n))))
+
+#define U8TO32_LITTLE(p) \
+ (((u32)((p)[0]) ) | \
+ ((u32)((p)[1]) << 8) | \
+ ((u32)((p)[2]) << 16) | \
+ ((u32)((p)[3]) << 24))
+
+#define U32TO8_LITTLE(p, v) \
+ do { \
+ (p)[0] = U8V((v) ); \
+ (p)[1] = U8V((v) >> 8); \
+ (p)[2] = U8V((v) >> 16); \
+ (p)[3] = U8V((v) >> 24); \
+ } while (0)
+
+#define ROTATE(v,c) (ROTL32(v,c))
+#define XOR(v,w) ((v) ^ (w))
+#define PLUS(v,w) (U32V((v) + (w)))
+#define PLUSONE(v) (PLUS((v),1))
+
+#define QUARTERROUND(a,b,c,d) \
+ a = PLUS(a,b); d = ROTATE(XOR(d,a),16); \
+ c = PLUS(c,d); b = ROTATE(XOR(b,c),12); \
+ a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); \
+ c = PLUS(c,d); b = ROTATE(XOR(b,c), 7);
+
+static const char sigma[16] = "expand 32-byte k";
+static const char tau[16] = "expand 16-byte k";
+
+static void
+chacha_keysetup(chacha_ctx *x,const u8 *k,u32 kbits,u32 ivbits)
+{
+ const char *constants;
+
+ x->input[4] = U8TO32_LITTLE(k + 0);
+ x->input[5] = U8TO32_LITTLE(k + 4);
+ x->input[6] = U8TO32_LITTLE(k + 8);
+ x->input[7] = U8TO32_LITTLE(k + 12);
+ if (kbits == 256) { /* recommended */
+ k += 16;
+ constants = sigma;
+ } else { /* kbits == 128 */
+ constants = tau;
+ }
+ x->input[8] = U8TO32_LITTLE(k + 0);
+ x->input[9] = U8TO32_LITTLE(k + 4);
+ x->input[10] = U8TO32_LITTLE(k + 8);
+ x->input[11] = U8TO32_LITTLE(k + 12);
+ x->input[0] = U8TO32_LITTLE(constants + 0);
+ x->input[1] = U8TO32_LITTLE(constants + 4);
+ x->input[2] = U8TO32_LITTLE(constants + 8);
+ x->input[3] = U8TO32_LITTLE(constants + 12);
+}
+
+static void
+chacha_ivsetup(chacha_ctx *x,const u8 *iv)
+{
+ x->input[12] = 0;
+ x->input[13] = 0;
+ x->input[14] = U8TO32_LITTLE(iv + 0);
+ x->input[15] = U8TO32_LITTLE(iv + 4);
+}
+
+static void
+chacha_encrypt_bytes(chacha_ctx *x,const u8 *m,u8 *c,u32 bytes)
+{
+ u32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
+ u32 j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
+ u8 *ctarget = NULL;
+ u8 tmp[64];
+ u_int i;
+
+ if (!bytes) return;
+
+ j0 = x->input[0];
+ j1 = x->input[1];
+ j2 = x->input[2];
+ j3 = x->input[3];
+ j4 = x->input[4];
+ j5 = x->input[5];
+ j6 = x->input[6];
+ j7 = x->input[7];
+ j8 = x->input[8];
+ j9 = x->input[9];
+ j10 = x->input[10];
+ j11 = x->input[11];
+ j12 = x->input[12];
+ j13 = x->input[13];
+ j14 = x->input[14];
+ j15 = x->input[15];
+
+ for (;;) {
+ if (bytes < 64) {
+ for (i = 0;i < bytes;++i) tmp[i] = m[i];
+ m = tmp;
+ ctarget = c;
+ c = tmp;
+ }
+ x0 = j0;
+ x1 = j1;
+ x2 = j2;
+ x3 = j3;
+ x4 = j4;
+ x5 = j5;
+ x6 = j6;
+ x7 = j7;
+ x8 = j8;
+ x9 = j9;
+ x10 = j10;
+ x11 = j11;
+ x12 = j12;
+ x13 = j13;
+ x14 = j14;
+ x15 = j15;
+ for (i = 20;i > 0;i -= 2) {
+ QUARTERROUND( x0, x4, x8,x12)
+ QUARTERROUND( x1, x5, x9,x13)
+ QUARTERROUND( x2, x6,x10,x14)
+ QUARTERROUND( x3, x7,x11,x15)
+ QUARTERROUND( x0, x5,x10,x15)
+ QUARTERROUND( x1, x6,x11,x12)
+ QUARTERROUND( x2, x7, x8,x13)
+ QUARTERROUND( x3, x4, x9,x14)
+ }
+ x0 = PLUS(x0,j0);
+ x1 = PLUS(x1,j1);
+ x2 = PLUS(x2,j2);
+ x3 = PLUS(x3,j3);
+ x4 = PLUS(x4,j4);
+ x5 = PLUS(x5,j5);
+ x6 = PLUS(x6,j6);
+ x7 = PLUS(x7,j7);
+ x8 = PLUS(x8,j8);
+ x9 = PLUS(x9,j9);
+ x10 = PLUS(x10,j10);
+ x11 = PLUS(x11,j11);
+ x12 = PLUS(x12,j12);
+ x13 = PLUS(x13,j13);
+ x14 = PLUS(x14,j14);
+ x15 = PLUS(x15,j15);
+
+#ifndef KEYSTREAM_ONLY
+ x0 = XOR(x0,U8TO32_LITTLE(m + 0));
+ x1 = XOR(x1,U8TO32_LITTLE(m + 4));
+ x2 = XOR(x2,U8TO32_LITTLE(m + 8));
+ x3 = XOR(x3,U8TO32_LITTLE(m + 12));
+ x4 = XOR(x4,U8TO32_LITTLE(m + 16));
+ x5 = XOR(x5,U8TO32_LITTLE(m + 20));
+ x6 = XOR(x6,U8TO32_LITTLE(m + 24));
+ x7 = XOR(x7,U8TO32_LITTLE(m + 28));
+ x8 = XOR(x8,U8TO32_LITTLE(m + 32));
+ x9 = XOR(x9,U8TO32_LITTLE(m + 36));
+ x10 = XOR(x10,U8TO32_LITTLE(m + 40));
+ x11 = XOR(x11,U8TO32_LITTLE(m + 44));
+ x12 = XOR(x12,U8TO32_LITTLE(m + 48));
+ x13 = XOR(x13,U8TO32_LITTLE(m + 52));
+ x14 = XOR(x14,U8TO32_LITTLE(m + 56));
+ x15 = XOR(x15,U8TO32_LITTLE(m + 60));
+#endif
+
+ j12 = PLUSONE(j12);
+ if (!j12) {
+ j13 = PLUSONE(j13);
+ /* stopping at 2^70 bytes per nonce is user's responsibility */
+ }
+
+ U32TO8_LITTLE(c + 0,x0);
+ U32TO8_LITTLE(c + 4,x1);
+ U32TO8_LITTLE(c + 8,x2);
+ U32TO8_LITTLE(c + 12,x3);
+ U32TO8_LITTLE(c + 16,x4);
+ U32TO8_LITTLE(c + 20,x5);
+ U32TO8_LITTLE(c + 24,x6);
+ U32TO8_LITTLE(c + 28,x7);
+ U32TO8_LITTLE(c + 32,x8);
+ U32TO8_LITTLE(c + 36,x9);
+ U32TO8_LITTLE(c + 40,x10);
+ U32TO8_LITTLE(c + 44,x11);
+ U32TO8_LITTLE(c + 48,x12);
+ U32TO8_LITTLE(c + 52,x13);
+ U32TO8_LITTLE(c + 56,x14);
+ U32TO8_LITTLE(c + 60,x15);
+
+ if (bytes <= 64) {
+ if (bytes < 64) {
+ for (i = 0;i < bytes;++i) ctarget[i] = c[i];
+ }
+ x->input[12] = j12;
+ x->input[13] = j13;
+ return;
+ }
+ bytes -= 64;
+ c += 64;
+#ifndef KEYSTREAM_ONLY
+ m += 64;
+#endif
+ }
+}
diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c
new file mode 100644
index 0000000..982dd87
--- /dev/null
+++ b/lib/libc/gen/fts.c
@@ -0,0 +1,1053 @@
+/* $OpenBSD: fts.c,v 1.59 2019/06/28 13:32:41 deraadt Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993, 1994
+ * 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.
+ */
+
+#include <sys/param.h> /* ALIGN */
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <fts.h>
+#include <limits.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+#define MAXIMUM(a, b) (((a) > (b)) ? (a) : (b))
+
+static FTSENT *fts_alloc(FTS *, char *, size_t);
+static FTSENT *fts_build(FTS *, int);
+static void fts_lfree(FTSENT *);
+static void fts_load(FTS *, FTSENT *);
+static size_t fts_maxarglen(char * const *);
+static void fts_padjust(FTS *, FTSENT *);
+static int fts_palloc(FTS *, size_t);
+static FTSENT *fts_sort(FTS *, FTSENT *, int);
+static u_short fts_stat(FTS *, FTSENT *, int, int);
+static int fts_safe_changedir(FTS *, FTSENT *, int, char *);
+
+#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2])))
+
+#define CLR(opt) (sp->fts_options &= ~(opt))
+#define ISSET(opt) (sp->fts_options & (opt))
+#define SET(opt) (sp->fts_options |= (opt))
+
+#define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && fchdir(fd))
+
+/* fts_build flags */
+#define BCHILD 1 /* fts_children */
+#define BNAMES 2 /* fts_children, names only */
+#define BREAD 3 /* fts_read */
+
+FTS *
+fts_open(char * const *argv, int options,
+ int (*compar)(const FTSENT **, const FTSENT **))
+{
+ FTS *sp;
+ FTSENT *p, *root;
+ int nitems;
+ FTSENT *parent, *prev;
+
+ /* Options check. */
+ if (options & ~FTS_OPTIONMASK) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ /* At least one path must be specified. */
+ if (*argv == NULL) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ /* Allocate/initialize the stream */
+ if ((sp = calloc(1, sizeof(FTS))) == NULL)
+ return (NULL);
+ sp->fts_compar = compar;
+ sp->fts_options = options;
+
+ /* Logical walks turn on NOCHDIR; symbolic links are too hard. */
+ if (ISSET(FTS_LOGICAL))
+ SET(FTS_NOCHDIR);
+
+ /*
+ * Start out with 1K of path space, and enough, in any case,
+ * to hold the user's paths.
+ */
+ if (fts_palloc(sp, MAXIMUM(fts_maxarglen(argv), PATH_MAX)))
+ goto mem1;
+
+ /* Allocate/initialize root's parent. */
+ if ((parent = fts_alloc(sp, "", 0)) == NULL)
+ goto mem2;
+ parent->fts_level = FTS_ROOTPARENTLEVEL;
+
+ /* Allocate/initialize root(s). */
+ for (root = prev = NULL, nitems = 0; *argv; ++argv, ++nitems) {
+ if ((p = fts_alloc(sp, *argv, strlen(*argv))) == NULL)
+ goto mem3;
+ p->fts_level = FTS_ROOTLEVEL;
+ p->fts_parent = parent;
+ p->fts_accpath = p->fts_name;
+ p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW), -1);
+
+ /* Command-line "." and ".." are real directories. */
+ if (p->fts_info == FTS_DOT)
+ p->fts_info = FTS_D;
+
+ /*
+ * If comparison routine supplied, traverse in sorted
+ * order; otherwise traverse in the order specified.
+ */
+ if (compar) {
+ p->fts_link = root;
+ root = p;
+ } else {
+ p->fts_link = NULL;
+ if (root == NULL)
+ root = p;
+ else
+ prev->fts_link = p;
+ prev = p;
+ }
+ }
+ if (compar && nitems > 1)
+ root = fts_sort(sp, root, nitems);
+
+ /*
+ * Allocate a dummy pointer and make fts_read think that we've just
+ * finished the node before the root(s); set p->fts_info to FTS_INIT
+ * so that everything about the "current" node is ignored.
+ */
+ if ((sp->fts_cur = fts_alloc(sp, "", 0)) == NULL)
+ goto mem3;
+ sp->fts_cur->fts_link = root;
+ sp->fts_cur->fts_info = FTS_INIT;
+
+ /*
+ * If using chdir(2), grab a file descriptor pointing to dot to ensure
+ * that we can get back here; this could be avoided for some paths,
+ * but almost certainly not worth the effort. Slashes, symbolic links,
+ * and ".." are all fairly nasty problems. Note, if we can't get the
+ * descriptor we run anyway, just more slowly.
+ */
+ if (!ISSET(FTS_NOCHDIR) &&
+ (sp->fts_rfd = open(".", O_RDONLY | O_CLOEXEC)) == -1)
+ SET(FTS_NOCHDIR);
+
+ if (nitems == 0)
+ free(parent);
+
+ return (sp);
+
+mem3: fts_lfree(root);
+ free(parent);
+mem2: free(sp->fts_path);
+mem1: free(sp);
+ return (NULL);
+}
+DEF_WEAK(fts_open);
+
+static void
+fts_load(FTS *sp, FTSENT *p)
+{
+ size_t len;
+ char *cp;
+
+ /*
+ * Load the stream structure for the next traversal. Since we don't
+ * actually enter the directory until after the preorder visit, set
+ * the fts_accpath field specially so the chdir gets done to the right
+ * place and the user can access the first node. From fts_open it's
+ * known that the path will fit.
+ */
+ len = p->fts_pathlen = p->fts_namelen;
+ memmove(sp->fts_path, p->fts_name, len + 1);
+ if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) {
+ len = strlen(++cp);
+ memmove(p->fts_name, cp, len + 1);
+ p->fts_namelen = len;
+ }
+ p->fts_accpath = p->fts_path = sp->fts_path;
+ sp->fts_dev = p->fts_dev;
+}
+
+int
+fts_close(FTS *sp)
+{
+ FTSENT *freep, *p;
+ int rfd, error = 0;
+
+ /*
+ * This still works if we haven't read anything -- the dummy structure
+ * points to the root list, so we step through to the end of the root
+ * list which has a valid parent pointer.
+ */
+ if (sp->fts_cur) {
+ for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) {
+ freep = p;
+ p = p->fts_link ? p->fts_link : p->fts_parent;
+ free(freep);
+ }
+ free(p);
+ }
+
+ /* Stash the original directory fd if needed. */
+ rfd = ISSET(FTS_NOCHDIR) ? -1 : sp->fts_rfd;
+
+ /* Free up child linked list, sort array, path buffer, stream ptr.*/
+ if (sp->fts_child)
+ fts_lfree(sp->fts_child);
+ free(sp->fts_array);
+ free(sp->fts_path);
+ free(sp);
+
+ /* Return to original directory, checking for error. */
+ if (rfd != -1) {
+ int saved_errno;
+ error = fchdir(rfd);
+ saved_errno = errno;
+ (void)close(rfd);
+ errno = saved_errno;
+ }
+
+ return (error);
+}
+DEF_WEAK(fts_close);
+
+/*
+ * Special case of "/" at the end of the path so that slashes aren't
+ * appended which would cause paths to be written as "....//foo".
+ */
+#define NAPPEND(p) \
+ (p->fts_path[p->fts_pathlen - 1] == '/' \
+ ? p->fts_pathlen - 1 : p->fts_pathlen)
+
+FTSENT *
+fts_read(FTS *sp)
+{
+ FTSENT *p, *tmp;
+ int instr;
+ char *t;
+ int saved_errno;
+
+ /* If finished or unrecoverable error, return NULL. */
+ if (sp->fts_cur == NULL || ISSET(FTS_STOP))
+ return (NULL);
+
+ /* Set current node pointer. */
+ p = sp->fts_cur;
+
+ /* Save and zero out user instructions. */
+ instr = p->fts_instr;
+ p->fts_instr = FTS_NOINSTR;
+
+ /* Any type of file may be re-visited; re-stat and re-turn. */
+ if (instr == FTS_AGAIN) {
+ p->fts_info = fts_stat(sp, p, 0, -1);
+ return (p);
+ }
+
+ /*
+ * Following a symlink -- SLNONE test allows application to see
+ * SLNONE and recover. If indirecting through a symlink, have
+ * keep a pointer to current location. If unable to get that
+ * pointer, follow fails.
+ */
+ if (instr == FTS_FOLLOW &&
+ (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) {
+ p->fts_info = fts_stat(sp, p, 1, -1);
+ if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
+ if ((p->fts_symfd =
+ open(".", O_RDONLY | O_CLOEXEC)) == -1) {
+ p->fts_errno = errno;
+ p->fts_info = FTS_ERR;
+ } else
+ p->fts_flags |= FTS_SYMFOLLOW;
+ }
+ return (p);
+ }
+
+ /* Directory in pre-order. */
+ if (p->fts_info == FTS_D) {
+ /* If skipped or crossed mount point, do post-order visit. */
+ if (instr == FTS_SKIP ||
+ (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) {
+ if (p->fts_flags & FTS_SYMFOLLOW)
+ (void)close(p->fts_symfd);
+ if (sp->fts_child) {
+ fts_lfree(sp->fts_child);
+ sp->fts_child = NULL;
+ }
+ p->fts_info = FTS_DP;
+ return (p);
+ }
+
+ /* Rebuild if only read the names and now traversing. */
+ if (sp->fts_child && ISSET(FTS_NAMEONLY)) {
+ CLR(FTS_NAMEONLY);
+ fts_lfree(sp->fts_child);
+ sp->fts_child = NULL;
+ }
+
+ /*
+ * Cd to the subdirectory.
+ *
+ * If have already read and now fail to chdir, whack the list
+ * to make the names come out right, and set the parent errno
+ * so the application will eventually get an error condition.
+ * Set the FTS_DONTCHDIR flag so that when we logically change
+ * directories back to the parent we don't do a chdir.
+ *
+ * If haven't read do so. If the read fails, fts_build sets
+ * FTS_STOP or the fts_info field of the node.
+ */
+ if (sp->fts_child) {
+ if (fts_safe_changedir(sp, p, -1, p->fts_accpath)) {
+ p->fts_errno = errno;
+ p->fts_flags |= FTS_DONTCHDIR;
+ for (p = sp->fts_child; p; p = p->fts_link)
+ p->fts_accpath =
+ p->fts_parent->fts_accpath;
+ }
+ } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) {
+ if (ISSET(FTS_STOP))
+ return (NULL);
+ return (p);
+ }
+ p = sp->fts_child;
+ sp->fts_child = NULL;
+ goto name;
+ }
+
+ /* Move to the next node on this level. */
+next: tmp = p;
+ if ((p = p->fts_link)) {
+ free(tmp);
+
+ /*
+ * If reached the top, return to the original directory (or
+ * the root of the tree), and load the paths for the next root.
+ */
+ if (p->fts_level == FTS_ROOTLEVEL) {
+ if (FCHDIR(sp, sp->fts_rfd)) {
+ SET(FTS_STOP);
+ return (NULL);
+ }
+ fts_load(sp, p);
+ return (sp->fts_cur = p);
+ }
+
+ /*
+ * User may have called fts_set on the node. If skipped,
+ * ignore. If followed, get a file descriptor so we can
+ * get back if necessary.
+ */
+ if (p->fts_instr == FTS_SKIP)
+ goto next;
+ if (p->fts_instr == FTS_FOLLOW) {
+ p->fts_info = fts_stat(sp, p, 1, -1);
+ if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) {
+ if ((p->fts_symfd =
+ open(".", O_RDONLY | O_CLOEXEC)) == -1) {
+ p->fts_errno = errno;
+ p->fts_info = FTS_ERR;
+ } else
+ p->fts_flags |= FTS_SYMFOLLOW;
+ }
+ p->fts_instr = FTS_NOINSTR;
+ }
+
+name: t = sp->fts_path + NAPPEND(p->fts_parent);
+ *t++ = '/';
+ memmove(t, p->fts_name, p->fts_namelen + 1);
+ return (sp->fts_cur = p);
+ }
+
+ /* Move up to the parent node. */
+ p = tmp->fts_parent;
+ free(tmp);
+
+ if (p->fts_level == FTS_ROOTPARENTLEVEL) {
+ /*
+ * Done; free everything up and set errno to 0 so the user
+ * can distinguish between error and EOF.
+ */
+ free(p);
+ errno = 0;
+ return (sp->fts_cur = NULL);
+ }
+
+ /* NUL terminate the pathname. */
+ sp->fts_path[p->fts_pathlen] = '\0';
+
+ /*
+ * Return to the parent directory. If at a root node or came through
+ * a symlink, go back through the file descriptor. Otherwise, cd up
+ * one directory.
+ */
+ if (p->fts_level == FTS_ROOTLEVEL) {
+ if (FCHDIR(sp, sp->fts_rfd)) {
+ SET(FTS_STOP);
+ sp->fts_cur = p;
+ return (NULL);
+ }
+ } else if (p->fts_flags & FTS_SYMFOLLOW) {
+ if (FCHDIR(sp, p->fts_symfd)) {
+ saved_errno = errno;
+ (void)close(p->fts_symfd);
+ errno = saved_errno;
+ SET(FTS_STOP);
+ sp->fts_cur = p;
+ return (NULL);
+ }
+ (void)close(p->fts_symfd);
+ } else if (!(p->fts_flags & FTS_DONTCHDIR) &&
+ fts_safe_changedir(sp, p->fts_parent, -1, "..")) {
+ SET(FTS_STOP);
+ sp->fts_cur = p;
+ return (NULL);
+ }
+ p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP;
+ return (sp->fts_cur = p);
+}
+DEF_WEAK(fts_read);
+
+/*
+ * Fts_set takes the stream as an argument although it's not used in this
+ * implementation; it would be necessary if anyone wanted to add global
+ * semantics to fts using fts_set. An error return is allowed for similar
+ * reasons.
+ */
+int
+fts_set(FTS *sp, FTSENT *p, int instr)
+{
+ if (instr && instr != FTS_AGAIN && instr != FTS_FOLLOW &&
+ instr != FTS_NOINSTR && instr != FTS_SKIP) {
+ errno = EINVAL;
+ return (1);
+ }
+ p->fts_instr = instr;
+ return (0);
+}
+DEF_WEAK(fts_set);
+
+FTSENT *
+fts_children(FTS *sp, int instr)
+{
+ FTSENT *p;
+ int fd;
+
+ if (instr && instr != FTS_NAMEONLY) {
+ errno = EINVAL;
+ return (NULL);
+ }
+
+ /* Set current node pointer. */
+ p = sp->fts_cur;
+
+ /*
+ * Errno set to 0 so user can distinguish empty directory from
+ * an error.
+ */
+ errno = 0;
+
+ /* Fatal errors stop here. */
+ if (ISSET(FTS_STOP))
+ return (NULL);
+
+ /* Return logical hierarchy of user's arguments. */
+ if (p->fts_info == FTS_INIT)
+ return (p->fts_link);
+
+ /*
+ * If not a directory being visited in pre-order, stop here. Could
+ * allow FTS_DNR, assuming the user has fixed the problem, but the
+ * same effect is available with FTS_AGAIN.
+ */
+ if (p->fts_info != FTS_D /* && p->fts_info != FTS_DNR */)
+ return (NULL);
+
+ /* Free up any previous child list. */
+ if (sp->fts_child)
+ fts_lfree(sp->fts_child);
+
+ if (instr == FTS_NAMEONLY) {
+ SET(FTS_NAMEONLY);
+ instr = BNAMES;
+ } else
+ instr = BCHILD;
+
+ /*
+ * If using chdir on a relative path and called BEFORE fts_read does
+ * its chdir to the root of a traversal, we can lose -- we need to
+ * chdir into the subdirectory, and we don't know where the current
+ * directory is, so we can't get back so that the upcoming chdir by
+ * fts_read will work.
+ */
+ if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == '/' ||
+ ISSET(FTS_NOCHDIR))
+ return (sp->fts_child = fts_build(sp, instr));
+
+ if ((fd = open(".", O_RDONLY | O_CLOEXEC)) == -1)
+ return (NULL);
+ sp->fts_child = fts_build(sp, instr);
+ if (fchdir(fd)) {
+ (void)close(fd);
+ return (NULL);
+ }
+ (void)close(fd);
+ return (sp->fts_child);
+}
+DEF_WEAK(fts_children);
+
+/*
+ * This is the tricky part -- do not casually change *anything* in here. The
+ * idea is to build the linked list of entries that are used by fts_children
+ * and fts_read. There are lots of special cases.
+ *
+ * The real slowdown in walking the tree is the stat calls. If FTS_NOSTAT is
+ * set and it's a physical walk (so that symbolic links can't be directories),
+ * we can do things quickly. First, if it's a 4.4BSD file system, the type
+ * of the file is in the directory entry. Otherwise, we assume that the number
+ * of subdirectories in a node is equal to the number of links to the parent.
+ * The former skips all stat calls. The latter skips stat calls in any leaf
+ * directories and for any files after the subdirectories in the directory have
+ * been found, cutting the stat calls by about 2/3.
+ */
+static FTSENT *
+fts_build(FTS *sp, int type)
+{
+ struct dirent *dp;
+ FTSENT *p, *head;
+ FTSENT *cur, *tail;
+ DIR *dirp;
+ void *oldaddr;
+ size_t len, maxlen;
+ int nitems, cderrno, descend, level, nlinks, nostat, doadjust;
+ int saved_errno;
+ char *cp;
+ size_t namlen;
+
+ /* Set current node pointer. */
+ cur = sp->fts_cur;
+
+ /*
+ * Open the directory for reading. If this fails, we're done.
+ * If being called from fts_read, set the fts_info field.
+ */
+ if ((dirp = opendir(cur->fts_accpath)) == NULL) {
+ if (type == BREAD) {
+ cur->fts_info = FTS_DNR;
+ cur->fts_errno = errno;
+ }
+ return (NULL);
+ }
+
+ /*
+ * Nlinks is the number of possible entries of type directory in the
+ * directory if we're cheating on stat calls, 0 if we're not doing
+ * any stat calls at all, -1 if we're doing stats on everything.
+ */
+ if (type == BNAMES)
+ nlinks = 0;
+ else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL)) {
+ nlinks = cur->fts_nlink - (ISSET(FTS_SEEDOT) ? 0 : 2);
+ nostat = 1;
+ } else {
+ nlinks = -1;
+ nostat = 0;
+ }
+
+#ifdef notdef
+ (void)printf("nlinks == %d (cur: %u)\n", nlinks, cur->fts_nlink);
+ (void)printf("NOSTAT %d PHYSICAL %d SEEDOT %d\n",
+ ISSET(FTS_NOSTAT), ISSET(FTS_PHYSICAL), ISSET(FTS_SEEDOT));
+#endif
+ /*
+ * If we're going to need to stat anything or we want to descend
+ * and stay in the directory, chdir. If this fails we keep going,
+ * but set a flag so we don't chdir after the post-order visit.
+ * We won't be able to stat anything, but we can still return the
+ * names themselves. Note, that since fts_read won't be able to
+ * chdir into the directory, it will have to return different path
+ * names than before, i.e. "a/b" instead of "b". Since the node
+ * has already been visited in pre-order, have to wait until the
+ * post-order visit to return the error. There is a special case
+ * here, if there was nothing to stat then it's not an error to
+ * not be able to stat. This is all fairly nasty. If a program
+ * needed sorted entries or stat information, they had better be
+ * checking FTS_NS on the returned nodes.
+ */
+ cderrno = 0;
+ if (nlinks || type == BREAD) {
+ if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) {
+ if (nlinks && type == BREAD)
+ cur->fts_errno = errno;
+ cur->fts_flags |= FTS_DONTCHDIR;
+ descend = 0;
+ cderrno = errno;
+ (void)closedir(dirp);
+ dirp = NULL;
+ } else
+ descend = 1;
+ } else
+ descend = 0;
+
+ /*
+ * Figure out the max file name length that can be stored in the
+ * current path -- the inner loop allocates more path as necessary.
+ * We really wouldn't have to do the maxlen calculations here, we
+ * could do them in fts_read before returning the path, but it's a
+ * lot easier here since the length is part of the dirent structure.
+ *
+ * If not changing directories set a pointer so that can just append
+ * each new name into the path.
+ */
+ len = NAPPEND(cur);
+ if (ISSET(FTS_NOCHDIR)) {
+ cp = sp->fts_path + len;
+ *cp++ = '/';
+ }
+ len++;
+ maxlen = sp->fts_pathlen - len;
+
+ /*
+ * fts_level is signed so we must prevent it from wrapping
+ * around to FTS_ROOTLEVEL and FTS_ROOTPARENTLEVEL.
+ */
+ level = cur->fts_level;
+ if (level < FTS_MAXLEVEL)
+ level++;
+
+ /* Read the directory, attaching each entry to the `link' pointer. */
+ doadjust = 0;
+ for (head = tail = NULL, nitems = 0; dirp && (dp = readdir(dirp));) {
+ if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
+ continue;
+
+ namlen = strlen(dp->d_name);
+ if (!(p = fts_alloc(sp, dp->d_name, namlen)))
+ goto mem1;
+ if (namlen >= maxlen) { /* include space for NUL */
+ oldaddr = sp->fts_path;
+ if (fts_palloc(sp, namlen +len + 1)) {
+ /*
+ * No more memory for path or structures. Save
+ * errno, free up the current structure and the
+ * structures already allocated.
+ */
+mem1: saved_errno = errno;
+ free(p);
+ fts_lfree(head);
+ (void)closedir(dirp);
+ cur->fts_info = FTS_ERR;
+ SET(FTS_STOP);
+ errno = saved_errno;
+ return (NULL);
+ }
+ /* Did realloc() change the pointer? */
+ if (oldaddr != sp->fts_path) {
+ doadjust = 1;
+ if (ISSET(FTS_NOCHDIR))
+ cp = sp->fts_path + len;
+ }
+ maxlen = sp->fts_pathlen - len;
+ }
+
+ p->fts_level = level;
+ p->fts_parent = sp->fts_cur;
+ p->fts_pathlen = len + namlen;
+ if (p->fts_pathlen < len) {
+ /*
+ * If we wrap, free up the current structure and
+ * the structures already allocated, then error
+ * out with ENAMETOOLONG.
+ */
+ free(p);
+ fts_lfree(head);
+ (void)closedir(dirp);
+ cur->fts_info = FTS_ERR;
+ SET(FTS_STOP);
+ errno = ENAMETOOLONG;
+ return (NULL);
+ }
+
+ if (cderrno) {
+ if (nlinks) {
+ p->fts_info = FTS_NS;
+ p->fts_errno = cderrno;
+ } else
+ p->fts_info = FTS_NSOK;
+ p->fts_accpath = cur->fts_accpath;
+ } else if (nlinks == 0
+#ifdef DT_DIR
+ || (nostat &&
+ dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN)
+#endif
+ ) {
+ p->fts_accpath =
+ ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name;
+ p->fts_info = FTS_NSOK;
+ } else {
+ /* Build a file name for fts_stat to stat. */
+ if (ISSET(FTS_NOCHDIR)) {
+ p->fts_accpath = p->fts_path;
+ memmove(cp, p->fts_name, p->fts_namelen + 1);
+ p->fts_info = fts_stat(sp, p, 0, dirfd(dirp));
+ } else {
+ p->fts_accpath = p->fts_name;
+ p->fts_info = fts_stat(sp, p, 0, -1);
+ }
+
+ /* Decrement link count if applicable. */
+ if (nlinks > 0 && (p->fts_info == FTS_D ||
+ p->fts_info == FTS_DC || p->fts_info == FTS_DOT))
+ --nlinks;
+ }
+
+ /* We walk in directory order so "ls -f" doesn't get upset. */
+ p->fts_link = NULL;
+ if (head == NULL)
+ head = tail = p;
+ else {
+ tail->fts_link = p;
+ tail = p;
+ }
+ ++nitems;
+ }
+ if (dirp)
+ (void)closedir(dirp);
+
+ /*
+ * If realloc() changed the address of the path, adjust the
+ * addresses for the rest of the tree and the dir list.
+ */
+ if (doadjust)
+ fts_padjust(sp, head);
+
+ /*
+ * If not changing directories, reset the path back to original
+ * state.
+ */
+ if (ISSET(FTS_NOCHDIR)) {
+ if (len == sp->fts_pathlen || nitems == 0)
+ --cp;
+ *cp = '\0';
+ }
+
+ /*
+ * If descended after called from fts_children or after called from
+ * fts_read and nothing found, get back. At the root level we use
+ * the saved fd; if one of fts_open()'s arguments is a relative path
+ * to an empty directory, we wind up here with no other way back. If
+ * can't get back, we're done.
+ */
+ if (descend && (type == BCHILD || !nitems) &&
+ (cur->fts_level == FTS_ROOTLEVEL ? FCHDIR(sp, sp->fts_rfd) :
+ fts_safe_changedir(sp, cur->fts_parent, -1, ".."))) {
+ cur->fts_info = FTS_ERR;
+ SET(FTS_STOP);
+ return (NULL);
+ }
+
+ /* If didn't find anything, return NULL. */
+ if (!nitems) {
+ if (type == BREAD)
+ cur->fts_info = FTS_DP;
+ return (NULL);
+ }
+
+ /* Sort the entries. */
+ if (sp->fts_compar && nitems > 1)
+ head = fts_sort(sp, head, nitems);
+ return (head);
+}
+
+static u_short
+fts_stat(FTS *sp, FTSENT *p, int follow, int dfd)
+{
+ FTSENT *t;
+ dev_t dev;
+ ino_t ino;
+ struct stat *sbp, sb;
+ int saved_errno;
+ const char *path;
+
+ if (dfd == -1) {
+ path = p->fts_accpath;
+ dfd = AT_FDCWD;
+ } else
+ path = p->fts_name;
+
+ /* If user needs stat info, stat buffer already allocated. */
+ sbp = ISSET(FTS_NOSTAT) ? &sb : p->fts_statp;
+
+ /*
+ * If doing a logical walk, or application requested FTS_FOLLOW, do
+ * a stat(2). If that fails, check for a non-existent symlink. If
+ * fail, set the errno from the stat call.
+ */
+ if (ISSET(FTS_LOGICAL) || follow) {
+ if (fstatat(dfd, path, sbp, 0)) {
+ saved_errno = errno;
+ if (!fstatat(dfd, path, sbp, AT_SYMLINK_NOFOLLOW)) {
+ errno = 0;
+ return (FTS_SLNONE);
+ }
+ p->fts_errno = saved_errno;
+ goto err;
+ }
+ } else if (fstatat(dfd, path, sbp, AT_SYMLINK_NOFOLLOW)) {
+ p->fts_errno = errno;
+err: memset(sbp, 0, sizeof(struct stat));
+ return (FTS_NS);
+ }
+
+ if (S_ISDIR(sbp->st_mode)) {
+ /*
+ * Set the device/inode. Used to find cycles and check for
+ * crossing mount points. Also remember the link count, used
+ * in fts_build to limit the number of stat calls. It is
+ * understood that these fields are only referenced if fts_info
+ * is set to FTS_D.
+ */
+ dev = p->fts_dev = sbp->st_dev;
+ ino = p->fts_ino = sbp->st_ino;
+ p->fts_nlink = sbp->st_nlink;
+
+ if (ISDOT(p->fts_name))
+ return (FTS_DOT);
+
+ /*
+ * Cycle detection is done by brute force when the directory
+ * is first encountered. If the tree gets deep enough or the
+ * number of symbolic links to directories is high enough,
+ * something faster might be worthwhile.
+ */
+ for (t = p->fts_parent;
+ t->fts_level >= FTS_ROOTLEVEL; t = t->fts_parent)
+ if (ino == t->fts_ino && dev == t->fts_dev) {
+ p->fts_cycle = t;
+ return (FTS_DC);
+ }
+ return (FTS_D);
+ }
+ if (S_ISLNK(sbp->st_mode))
+ return (FTS_SL);
+ if (S_ISREG(sbp->st_mode))
+ return (FTS_F);
+ return (FTS_DEFAULT);
+}
+
+static FTSENT *
+fts_sort(FTS *sp, FTSENT *head, int nitems)
+{
+ FTSENT **ap, *p;
+
+ /*
+ * Construct an array of pointers to the structures and call qsort(3).
+ * Reassemble the array in the order returned by qsort. If unable to
+ * sort for memory reasons, return the directory entries in their
+ * current order. Allocate enough space for the current needs plus
+ * 40 so don't realloc one entry at a time.
+ */
+ if (nitems > sp->fts_nitems) {
+ struct _ftsent **a;
+
+ if ((a = reallocarray(sp->fts_array,
+ nitems + 40, sizeof(FTSENT *))) == NULL) {
+ free(sp->fts_array);
+ sp->fts_array = NULL;
+ sp->fts_nitems = 0;
+ return (head);
+ }
+ sp->fts_nitems = nitems + 40;
+ sp->fts_array = a;
+ }
+ for (ap = sp->fts_array, p = head; p; p = p->fts_link)
+ *ap++ = p;
+ qsort(sp->fts_array, nitems, sizeof(FTSENT *), sp->fts_compar);
+ for (head = *(ap = sp->fts_array); --nitems; ++ap)
+ ap[0]->fts_link = ap[1];
+ ap[0]->fts_link = NULL;
+ return (head);
+}
+
+static FTSENT *
+fts_alloc(FTS *sp, char *name, size_t namelen)
+{
+ FTSENT *p;
+ size_t len;
+
+ /*
+ * The file name is a variable length array and no stat structure is
+ * necessary if the user has set the nostat bit. Allocate the FTSENT
+ * structure, the file name and the stat structure in one chunk, but
+ * be careful that the stat structure is reasonably aligned. Since the
+ * fts_name field is declared to be of size 1, the fts_name pointer is
+ * namelen + 2 before the first possible address of the stat structure.
+ */
+ len = sizeof(FTSENT) + namelen;
+ if (!ISSET(FTS_NOSTAT))
+ len += sizeof(struct stat) + ALIGNBYTES;
+ if ((p = calloc(1, len)) == NULL)
+ return (NULL);
+
+ p->fts_path = sp->fts_path;
+ p->fts_namelen = namelen;
+ p->fts_instr = FTS_NOINSTR;
+ if (!ISSET(FTS_NOSTAT))
+ p->fts_statp = (struct stat *)ALIGN(p->fts_name + namelen + 2);
+ memcpy(p->fts_name, name, namelen);
+
+ return (p);
+}
+
+static void
+fts_lfree(FTSENT *head)
+{
+ FTSENT *p;
+
+ /* Free a linked list of structures. */
+ while ((p = head)) {
+ head = head->fts_link;
+ free(p);
+ }
+}
+
+/*
+ * Allow essentially unlimited paths; find, rm, ls should all work on any tree.
+ * Most systems will allow creation of paths much longer than PATH_MAX, even
+ * though the kernel won't resolve them. Add the size (not just what's needed)
+ * plus 256 bytes so don't realloc the path 2 bytes at a time.
+ */
+static int
+fts_palloc(FTS *sp, size_t more)
+{
+ char *p;
+
+ /*
+ * Check for possible wraparound.
+ */
+ more += 256;
+ if (sp->fts_pathlen + more < sp->fts_pathlen) {
+ free(sp->fts_path);
+ sp->fts_path = NULL;
+ errno = ENAMETOOLONG;
+ return (1);
+ }
+ p = recallocarray(sp->fts_path, sp->fts_pathlen,
+ sp->fts_pathlen + more, 1);
+ if (p == NULL) {
+ free(sp->fts_path);
+ sp->fts_path = NULL;
+ return (1);
+ }
+ sp->fts_pathlen += more;
+ sp->fts_path = p;
+ return (0);
+}
+
+/*
+ * When the path is realloc'd, have to fix all of the pointers in structures
+ * already returned.
+ */
+static void
+fts_padjust(FTS *sp, FTSENT *head)
+{
+ FTSENT *p;
+ char *addr = sp->fts_path;
+
+#define ADJUST(p) { \
+ if ((p)->fts_accpath != (p)->fts_name) { \
+ (p)->fts_accpath = \
+ (char *)addr + ((p)->fts_accpath - (p)->fts_path); \
+ } \
+ (p)->fts_path = addr; \
+}
+ /* Adjust the current set of children. */
+ for (p = sp->fts_child; p; p = p->fts_link)
+ ADJUST(p);
+
+ /* Adjust the rest of the tree, including the current level. */
+ for (p = head; p->fts_level >= FTS_ROOTLEVEL;) {
+ ADJUST(p);
+ p = p->fts_link ? p->fts_link : p->fts_parent;
+ }
+}
+
+static size_t
+fts_maxarglen(char * const *argv)
+{
+ size_t len, max;
+
+ for (max = 0; *argv; ++argv)
+ if ((len = strlen(*argv)) > max)
+ max = len;
+ return (max + 1);
+}
+
+/*
+ * Change to dir specified by fd or p->fts_accpath without getting
+ * tricked by someone changing the world out from underneath us.
+ * Assumes p->fts_dev and p->fts_ino are filled in.
+ */
+static int
+fts_safe_changedir(FTS *sp, FTSENT *p, int fd, char *path)
+{
+ int ret, oerrno, newfd;
+ struct stat sb;
+
+ newfd = fd;
+ if (ISSET(FTS_NOCHDIR))
+ return (0);
+ if (fd == -1 && (newfd = open(path, O_RDONLY|O_DIRECTORY|O_CLOEXEC)) == -1)
+ return (-1);
+ if (fstat(newfd, &sb) == -1) {
+ ret = -1;
+ goto bail;
+ }
+ if (p->fts_dev != sb.st_dev || p->fts_ino != sb.st_ino) {
+ errno = ENOENT; /* disinformation */
+ ret = -1;
+ goto bail;
+ }
+ ret = fchdir(newfd);
+bail:
+ oerrno = errno;
+ if (fd == -1)
+ (void)close(newfd);
+ errno = oerrno;
+ return (ret);
+}
diff --git a/lib/libc/gen/getprogname.c b/lib/libc/gen/getprogname.c
new file mode 100644
index 0000000..a020830
--- /dev/null
+++ b/lib/libc/gen/getprogname.c
@@ -0,0 +1,24 @@
+/* $OpenBSD: getprogname.c,v 1.4 2016/03/13 18:34:20 guenther Exp $ */
+/*
+ * Copyright (c) 2013 Antoine Jacoutot <ajacoutot@openbsd.org>
+ *
+ * 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 <stdlib.h>
+
+const char *
+getprogname(void)
+{
+ return (__progname);
+}
diff --git a/lib/libc/gen/pwcache.c b/lib/libc/gen/pwcache.c
new file mode 100644
index 0000000..2f30f4b
--- /dev/null
+++ b/lib/libc/gen/pwcache.c
@@ -0,0 +1,433 @@
+/* $OpenBSD: pwcache.c,v 1.15 2018/09/22 02:47:23 millert Exp $ */
+
+/*-
+ * Copyright (c) 1992 Keith Muller.
+ * Copyright (c) 1992, 1993
+ * 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.
+ *
+ * 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/types.h>
+
+#include <assert.h>
+#include <grp.h>
+#include <pwd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+/*
+ * Constants and data structures used to implement group and password file
+ * caches. Name lengths have been chosen to be as large as those supported
+ * by the passwd and group files as well as the standard archive formats.
+ * CACHE SIZES MUST BE PRIME
+ */
+#define UNMLEN 32 /* >= user name found in any protocol */
+#define GNMLEN 32 /* >= group name found in any protocol */
+#define UID_SZ 317 /* size of uid to user_name cache */
+#define UNM_SZ 317 /* size of user_name to uid cache */
+#define GID_SZ 251 /* size of gid to group_name cache */
+#define GNM_SZ 251 /* size of group_name to gid cache */
+#define VALID 1 /* entry and name are valid */
+#define INVALID 2 /* entry valid, name NOT valid */
+
+/*
+ * Node structures used in the user, group, uid, and gid caches.
+ */
+
+typedef struct uidc {
+ int valid; /* is this a valid or a miss entry */
+ char name[UNMLEN]; /* uid name */
+ uid_t uid; /* cached uid */
+} UIDC;
+
+typedef struct gidc {
+ int valid; /* is this a valid or a miss entry */
+ char name[GNMLEN]; /* gid name */
+ gid_t gid; /* cached gid */
+} GIDC;
+
+/*
+ * Routines that control user, group, uid and gid caches.
+ * Traditional passwd/group cache routines perform quite poorly with
+ * archives. The chances of hitting a valid lookup with an archive is quite a
+ * bit worse than with files already resident on the file system. These misses
+ * create a MAJOR performance cost. To adress this problem, these routines
+ * cache both hits and misses.
+ */
+
+static UIDC **uidtb; /* uid to name cache */
+static GIDC **gidtb; /* gid to name cache */
+static UIDC **usrtb; /* user name to uid cache */
+static GIDC **grptb; /* group name to gid cache */
+
+static u_int
+st_hash(const char *name, size_t len, int tabsz)
+{
+ u_int key = 0;
+
+ assert(name != NULL);
+
+ while (len--) {
+ key += *name++;
+ key = (key << 8) | (key >> 24);
+ }
+
+ return key % tabsz;
+}
+
+/*
+ * uidtb_start
+ * creates an an empty uidtb
+ * Return:
+ * 0 if ok, -1 otherwise
+ */
+static int
+uidtb_start(void)
+{
+ static int fail = 0;
+
+ if (uidtb != NULL)
+ return 0;
+ if (fail)
+ return -1;
+ if ((uidtb = calloc(UID_SZ, sizeof(UIDC *))) == NULL) {
+ ++fail;
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * gidtb_start
+ * creates an an empty gidtb
+ * Return:
+ * 0 if ok, -1 otherwise
+ */
+static int
+gidtb_start(void)
+{
+ static int fail = 0;
+
+ if (gidtb != NULL)
+ return 0;
+ if (fail)
+ return -1;
+ if ((gidtb = calloc(GID_SZ, sizeof(GIDC *))) == NULL) {
+ ++fail;
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * usrtb_start
+ * creates an an empty usrtb
+ * Return:
+ * 0 if ok, -1 otherwise
+ */
+static int
+usrtb_start(void)
+{
+ static int fail = 0;
+
+ if (usrtb != NULL)
+ return 0;
+ if (fail)
+ return -1;
+ if ((usrtb = calloc(UNM_SZ, sizeof(UIDC *))) == NULL) {
+ ++fail;
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * grptb_start
+ * creates an an empty grptb
+ * Return:
+ * 0 if ok, -1 otherwise
+ */
+static int
+grptb_start(void)
+{
+ static int fail = 0;
+
+ if (grptb != NULL)
+ return 0;
+ if (fail)
+ return -1;
+ if ((grptb = calloc(GNM_SZ, sizeof(GIDC *))) == NULL) {
+ ++fail;
+ return -1;
+ }
+ return 0;
+}
+
+/*
+ * user_from_uid()
+ * caches the name (if any) for the uid. If noname clear, we always
+ * return the stored name (if valid or invalid match).
+ * We use a simple hash table.
+ * Return:
+ * Pointer to stored name (or a empty string)
+ */
+const char *
+user_from_uid(uid_t uid, int noname)
+{
+ struct passwd *pw;
+ UIDC **pptr, *ptr = NULL;
+
+ if ((uidtb != NULL) || (uidtb_start() == 0)) {
+ /*
+ * see if we have this uid cached
+ */
+ pptr = uidtb + (uid % UID_SZ);
+ ptr = *pptr;
+
+ if ((ptr != NULL) && (ptr->valid > 0) && (ptr->uid == uid)) {
+ /*
+ * have an entry for this uid
+ */
+ if (!noname || (ptr->valid == VALID))
+ return ptr->name;
+ return NULL;
+ }
+
+ if (ptr == NULL)
+ *pptr = ptr = malloc(sizeof(UIDC));
+ }
+
+ pw = getpwuid(uid);
+ if (pw == NULL) {
+ /*
+ * no match for this uid in the local password file
+ * a string that is the uid in numeric format
+ */
+ if (ptr == NULL)
+ return NULL;
+ ptr->uid = uid;
+ (void)snprintf(ptr->name, UNMLEN, "%u", uid);
+ ptr->valid = INVALID;
+ if (noname)
+ return NULL;
+ } else {
+ /*
+ * there is an entry for this uid in the password file
+ */
+ if (ptr == NULL)
+ return pw->pw_name;
+ ptr->uid = uid;
+ (void)strlcpy(ptr->name, pw->pw_name, sizeof(ptr->name));
+ ptr->valid = VALID;
+ }
+ return ptr->name;
+}
+
+/*
+ * group_from_gid()
+ * caches the name (if any) for the gid. If noname clear, we always
+ * return the stored name (if valid or invalid match).
+ * We use a simple hash table.
+ * Return:
+ * Pointer to stored name (or a empty string)
+ */
+const char *
+group_from_gid(gid_t gid, int noname)
+{
+ struct group *gr;
+ GIDC **pptr, *ptr = NULL;
+
+ if ((gidtb != NULL) || (gidtb_start() == 0)) {
+ /*
+ * see if we have this gid cached
+ */
+ pptr = gidtb + (gid % GID_SZ);
+ ptr = *pptr;
+
+ if ((ptr != NULL) && (ptr->valid > 0) && (ptr->gid == gid)) {
+ /*
+ * have an entry for this gid
+ */
+ if (!noname || (ptr->valid == VALID))
+ return ptr->name;
+ return NULL;
+ }
+
+ if (ptr == NULL)
+ *pptr = ptr = malloc(sizeof(GIDC));
+ }
+
+ gr = getgrgid(gid);
+ if (gr == NULL) {
+ /*
+ * no match for this gid in the local group file, put in
+ * a string that is the gid in numeric format
+ */
+ if (ptr == NULL)
+ return NULL;
+ ptr->gid = gid;
+ (void)snprintf(ptr->name, GNMLEN, "%u", gid);
+ ptr->valid = INVALID;
+ if (noname)
+ return NULL;
+ } else {
+ /*
+ * there is an entry for this group in the group file
+ */
+ if (ptr == NULL)
+ return gr->gr_name;
+ ptr->gid = gid;
+ (void)strlcpy(ptr->name, gr->gr_name, sizeof(ptr->name));
+ ptr->valid = VALID;
+ }
+ return ptr->name;
+}
+
+/*
+ * uid_from_user()
+ * caches the uid for a given user name. We use a simple hash table.
+ * Return:
+ * 0 if the user name is found (filling in uid), -1 otherwise
+ */
+int
+uid_from_user(const char *name, uid_t *uid)
+{
+ struct passwd *pw;
+ UIDC **pptr, *ptr = NULL;
+ size_t namelen;
+
+ /*
+ * return -1 for mangled names
+ */
+ if (name == NULL || ((namelen = strlen(name)) == 0))
+ return -1;
+
+ if ((usrtb != NULL) || (usrtb_start() == 0)) {
+ /*
+ * look up in hash table, if found and valid return the uid,
+ * if found and invalid, return a -1
+ */
+ pptr = usrtb + st_hash(name, namelen, UNM_SZ);
+ ptr = *pptr;
+
+ if ((ptr != NULL) && (ptr->valid > 0) &&
+ strcmp(name, ptr->name) == 0) {
+ if (ptr->valid == INVALID)
+ return -1;
+ *uid = ptr->uid;
+ return 0;
+ }
+
+ if (ptr == NULL)
+ *pptr = ptr = malloc(sizeof(UIDC));
+ }
+
+ /*
+ * no match, look it up, if no match store it as an invalid entry,
+ * or store the matching uid
+ */
+ pw = getpwnam(name);
+ if (ptr == NULL) {
+ if (pw == NULL)
+ return -1;
+ *uid = pw->pw_uid;
+ return 0;
+ }
+ (void)strlcpy(ptr->name, name, sizeof(ptr->name));
+ if (pw == NULL) {
+ ptr->valid = INVALID;
+ return -1;
+ }
+ ptr->valid = VALID;
+ *uid = ptr->uid = pw->pw_uid;
+ return 0;
+}
+
+/*
+ * gid_from_group()
+ * caches the gid for a given group name. We use a simple hash table.
+ * Return:
+ * 0 if the group name is found (filling in gid), -1 otherwise
+ */
+int
+gid_from_group(const char *name, gid_t *gid)
+{
+ struct group *gr;
+ GIDC **pptr, *ptr = NULL;
+ size_t namelen;
+
+ /*
+ * return -1 for mangled names
+ */
+ if (name == NULL || ((namelen = strlen(name)) == 0))
+ return -1;
+
+ if ((grptb != NULL) || (grptb_start() == 0)) {
+ /*
+ * look up in hash table, if found and valid return the uid,
+ * if found and invalid, return a -1
+ */
+ pptr = grptb + st_hash(name, namelen, GID_SZ);
+ ptr = *pptr;
+
+ if ((ptr != NULL) && (ptr->valid > 0) &&
+ strcmp(name, ptr->name) == 0) {
+ if (ptr->valid == INVALID)
+ return -1;
+ *gid = ptr->gid;
+ return 0;
+ }
+
+ if (ptr == NULL)
+ *pptr = ptr = malloc(sizeof(GIDC));
+ }
+
+ /*
+ * no match, look it up, if no match store it as an invalid entry,
+ * or store the matching gid
+ */
+ gr = getgrnam(name);
+ if (ptr == NULL) {
+ if (gr == NULL)
+ return -1;
+ *gid = gr->gr_gid;
+ return 0;
+ }
+
+ (void)strlcpy(ptr->name, name, sizeof(ptr->name));
+ if (gr == NULL) {
+ ptr->valid = INVALID;
+ return -1;
+ }
+ ptr->valid = VALID;
+ *gid = ptr->gid = gr->gr_gid;
+ return 0;
+}
diff --git a/lib/libc/gen/readpassphrase.c b/lib/libc/gen/readpassphrase.c
new file mode 100644
index 0000000..e2a6121
--- /dev/null
+++ b/lib/libc/gen/readpassphrase.c
@@ -0,0 +1,190 @@
+/* $OpenBSD: readpassphrase.c,v 1.27 2019/01/25 00:19:25 millert Exp $ */
+
+/*
+ * Copyright (c) 2000-2002, 2007, 2010
+ * Todd C. Miller <millert@openbsd.org>
+ *
+ * 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.
+ *
+ * Sponsored in part by the Defense Advanced Research Projects
+ * Agency (DARPA) and Air Force Research Laboratory, Air Force
+ * Materiel Command, USAF, under agreement number F39502-99-1-0512.
+ */
+
+#include <ctype.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <paths.h>
+#include <pwd.h>
+#include <signal.h>
+#include <string.h>
+#include <termios.h>
+#include <unistd.h>
+#include <readpassphrase.h>
+
+#ifndef TCSASOFT
+#define TCSASOFT 0
+#endif
+
+static volatile sig_atomic_t signo[_NSIG];
+
+static void handler(int);
+
+char *
+readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags)
+{
+ ssize_t nr;
+ int input, output, save_errno, i, need_restart;
+ char ch, *p, *end;
+ struct termios term, oterm;
+ struct sigaction sa, savealrm, saveint, savehup, savequit, saveterm;
+ struct sigaction savetstp, savettin, savettou, savepipe;
+
+ /* I suppose we could alloc on demand in this case (XXX). */
+ if (bufsiz == 0) {
+ errno = EINVAL;
+ return(NULL);
+ }
+
+restart:
+ for (i = 0; i < _NSIG; i++)
+ signo[i] = 0;
+ nr = -1;
+ save_errno = 0;
+ need_restart = 0;
+ /*
+ * Read and write to /dev/tty if available. If not, read from
+ * stdin and write to stderr unless a tty is required.
+ */
+ if ((flags & RPP_STDIN) ||
+ (input = output = open(_PATH_TTY, O_RDWR)) == -1) {
+ if (flags & RPP_REQUIRE_TTY) {
+ errno = ENOTTY;
+ return(NULL);
+ }
+ input = STDIN_FILENO;
+ output = STDERR_FILENO;
+ }
+
+ /*
+ * Turn off echo if possible.
+ * If we are using a tty but are not the foreground pgrp this will
+ * generate SIGTTOU, so do it *before* installing the signal handlers.
+ */
+ if (input != STDIN_FILENO && tcgetattr(input, &oterm) == 0) {
+ memcpy(&term, &oterm, sizeof(term));
+ if (!(flags & RPP_ECHO_ON))
+ term.c_lflag &= ~(ECHO | ECHONL);
+#ifdef VSTATUS
+ if (term.c_cc[VSTATUS] != _POSIX_VDISABLE)
+ term.c_cc[VSTATUS] = _POSIX_VDISABLE;
+#endif
+ (void)tcsetattr(input, TCSAFLUSH|TCSASOFT, &term);
+ } else {
+ memset(&term, 0, sizeof(term));
+ term.c_lflag |= ECHO;
+ memset(&oterm, 0, sizeof(oterm));
+ oterm.c_lflag |= ECHO;
+ }
+
+ /*
+ * Catch signals that would otherwise cause the user to end
+ * up with echo turned off in the shell. Don't worry about
+ * things like SIGXCPU and SIGVTALRM for now.
+ */
+ sigemptyset(&sa.sa_mask);
+ sa.sa_flags = 0; /* don't restart system calls */
+ sa.sa_handler = handler;
+ (void)sigaction(SIGALRM, &sa, &savealrm);
+ (void)sigaction(SIGHUP, &sa, &savehup);
+ (void)sigaction(SIGINT, &sa, &saveint);
+ (void)sigaction(SIGPIPE, &sa, &savepipe);
+ (void)sigaction(SIGQUIT, &sa, &savequit);
+ (void)sigaction(SIGTERM, &sa, &saveterm);
+ (void)sigaction(SIGTSTP, &sa, &savetstp);
+ (void)sigaction(SIGTTIN, &sa, &savettin);
+ (void)sigaction(SIGTTOU, &sa, &savettou);
+
+ if (!(flags & RPP_STDIN))
+ (void)write(output, prompt, strlen(prompt));
+ end = buf + bufsiz - 1;
+ p = buf;
+ while ((nr = read(input, &ch, 1)) == 1 && ch != '\n' && ch != '\r') {
+ if (p < end) {
+ if ((flags & RPP_SEVENBIT))
+ ch &= 0x7f;
+ if (isalpha((unsigned char)ch)) {
+ if ((flags & RPP_FORCELOWER))
+ ch = (char)tolower((unsigned char)ch);
+ if ((flags & RPP_FORCEUPPER))
+ ch = (char)toupper((unsigned char)ch);
+ }
+ *p++ = ch;
+ }
+ }
+ *p = '\0';
+ save_errno = errno;
+ if (!(term.c_lflag & ECHO))
+ (void)write(output, "\n", 1);
+
+ /* Restore old terminal settings and signals. */
+ if (memcmp(&term, &oterm, sizeof(term)) != 0) {
+ const int sigttou = signo[SIGTTOU];
+
+ /* Ignore SIGTTOU generated when we are not the fg pgrp. */
+ while (tcsetattr(input, TCSAFLUSH|TCSASOFT, &oterm) == -1 &&
+ errno == EINTR && !signo[SIGTTOU])
+ continue;
+ signo[SIGTTOU] = sigttou;
+ }
+ (void)sigaction(SIGALRM, &savealrm, NULL);
+ (void)sigaction(SIGHUP, &savehup, NULL);
+ (void)sigaction(SIGINT, &saveint, NULL);
+ (void)sigaction(SIGQUIT, &savequit, NULL);
+ (void)sigaction(SIGPIPE, &savepipe, NULL);
+ (void)sigaction(SIGTERM, &saveterm, NULL);
+ (void)sigaction(SIGTSTP, &savetstp, NULL);
+ (void)sigaction(SIGTTIN, &savettin, NULL);
+ (void)sigaction(SIGTTOU, &savettou, NULL);
+ if (input != STDIN_FILENO)
+ (void)close(input);
+
+ /*
+ * If we were interrupted by a signal, resend it to ourselves
+ * now that we have restored the signal handlers.
+ */
+ for (i = 0; i < _NSIG; i++) {
+ if (signo[i]) {
+ kill(getpid(), i);
+ switch (i) {
+ case SIGTSTP:
+ case SIGTTIN:
+ case SIGTTOU:
+ need_restart = 1;
+ }
+ }
+ }
+ if (need_restart)
+ goto restart;
+
+ if (save_errno)
+ errno = save_errno;
+ return(nr == -1 ? NULL : buf);
+}
+DEF_WEAK(readpassphrase);
+
+static void
+handler(int s)
+{
+ signo[s] = 1;
+}
diff --git a/lib/libc/gen/setprogname.c b/lib/libc/gen/setprogname.c
new file mode 100644
index 0000000..0c1573c
--- /dev/null
+++ b/lib/libc/gen/setprogname.c
@@ -0,0 +1,31 @@
+/* $OpenBSD: setprogname.c,v 1.6 2017/09/17 06:38:03 otto Exp $ */
+/*
+ * Copyright (c) 2013 Antoine Jacoutot <ajacoutot@openbsd.org>
+ *
+ * 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 <string.h>
+#include <stdlib.h>
+
+void
+setprogname(const char *progname)
+{
+ char *tmpn;
+
+ tmpn = strrchr(progname, '/');
+ if (tmpn == NULL)
+ __progname = (char *)progname;
+ else
+ __progname = (char *)tmpn + 1;
+}
diff --git a/lib/libc/gen/unvis.c b/lib/libc/gen/unvis.c
new file mode 100644
index 0000000..05749aa
--- /dev/null
+++ b/lib/libc/gen/unvis.c
@@ -0,0 +1,286 @@
+/* $OpenBSD: unvis.c,v 1.17 2015/09/13 11:32:51 guenther Exp $ */
+/*-
+ * 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.
+ * 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/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 isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
+
+/*
+ * unvis - decode characters previously encoded by vis
+ */
+int
+unvis(char *cp, char 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) {
+
+ case S_GROUND:
+ *cp = 0;
+ if (c == '\\') {
+ *astate = S_START;
+ return (0);
+ }
+ *cp = c;
+ return (UNVIS_VALID);
+
+ case S_START:
+ switch(c) {
+ case '-':
+ *cp = 0;
+ *astate = S_GROUND;
+ return (0);
+ case '\\':
+ 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 = (char) 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);
+
+ default:
+ /*
+ * decoder in unknown state - (probably uninitialized)
+ */
+ *astate = S_GROUND;
+ return (UNVIS_SYNBAD);
+ }
+}
+DEF_WEAK(unvis);
+
+/*
+ * 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:
+ *dst = '\0';
+ return (-1);
+ }
+ }
+ if (unvis(dst, c, &state, UNVIS_END) == UNVIS_VALID)
+ dst++;
+ *dst = '\0';
+ return (dst - start);
+}
+
+ssize_t
+strnunvis(char *dst, const char *src, size_t sz)
+{
+ char c, p;
+ char *start = dst, *end = dst + sz - 1;
+ int state = 0;
+
+ if (sz > 0)
+ *end = '\0';
+ while ((c = *src++)) {
+ again:
+ switch (unvis(&p, c, &state, 0)) {
+ case UNVIS_VALID:
+ if (dst < end)
+ *dst = p;
+ dst++;
+ break;
+ case UNVIS_VALIDPUSH:
+ if (dst < end)
+ *dst = p;
+ dst++;
+ goto again;
+ case 0:
+ case UNVIS_NOCHAR:
+ break;
+ default:
+ if (dst <= end)
+ *dst = '\0';
+ return (-1);
+ }
+ }
+ if (unvis(&p, c, &state, UNVIS_END) == UNVIS_VALID) {
+ if (dst < end)
+ *dst = p;
+ dst++;
+ }
+ if (dst <= end)
+ *dst = '\0';
+ return (dst - start);
+}
+
diff --git a/lib/libc/gen/vis.c b/lib/libc/gen/vis.c
new file mode 100644
index 0000000..4400c7b
--- /dev/null
+++ b/lib/libc/gen/vis.c
@@ -0,0 +1,243 @@
+/* $OpenBSD: vis.c,v 1.25 2015/09/13 11:32:51 guenther Exp $ */
+/*-
+ * 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.
+ * 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/types.h>
+#include <errno.h>
+#include <ctype.h>
+#include <limits.h>
+#include <string.h>
+#include <stdlib.h>
+#include <vis.h>
+
+#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
+#define isvisible(c,flag) \
+ (((c) == '\\' || (flag & VIS_ALL) == 0) && \
+ (((u_int)(c) <= UCHAR_MAX && isascii((u_char)(c)) && \
+ (((c) != '*' && (c) != '?' && (c) != '[' && (c) != '#') || \
+ (flag & VIS_GLOB) == 0) && isgraph((u_char)(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' || \
+ isgraph((u_char)(c))))))
+
+/*
+ * vis - visually encode characters
+ */
+char *
+vis(char *dst, int c, int flag, int nextc)
+{
+ if (isvisible(c, flag)) {
+ if ((c == '"' && (flag & VIS_DQ) != 0) ||
+ (c == '\\' && (flag & VIS_NOSLASH) == 0))
+ *dst++ = '\\';
+ *dst++ = c;
+ *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) == ' ') || (flag & VIS_OCTAL) ||
+ ((flag & VIS_GLOB) && (c == '*' || c == '?' || c == '[' || c == '#'))) {
+ *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((u_char)c)) {
+ *dst++ = '^';
+ if (c == 0177)
+ *dst++ = '?';
+ else
+ *dst++ = c + '@';
+ } else {
+ *dst++ = '-';
+ *dst++ = c;
+ }
+done:
+ *dst = '\0';
+ return (dst);
+}
+DEF_WEAK(vis);
+
+/*
+ * strvis, strnvis, 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 NULL,
+ * is returned.
+ *
+ * Strnvis will write no more than siz-1 bytes (and will NULL terminate).
+ * The number of bytes needed to fully encode the string is returned.
+ *
+ * Strvisx encodes exactly len bytes from src into dst.
+ * This is useful for encoding a block of data.
+ */
+int
+strvis(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);
+}
+DEF_WEAK(strvis);
+
+int
+strnvis(char *dst, const char *src, size_t siz, int flag)
+{
+ char *start, *end;
+ char tbuf[5];
+ int c, i;
+
+ i = 0;
+ for (start = dst, end = start + siz - 1; (c = *src) && dst < end; ) {
+ if (isvisible(c, flag)) {
+ if ((c == '"' && (flag & VIS_DQ) != 0) ||
+ (c == '\\' && (flag & VIS_NOSLASH) == 0)) {
+ /* need space for the extra '\\' */
+ if (dst + 1 >= end) {
+ i = 2;
+ break;
+ }
+ *dst++ = '\\';
+ }
+ i = 1;
+ *dst++ = c;
+ src++;
+ } else {
+ i = vis(tbuf, c, flag, *++src) - tbuf;
+ if (dst + i <= end) {
+ memcpy(dst, tbuf, i);
+ dst += i;
+ } else {
+ src--;
+ break;
+ }
+ }
+ }
+ if (siz > 0)
+ *dst = '\0';
+ if (dst + i > end) {
+ /* adjust return value for truncation */
+ while ((c = *src))
+ dst += vis(tbuf, c, flag, *++src) - tbuf;
+ }
+ return (dst - start);
+}
+
+int
+stravis(char **outp, const char *src, int flag)
+{
+ char *buf;
+ int len, serrno;
+
+ buf = reallocarray(NULL, 4, strlen(src) + 1);
+ if (buf == NULL)
+ return -1;
+ len = strvis(buf, src, flag);
+ serrno = errno;
+ *outp = realloc(buf, len + 1);
+ if (*outp == NULL) {
+ *outp = buf;
+ errno = serrno;
+ }
+ return (len);
+}
+
+int
+strvisx(char *dst, const char *src, size_t len, int flag)
+{
+ char 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/vwarnc.c b/lib/libc/gen/vwarnc.c
new file mode 100644
index 0000000..e528de3
--- /dev/null
+++ b/lib/libc/gen/vwarnc.c
@@ -0,0 +1,47 @@
+/* $OpenBSD: vwarnc.c,v 1.3 2016/03/13 18:34:20 guenther Exp $ */
+/*-
+ * Copyright (c) 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.
+ */
+
+#include <err.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+
+void
+vwarnc(int code, const char *fmt, va_list ap)
+{
+ (void)fprintf(stderr, "%s: ", __progname);
+ if (fmt != NULL) {
+ (void)vfprintf(stderr, fmt, ap);
+ (void)fprintf(stderr, ": ");
+ }
+ (void)fprintf(stderr, "%s\n", strerror(code));
+}
+DEF_WEAK(vwarnc);
diff --git a/lib/libc/gen/warnc.c b/lib/libc/gen/warnc.c
new file mode 100644
index 0000000..bbda54b
--- /dev/null
+++ b/lib/libc/gen/warnc.c
@@ -0,0 +1,43 @@
+/* $OpenBSD: warnc.c,v 1.2 2015/08/31 02:53:57 guenther Exp $ */
+/*-
+ * Copyright (c) 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.
+ */
+
+#include <err.h>
+#include <stdarg.h>
+
+void
+warnc(int code, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ vwarnc(code, fmt, ap);
+ va_end(ap);
+}
+DEF_WEAK(warnc);
diff --git a/lib/libc/hash/helper.c b/lib/libc/hash/helper.c
new file mode 100644
index 0000000..06e8060
--- /dev/null
+++ b/lib/libc/hash/helper.c
@@ -0,0 +1,118 @@
+/* $OpenBSD: helper.c,v 1.18 2019/06/28 13:32:41 deraadt Exp $ */
+
+/*
+ * Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org>
+ *
+ * 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.
+ */
+
+/*
+ * 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/types.h>
+#include <sys/cdefs.h>
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <hashinc>
+
+#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b))
+
+char *
+HASHEnd(HASH_CTX *ctx, char *buf)
+{
+ int i;
+ u_int8_t digest[HASH_DIGEST_LENGTH];
+ static const char hex[] = "0123456789abcdef";
+
+ if (buf == NULL && (buf = malloc(HASH_DIGEST_STRING_LENGTH)) == NULL)
+ return (NULL);
+
+ HASHFinal(digest, ctx);
+ for (i = 0; i < HASH_DIGEST_LENGTH; i++) {
+ buf[i + i] = hex[digest[i] >> 4];
+ buf[i + i + 1] = hex[digest[i] & 0x0f];
+ }
+ buf[i + i] = '\0';
+ explicit_bzero(digest, sizeof(digest));
+ return (buf);
+}
+DEF_WEAK(HASHEnd);
+
+char *
+HASHFileChunk(const char *filename, char *buf, off_t off, off_t len)
+{
+ struct stat sb;
+ u_char buffer[BUFSIZ];
+ HASH_CTX ctx;
+ int fd, save_errno;
+ ssize_t nr;
+
+ HASHInit(&ctx);
+
+ if ((fd = open(filename, O_RDONLY)) == -1)
+ return (NULL);
+ if (len == 0) {
+ if (fstat(fd, &sb) == -1) {
+ save_errno = errno;
+ close(fd);
+ errno = save_errno;
+ return (NULL);
+ }
+ len = sb.st_size;
+ }
+ if (off > 0 && lseek(fd, off, SEEK_SET) == -1) {
+ save_errno = errno;
+ close(fd);
+ errno = save_errno;
+ return (NULL);
+ }
+
+ while ((nr = read(fd, buffer, MINIMUM(sizeof(buffer), len))) > 0) {
+ HASHUpdate(&ctx, buffer, nr);
+ if (len > 0 && (len -= nr) == 0)
+ break;
+ }
+
+ save_errno = errno;
+ close(fd);
+ errno = save_errno;
+ return (nr == -1 ? NULL : HASHEnd(&ctx, buf));
+}
+DEF_WEAK(HASHFileChunk);
+
+char *
+HASHFile(const char *filename, char *buf)
+{
+ return (HASHFileChunk(filename, buf, 0, 0));
+}
+DEF_WEAK(HASHFile);
+
+char *
+HASHData(const u_char *data, size_t len, char *buf)
+{
+ HASH_CTX ctx;
+
+ HASHInit(&ctx);
+ HASHUpdate(&ctx, data, len);
+ return (HASHEnd(&ctx, buf));
+}
+DEF_WEAK(HASHData);
diff --git a/lib/libc/hash/md5.c b/lib/libc/hash/md5.c
new file mode 100644
index 0000000..97a444d
--- /dev/null
+++ b/lib/libc/hash/md5.c
@@ -0,0 +1,252 @@
+/* $OpenBSD: md5.c,v 1.11 2015/09/11 09:18:27 guenther Exp $ */
+
+/*
+ * This code implements the MD5 message-digest algorithm.
+ * The algorithm is due to Ron Rivest. This code was
+ * written by Colin Plumb in 1993, no copyright is claimed.
+ * This code is in the public domain; do with it what you wish.
+ *
+ * Equivalent code is available from RSA Data Security, Inc.
+ * This code has been tested against that, and is equivalent,
+ * except that you don't need to include two pages of legalese
+ * with every copy.
+ *
+ * To compute the message digest of a chunk of bytes, declare an
+ * MD5Context structure, pass it to MD5Init, call MD5Update as
+ * needed on buffers full of bytes, and then call MD5Final, which
+ * will fill a supplied 16-byte array with the digest.
+ */
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <string.h>
+#include <md5.h>
+
+#define PUT_64BIT_LE(cp, value) do { \
+ (cp)[7] = (value) >> 56; \
+ (cp)[6] = (value) >> 48; \
+ (cp)[5] = (value) >> 40; \
+ (cp)[4] = (value) >> 32; \
+ (cp)[3] = (value) >> 24; \
+ (cp)[2] = (value) >> 16; \
+ (cp)[1] = (value) >> 8; \
+ (cp)[0] = (value); } while (0)
+
+#define PUT_32BIT_LE(cp, value) do { \
+ (cp)[3] = (value) >> 24; \
+ (cp)[2] = (value) >> 16; \
+ (cp)[1] = (value) >> 8; \
+ (cp)[0] = (value); } while (0)
+
+static u_int8_t PADDING[MD5_BLOCK_LENGTH] = {
+ 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+/*
+ * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious
+ * initialization constants.
+ */
+void
+MD5Init(MD5_CTX *ctx)
+{
+ ctx->count = 0;
+ ctx->state[0] = 0x67452301;
+ ctx->state[1] = 0xefcdab89;
+ ctx->state[2] = 0x98badcfe;
+ ctx->state[3] = 0x10325476;
+}
+DEF_WEAK(MD5Init);
+
+/*
+ * Update context to reflect the concatenation of another buffer full
+ * of bytes.
+ */
+void
+MD5Update(MD5_CTX *ctx, const unsigned char *input, size_t len)
+{
+ size_t have, need;
+
+ /* Check how many bytes we already have and how many more we need. */
+ have = (size_t)((ctx->count >> 3) & (MD5_BLOCK_LENGTH - 1));
+ need = MD5_BLOCK_LENGTH - have;
+
+ /* Update bitcount */
+ ctx->count += (u_int64_t)len << 3;
+
+ if (len >= need) {
+ if (have != 0) {
+ memcpy(ctx->buffer + have, input, need);
+ MD5Transform(ctx->state, ctx->buffer);
+ input += need;
+ len -= need;
+ have = 0;
+ }
+
+ /* Process data in MD5_BLOCK_LENGTH-byte chunks. */
+ while (len >= MD5_BLOCK_LENGTH) {
+ MD5Transform(ctx->state, input);
+ input += MD5_BLOCK_LENGTH;
+ len -= MD5_BLOCK_LENGTH;
+ }
+ }
+
+ /* Handle any remaining bytes of data. */
+ if (len != 0)
+ memcpy(ctx->buffer + have, input, len);
+}
+DEF_WEAK(MD5Update);
+
+/*
+ * Pad pad to 64-byte boundary with the bit pattern
+ * 1 0* (64-bit count of bits processed, MSB-first)
+ */
+void
+MD5Pad(MD5_CTX *ctx)
+{
+ u_int8_t count[8];
+ size_t padlen;
+
+ /* Convert count to 8 bytes in little endian order. */
+ PUT_64BIT_LE(count, ctx->count);
+
+ /* Pad out to 56 mod 64. */
+ padlen = MD5_BLOCK_LENGTH -
+ ((ctx->count >> 3) & (MD5_BLOCK_LENGTH - 1));
+ if (padlen < 1 + 8)
+ padlen += MD5_BLOCK_LENGTH;
+ MD5Update(ctx, PADDING, padlen - 8); /* padlen - 8 <= 64 */
+ MD5Update(ctx, count, 8);
+}
+DEF_WEAK(MD5Pad);
+
+/*
+ * Final wrapup--call MD5Pad, fill in digest and zero out ctx.
+ */
+void
+MD5Final(unsigned char digest[MD5_DIGEST_LENGTH], MD5_CTX *ctx)
+{
+ int i;
+
+ MD5Pad(ctx);
+ for (i = 0; i < 4; i++)
+ PUT_32BIT_LE(digest + i * 4, ctx->state[i]);
+ explicit_bzero(ctx, sizeof(*ctx));
+}
+DEF_WEAK(MD5Final);
+
+
+/* The four core functions - F1 is optimized somewhat */
+
+/* #define F1(x, y, z) (x & y | ~x & z) */
+#define F1(x, y, z) (z ^ (x & (y ^ z)))
+#define F2(x, y, z) F1(z, x, y)
+#define F3(x, y, z) (x ^ y ^ z)
+#define F4(x, y, z) (y ^ (x | ~z))
+
+/* This is the central step in the MD5 algorithm. */
+#define MD5STEP(f, w, x, y, z, data, s) \
+ ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x )
+
+/*
+ * The core of the MD5 algorithm, this alters an existing MD5 hash to
+ * reflect the addition of 16 longwords of new data. MD5Update blocks
+ * the data and converts bytes into longwords for this routine.
+ */
+void
+MD5Transform(u_int32_t state[4], const u_int8_t block[MD5_BLOCK_LENGTH])
+{
+ u_int32_t a, b, c, d, in[MD5_BLOCK_LENGTH / 4];
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+ memcpy(in, block, sizeof(in));
+#else
+ for (a = 0; a < MD5_BLOCK_LENGTH / 4; a++) {
+ in[a] = (u_int32_t)(
+ (u_int32_t)(block[a * 4 + 0]) |
+ (u_int32_t)(block[a * 4 + 1]) << 8 |
+ (u_int32_t)(block[a * 4 + 2]) << 16 |
+ (u_int32_t)(block[a * 4 + 3]) << 24);
+ }
+#endif
+
+ a = state[0];
+ b = state[1];
+ c = state[2];
+ d = state[3];
+
+ MD5STEP(F1, a, b, c, d, in[ 0] + 0xd76aa478, 7);
+ MD5STEP(F1, d, a, b, c, in[ 1] + 0xe8c7b756, 12);
+ MD5STEP(F1, c, d, a, b, in[ 2] + 0x242070db, 17);
+ MD5STEP(F1, b, c, d, a, in[ 3] + 0xc1bdceee, 22);
+ MD5STEP(F1, a, b, c, d, in[ 4] + 0xf57c0faf, 7);
+ MD5STEP(F1, d, a, b, c, in[ 5] + 0x4787c62a, 12);
+ MD5STEP(F1, c, d, a, b, in[ 6] + 0xa8304613, 17);
+ MD5STEP(F1, b, c, d, a, in[ 7] + 0xfd469501, 22);
+ MD5STEP(F1, a, b, c, d, in[ 8] + 0x698098d8, 7);
+ MD5STEP(F1, d, a, b, c, in[ 9] + 0x8b44f7af, 12);
+ MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
+ MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
+ MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
+ MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
+ MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
+ MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
+
+ MD5STEP(F2, a, b, c, d, in[ 1] + 0xf61e2562, 5);
+ MD5STEP(F2, d, a, b, c, in[ 6] + 0xc040b340, 9);
+ MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
+ MD5STEP(F2, b, c, d, a, in[ 0] + 0xe9b6c7aa, 20);
+ MD5STEP(F2, a, b, c, d, in[ 5] + 0xd62f105d, 5);
+ MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
+ MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
+ MD5STEP(F2, b, c, d, a, in[ 4] + 0xe7d3fbc8, 20);
+ MD5STEP(F2, a, b, c, d, in[ 9] + 0x21e1cde6, 5);
+ MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
+ MD5STEP(F2, c, d, a, b, in[ 3] + 0xf4d50d87, 14);
+ MD5STEP(F2, b, c, d, a, in[ 8] + 0x455a14ed, 20);
+ MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
+ MD5STEP(F2, d, a, b, c, in[ 2] + 0xfcefa3f8, 9);
+ MD5STEP(F2, c, d, a, b, in[ 7] + 0x676f02d9, 14);
+ MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
+
+ MD5STEP(F3, a, b, c, d, in[ 5] + 0xfffa3942, 4);
+ MD5STEP(F3, d, a, b, c, in[ 8] + 0x8771f681, 11);
+ MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
+ MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
+ MD5STEP(F3, a, b, c, d, in[ 1] + 0xa4beea44, 4);
+ MD5STEP(F3, d, a, b, c, in[ 4] + 0x4bdecfa9, 11);
+ MD5STEP(F3, c, d, a, b, in[ 7] + 0xf6bb4b60, 16);
+ MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
+ MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
+ MD5STEP(F3, d, a, b, c, in[ 0] + 0xeaa127fa, 11);
+ MD5STEP(F3, c, d, a, b, in[ 3] + 0xd4ef3085, 16);
+ MD5STEP(F3, b, c, d, a, in[ 6] + 0x04881d05, 23);
+ MD5STEP(F3, a, b, c, d, in[ 9] + 0xd9d4d039, 4);
+ MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
+ MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
+ MD5STEP(F3, b, c, d, a, in[2 ] + 0xc4ac5665, 23);
+
+ MD5STEP(F4, a, b, c, d, in[ 0] + 0xf4292244, 6);
+ MD5STEP(F4, d, a, b, c, in[7 ] + 0x432aff97, 10);
+ MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
+ MD5STEP(F4, b, c, d, a, in[5 ] + 0xfc93a039, 21);
+ MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
+ MD5STEP(F4, d, a, b, c, in[3 ] + 0x8f0ccc92, 10);
+ MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
+ MD5STEP(F4, b, c, d, a, in[1 ] + 0x85845dd1, 21);
+ MD5STEP(F4, a, b, c, d, in[8 ] + 0x6fa87e4f, 6);
+ MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
+ MD5STEP(F4, c, d, a, b, in[6 ] + 0xa3014314, 15);
+ MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
+ MD5STEP(F4, a, b, c, d, in[4 ] + 0xf7537e82, 6);
+ MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
+ MD5STEP(F4, c, d, a, b, in[2 ] + 0x2ad7d2bb, 15);
+ MD5STEP(F4, b, c, d, a, in[9 ] + 0xeb86d391, 21);
+
+ state[0] += a;
+ state[1] += b;
+ state[2] += c;
+ state[3] += d;
+}
+DEF_WEAK(MD5Transform);
diff --git a/lib/libc/hash/rmd160.c b/lib/libc/hash/rmd160.c
new file mode 100644
index 0000000..c2e368f
--- /dev/null
+++ b/lib/libc/hash/rmd160.c
@@ -0,0 +1,375 @@
+/*
+ * Copyright (c) 2001 Markus Friedl. 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.
+ */
+/*
+ * Preneel, Bosselaers, Dobbertin, "The Cryptographic Hash Function RIPEMD-160",
+ * RSA Laboratories, CryptoBytes, Volume 3, Number 2, Autumn 1997,
+ * ftp://ftp.rsasecurity.com/pub/cryptobytes/crypto3n2.pdf
+ */
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <endian.h>
+#include <string.h>
+#include <rmd160.h>
+
+#define PUT_64BIT_LE(cp, value) do { \
+ (cp)[7] = (value) >> 56; \
+ (cp)[6] = (value) >> 48; \
+ (cp)[5] = (value) >> 40; \
+ (cp)[4] = (value) >> 32; \
+ (cp)[3] = (value) >> 24; \
+ (cp)[2] = (value) >> 16; \
+ (cp)[1] = (value) >> 8; \
+ (cp)[0] = (value); } while (0)
+
+#define PUT_32BIT_LE(cp, value) do { \
+ (cp)[3] = (value) >> 24; \
+ (cp)[2] = (value) >> 16; \
+ (cp)[1] = (value) >> 8; \
+ (cp)[0] = (value); } while (0)
+
+#define H0 0x67452301U
+#define H1 0xEFCDAB89U
+#define H2 0x98BADCFEU
+#define H3 0x10325476U
+#define H4 0xC3D2E1F0U
+
+#define K0 0x00000000U
+#define K1 0x5A827999U
+#define K2 0x6ED9EBA1U
+#define K3 0x8F1BBCDCU
+#define K4 0xA953FD4EU
+
+#define KK0 0x50A28BE6U
+#define KK1 0x5C4DD124U
+#define KK2 0x6D703EF3U
+#define KK3 0x7A6D76E9U
+#define KK4 0x00000000U
+
+/* rotate x left n bits. */
+#define ROL(n, x) (((x) << (n)) | ((x) >> (32-(n))))
+
+#define F0(x, y, z) ((x) ^ (y) ^ (z))
+#define F1(x, y, z) (((x) & (y)) | ((~x) & (z)))
+#define F2(x, y, z) (((x) | (~y)) ^ (z))
+#define F3(x, y, z) (((x) & (z)) | ((y) & (~z)))
+#define F4(x, y, z) ((x) ^ ((y) | (~z)))
+
+#define R(a, b, c, d, e, Fj, Kj, sj, rj) \
+ do { \
+ a = ROL(sj, a + Fj(b,c,d) + X(rj) + Kj) + e; \
+ c = ROL(10, c); \
+ } while(0)
+
+#define X(i) x[i]
+
+static u_int8_t PADDING[RMD160_BLOCK_LENGTH] = {
+ 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+void
+RMD160Init(RMD160_CTX *ctx)
+{
+ ctx->count = 0;
+ ctx->state[0] = H0;
+ ctx->state[1] = H1;
+ ctx->state[2] = H2;
+ ctx->state[3] = H3;
+ ctx->state[4] = H4;
+}
+DEF_WEAK(RMD160Init);
+
+void
+RMD160Update(RMD160_CTX *ctx, const u_int8_t *input, size_t len)
+{
+ size_t have, off, need;
+
+ have = (ctx->count / 8) % RMD160_BLOCK_LENGTH;
+ need = RMD160_BLOCK_LENGTH - have;
+ ctx->count += 8 * len;
+ off = 0;
+
+ if (len >= need) {
+ if (have) {
+ memcpy(ctx->buffer + have, input, need);
+ RMD160Transform(ctx->state, ctx->buffer);
+ off = need;
+ have = 0;
+ }
+ /* now the buffer is empty */
+ while (off + RMD160_BLOCK_LENGTH <= len) {
+ RMD160Transform(ctx->state, input+off);
+ off += RMD160_BLOCK_LENGTH;
+ }
+ }
+ if (off < len)
+ memcpy(ctx->buffer + have, input+off, len-off);
+}
+DEF_WEAK(RMD160Update);
+
+void
+RMD160Pad(RMD160_CTX *ctx)
+{
+ u_int8_t size[8];
+ size_t padlen;
+
+ PUT_64BIT_LE(size, ctx->count);
+
+ /*
+ * pad to RMD160_BLOCK_LENGTH byte blocks, at least one byte from
+ * PADDING plus 8 bytes for the size
+ */
+ padlen = RMD160_BLOCK_LENGTH - ((ctx->count / 8) % RMD160_BLOCK_LENGTH);
+ if (padlen < 1 + 8)
+ padlen += RMD160_BLOCK_LENGTH;
+ RMD160Update(ctx, PADDING, padlen - 8); /* padlen - 8 <= 64 */
+ RMD160Update(ctx, size, 8);
+}
+DEF_WEAK(RMD160Pad);
+
+void
+RMD160Final(u_int8_t digest[RMD160_DIGEST_LENGTH], RMD160_CTX *ctx)
+{
+ int i;
+
+ RMD160Pad(ctx);
+ for (i = 0; i < 5; i++)
+ PUT_32BIT_LE(digest + i*4, ctx->state[i]);
+ explicit_bzero(ctx, sizeof (*ctx));
+}
+DEF_WEAK(RMD160Final);
+
+void
+RMD160Transform(u_int32_t state[5], const u_int8_t block[RMD160_BLOCK_LENGTH])
+{
+ u_int32_t a, b, c, d, e, aa, bb, cc, dd, ee, t, x[16];
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+ memcpy(x, block, RMD160_BLOCK_LENGTH);
+#else
+ int i;
+
+ for (i = 0; i < 16; i++)
+ x[i] = (u_int32_t)(
+ (u_int32_t)(block[i*4 + 0]) |
+ (u_int32_t)(block[i*4 + 1]) << 8 |
+ (u_int32_t)(block[i*4 + 2]) << 16 |
+ (u_int32_t)(block[i*4 + 3]) << 24);
+#endif
+
+ a = state[0];
+ b = state[1];
+ c = state[2];
+ d = state[3];
+ e = state[4];
+
+ /* Round 1 */
+ R(a, b, c, d, e, F0, K0, 11, 0);
+ R(e, a, b, c, d, F0, K0, 14, 1);
+ R(d, e, a, b, c, F0, K0, 15, 2);
+ R(c, d, e, a, b, F0, K0, 12, 3);
+ R(b, c, d, e, a, F0, K0, 5, 4);
+ R(a, b, c, d, e, F0, K0, 8, 5);
+ R(e, a, b, c, d, F0, K0, 7, 6);
+ R(d, e, a, b, c, F0, K0, 9, 7);
+ R(c, d, e, a, b, F0, K0, 11, 8);
+ R(b, c, d, e, a, F0, K0, 13, 9);
+ R(a, b, c, d, e, F0, K0, 14, 10);
+ R(e, a, b, c, d, F0, K0, 15, 11);
+ R(d, e, a, b, c, F0, K0, 6, 12);
+ R(c, d, e, a, b, F0, K0, 7, 13);
+ R(b, c, d, e, a, F0, K0, 9, 14);
+ R(a, b, c, d, e, F0, K0, 8, 15); /* #15 */
+ /* Round 2 */
+ R(e, a, b, c, d, F1, K1, 7, 7);
+ R(d, e, a, b, c, F1, K1, 6, 4);
+ R(c, d, e, a, b, F1, K1, 8, 13);
+ R(b, c, d, e, a, F1, K1, 13, 1);
+ R(a, b, c, d, e, F1, K1, 11, 10);
+ R(e, a, b, c, d, F1, K1, 9, 6);
+ R(d, e, a, b, c, F1, K1, 7, 15);
+ R(c, d, e, a, b, F1, K1, 15, 3);
+ R(b, c, d, e, a, F1, K1, 7, 12);
+ R(a, b, c, d, e, F1, K1, 12, 0);
+ R(e, a, b, c, d, F1, K1, 15, 9);
+ R(d, e, a, b, c, F1, K1, 9, 5);
+ R(c, d, e, a, b, F1, K1, 11, 2);
+ R(b, c, d, e, a, F1, K1, 7, 14);
+ R(a, b, c, d, e, F1, K1, 13, 11);
+ R(e, a, b, c, d, F1, K1, 12, 8); /* #31 */
+ /* Round 3 */
+ R(d, e, a, b, c, F2, K2, 11, 3);
+ R(c, d, e, a, b, F2, K2, 13, 10);
+ R(b, c, d, e, a, F2, K2, 6, 14);
+ R(a, b, c, d, e, F2, K2, 7, 4);
+ R(e, a, b, c, d, F2, K2, 14, 9);
+ R(d, e, a, b, c, F2, K2, 9, 15);
+ R(c, d, e, a, b, F2, K2, 13, 8);
+ R(b, c, d, e, a, F2, K2, 15, 1);
+ R(a, b, c, d, e, F2, K2, 14, 2);
+ R(e, a, b, c, d, F2, K2, 8, 7);
+ R(d, e, a, b, c, F2, K2, 13, 0);
+ R(c, d, e, a, b, F2, K2, 6, 6);
+ R(b, c, d, e, a, F2, K2, 5, 13);
+ R(a, b, c, d, e, F2, K2, 12, 11);
+ R(e, a, b, c, d, F2, K2, 7, 5);
+ R(d, e, a, b, c, F2, K2, 5, 12); /* #47 */
+ /* Round 4 */
+ R(c, d, e, a, b, F3, K3, 11, 1);
+ R(b, c, d, e, a, F3, K3, 12, 9);
+ R(a, b, c, d, e, F3, K3, 14, 11);
+ R(e, a, b, c, d, F3, K3, 15, 10);
+ R(d, e, a, b, c, F3, K3, 14, 0);
+ R(c, d, e, a, b, F3, K3, 15, 8);
+ R(b, c, d, e, a, F3, K3, 9, 12);
+ R(a, b, c, d, e, F3, K3, 8, 4);
+ R(e, a, b, c, d, F3, K3, 9, 13);
+ R(d, e, a, b, c, F3, K3, 14, 3);
+ R(c, d, e, a, b, F3, K3, 5, 7);
+ R(b, c, d, e, a, F3, K3, 6, 15);
+ R(a, b, c, d, e, F3, K3, 8, 14);
+ R(e, a, b, c, d, F3, K3, 6, 5);
+ R(d, e, a, b, c, F3, K3, 5, 6);
+ R(c, d, e, a, b, F3, K3, 12, 2); /* #63 */
+ /* Round 5 */
+ R(b, c, d, e, a, F4, K4, 9, 4);
+ R(a, b, c, d, e, F4, K4, 15, 0);
+ R(e, a, b, c, d, F4, K4, 5, 5);
+ R(d, e, a, b, c, F4, K4, 11, 9);
+ R(c, d, e, a, b, F4, K4, 6, 7);
+ R(b, c, d, e, a, F4, K4, 8, 12);
+ R(a, b, c, d, e, F4, K4, 13, 2);
+ R(e, a, b, c, d, F4, K4, 12, 10);
+ R(d, e, a, b, c, F4, K4, 5, 14);
+ R(c, d, e, a, b, F4, K4, 12, 1);
+ R(b, c, d, e, a, F4, K4, 13, 3);
+ R(a, b, c, d, e, F4, K4, 14, 8);
+ R(e, a, b, c, d, F4, K4, 11, 11);
+ R(d, e, a, b, c, F4, K4, 8, 6);
+ R(c, d, e, a, b, F4, K4, 5, 15);
+ R(b, c, d, e, a, F4, K4, 6, 13); /* #79 */
+
+ aa = a ; bb = b; cc = c; dd = d; ee = e;
+
+ a = state[0];
+ b = state[1];
+ c = state[2];
+ d = state[3];
+ e = state[4];
+
+ /* Parallel round 1 */
+ R(a, b, c, d, e, F4, KK0, 8, 5);
+ R(e, a, b, c, d, F4, KK0, 9, 14);
+ R(d, e, a, b, c, F4, KK0, 9, 7);
+ R(c, d, e, a, b, F4, KK0, 11, 0);
+ R(b, c, d, e, a, F4, KK0, 13, 9);
+ R(a, b, c, d, e, F4, KK0, 15, 2);
+ R(e, a, b, c, d, F4, KK0, 15, 11);
+ R(d, e, a, b, c, F4, KK0, 5, 4);
+ R(c, d, e, a, b, F4, KK0, 7, 13);
+ R(b, c, d, e, a, F4, KK0, 7, 6);
+ R(a, b, c, d, e, F4, KK0, 8, 15);
+ R(e, a, b, c, d, F4, KK0, 11, 8);
+ R(d, e, a, b, c, F4, KK0, 14, 1);
+ R(c, d, e, a, b, F4, KK0, 14, 10);
+ R(b, c, d, e, a, F4, KK0, 12, 3);
+ R(a, b, c, d, e, F4, KK0, 6, 12); /* #15 */
+ /* Parallel round 2 */
+ R(e, a, b, c, d, F3, KK1, 9, 6);
+ R(d, e, a, b, c, F3, KK1, 13, 11);
+ R(c, d, e, a, b, F3, KK1, 15, 3);
+ R(b, c, d, e, a, F3, KK1, 7, 7);
+ R(a, b, c, d, e, F3, KK1, 12, 0);
+ R(e, a, b, c, d, F3, KK1, 8, 13);
+ R(d, e, a, b, c, F3, KK1, 9, 5);
+ R(c, d, e, a, b, F3, KK1, 11, 10);
+ R(b, c, d, e, a, F3, KK1, 7, 14);
+ R(a, b, c, d, e, F3, KK1, 7, 15);
+ R(e, a, b, c, d, F3, KK1, 12, 8);
+ R(d, e, a, b, c, F3, KK1, 7, 12);
+ R(c, d, e, a, b, F3, KK1, 6, 4);
+ R(b, c, d, e, a, F3, KK1, 15, 9);
+ R(a, b, c, d, e, F3, KK1, 13, 1);
+ R(e, a, b, c, d, F3, KK1, 11, 2); /* #31 */
+ /* Parallel round 3 */
+ R(d, e, a, b, c, F2, KK2, 9, 15);
+ R(c, d, e, a, b, F2, KK2, 7, 5);
+ R(b, c, d, e, a, F2, KK2, 15, 1);
+ R(a, b, c, d, e, F2, KK2, 11, 3);
+ R(e, a, b, c, d, F2, KK2, 8, 7);
+ R(d, e, a, b, c, F2, KK2, 6, 14);
+ R(c, d, e, a, b, F2, KK2, 6, 6);
+ R(b, c, d, e, a, F2, KK2, 14, 9);
+ R(a, b, c, d, e, F2, KK2, 12, 11);
+ R(e, a, b, c, d, F2, KK2, 13, 8);
+ R(d, e, a, b, c, F2, KK2, 5, 12);
+ R(c, d, e, a, b, F2, KK2, 14, 2);
+ R(b, c, d, e, a, F2, KK2, 13, 10);
+ R(a, b, c, d, e, F2, KK2, 13, 0);
+ R(e, a, b, c, d, F2, KK2, 7, 4);
+ R(d, e, a, b, c, F2, KK2, 5, 13); /* #47 */
+ /* Parallel round 4 */
+ R(c, d, e, a, b, F1, KK3, 15, 8);
+ R(b, c, d, e, a, F1, KK3, 5, 6);
+ R(a, b, c, d, e, F1, KK3, 8, 4);
+ R(e, a, b, c, d, F1, KK3, 11, 1);
+ R(d, e, a, b, c, F1, KK3, 14, 3);
+ R(c, d, e, a, b, F1, KK3, 14, 11);
+ R(b, c, d, e, a, F1, KK3, 6, 15);
+ R(a, b, c, d, e, F1, KK3, 14, 0);
+ R(e, a, b, c, d, F1, KK3, 6, 5);
+ R(d, e, a, b, c, F1, KK3, 9, 12);
+ R(c, d, e, a, b, F1, KK3, 12, 2);
+ R(b, c, d, e, a, F1, KK3, 9, 13);
+ R(a, b, c, d, e, F1, KK3, 12, 9);
+ R(e, a, b, c, d, F1, KK3, 5, 7);
+ R(d, e, a, b, c, F1, KK3, 15, 10);
+ R(c, d, e, a, b, F1, KK3, 8, 14); /* #63 */
+ /* Parallel round 5 */
+ R(b, c, d, e, a, F0, KK4, 8, 12);
+ R(a, b, c, d, e, F0, KK4, 5, 15);
+ R(e, a, b, c, d, F0, KK4, 12, 10);
+ R(d, e, a, b, c, F0, KK4, 9, 4);
+ R(c, d, e, a, b, F0, KK4, 12, 1);
+ R(b, c, d, e, a, F0, KK4, 5, 5);
+ R(a, b, c, d, e, F0, KK4, 14, 8);
+ R(e, a, b, c, d, F0, KK4, 6, 7);
+ R(d, e, a, b, c, F0, KK4, 8, 6);
+ R(c, d, e, a, b, F0, KK4, 13, 2);
+ R(b, c, d, e, a, F0, KK4, 6, 13);
+ R(a, b, c, d, e, F0, KK4, 5, 14);
+ R(e, a, b, c, d, F0, KK4, 15, 0);
+ R(d, e, a, b, c, F0, KK4, 13, 3);
+ R(c, d, e, a, b, F0, KK4, 11, 9);
+ R(b, c, d, e, a, F0, KK4, 11, 11); /* #79 */
+
+ t = state[1] + cc + d;
+ state[1] = state[2] + dd + e;
+ state[2] = state[3] + ee + a;
+ state[3] = state[4] + aa + b;
+ state[4] = state[0] + bb + c;
+ state[0] = t;
+}
+DEF_WEAK(RMD160Transform);
diff --git a/lib/libc/hash/sha1.c b/lib/libc/hash/sha1.c
new file mode 100644
index 0000000..ef6e2c2
--- /dev/null
+++ b/lib/libc/hash/sha1.c
@@ -0,0 +1,179 @@
+/* $OpenBSD: sha1.c,v 1.27 2019/06/07 22:56:36 dtucker Exp $ */
+
+/*
+ * SHA-1 in C
+ * By Steve Reid <steve@edmweb.com>
+ * 100% Public Domain
+ *
+ * Test Vectors (from FIPS PUB 180-1)
+ * "abc"
+ * A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
+ * "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
+ * 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
+ * A million repetitions of "a"
+ * 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
+ */
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <string.h>
+#include <sha1.h>
+
+#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
+
+/*
+ * blk0() and blk() perform the initial expand.
+ * I got the idea of expanding during the round function from SSLeay
+ */
+#if BYTE_ORDER == LITTLE_ENDIAN
+# define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \
+ |(rol(block->l[i],8)&0x00FF00FF))
+#else
+# define blk0(i) block->l[i]
+#endif
+#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
+ ^block->l[(i+2)&15]^block->l[i&15],1))
+
+/*
+ * (R0+R1), R2, R3, R4 are the different operations (rounds) used in SHA1
+ */
+#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);
+#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30);
+#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
+#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
+#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
+
+typedef union {
+ u_int8_t c[64];
+ u_int32_t l[16];
+} CHAR64LONG16;
+
+/*
+ * Hash a single 512-bit block. This is the core of the algorithm.
+ */
+void
+SHA1Transform(u_int32_t state[5], const u_int8_t buffer[SHA1_BLOCK_LENGTH])
+{
+ u_int32_t a, b, c, d, e;
+ u_int8_t workspace[SHA1_BLOCK_LENGTH];
+ CHAR64LONG16 *block = (CHAR64LONG16 *)workspace;
+
+ (void)memcpy(block, buffer, SHA1_BLOCK_LENGTH);
+
+ /* Copy context->state[] to working vars */
+ a = state[0];
+ b = state[1];
+ c = state[2];
+ d = state[3];
+ e = state[4];
+
+ /* 4 rounds of 20 operations each. Loop unrolled. */
+ R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2); R0(c,d,e,a,b, 3);
+ R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5); R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7);
+ R0(c,d,e,a,b, 8); R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
+ R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14); R0(a,b,c,d,e,15);
+ R1(e,a,b,c,d,16); R1(d,e,a,b,c,17); R1(c,d,e,a,b,18); R1(b,c,d,e,a,19);
+ R2(a,b,c,d,e,20); R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
+ R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26); R2(d,e,a,b,c,27);
+ R2(c,d,e,a,b,28); R2(b,c,d,e,a,29); R2(a,b,c,d,e,30); R2(e,a,b,c,d,31);
+ R2(d,e,a,b,c,32); R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
+ R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38); R2(b,c,d,e,a,39);
+ R3(a,b,c,d,e,40); R3(e,a,b,c,d,41); R3(d,e,a,b,c,42); R3(c,d,e,a,b,43);
+ R3(b,c,d,e,a,44); R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
+ R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50); R3(e,a,b,c,d,51);
+ R3(d,e,a,b,c,52); R3(c,d,e,a,b,53); R3(b,c,d,e,a,54); R3(a,b,c,d,e,55);
+ R3(e,a,b,c,d,56); R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
+ R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62); R4(c,d,e,a,b,63);
+ R4(b,c,d,e,a,64); R4(a,b,c,d,e,65); R4(e,a,b,c,d,66); R4(d,e,a,b,c,67);
+ R4(c,d,e,a,b,68); R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
+ R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74); R4(a,b,c,d,e,75);
+ R4(e,a,b,c,d,76); R4(d,e,a,b,c,77); R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
+
+ /* Add the working vars back into context.state[] */
+ state[0] += a;
+ state[1] += b;
+ state[2] += c;
+ state[3] += d;
+ state[4] += e;
+
+ /* Wipe variables */
+ a = b = c = d = e = 0;
+}
+DEF_WEAK(SHA1Transform);
+
+
+/*
+ * SHA1Init - Initialize new context
+ */
+void
+SHA1Init(SHA1_CTX *context)
+{
+
+ /* SHA1 initialization constants */
+ context->count = 0;
+ context->state[0] = 0x67452301;
+ context->state[1] = 0xEFCDAB89;
+ context->state[2] = 0x98BADCFE;
+ context->state[3] = 0x10325476;
+ context->state[4] = 0xC3D2E1F0;
+}
+DEF_WEAK(SHA1Init);
+
+
+/*
+ * Run your data through this.
+ */
+void
+SHA1Update(SHA1_CTX *context, const u_int8_t *data, size_t len)
+{
+ size_t i, j;
+
+ j = (size_t)((context->count >> 3) & 63);
+ context->count += ((u_int64_t)len << 3);
+ if ((j + len) > 63) {
+ (void)memcpy(&context->buffer[j], data, (i = 64-j));
+ SHA1Transform(context->state, context->buffer);
+ for ( ; i + 63 < len; i += 64)
+ SHA1Transform(context->state, (u_int8_t *)&data[i]);
+ j = 0;
+ } else {
+ i = 0;
+ }
+ (void)memcpy(&context->buffer[j], &data[i], len - i);
+}
+DEF_WEAK(SHA1Update);
+
+
+/*
+ * Add padding and return the message digest.
+ */
+void
+SHA1Pad(SHA1_CTX *context)
+{
+ u_int8_t finalcount[8];
+ u_int i;
+
+ for (i = 0; i < 8; i++) {
+ finalcount[i] = (u_int8_t)((context->count >>
+ ((7 - (i & 7)) * 8)) & 255); /* Endian independent */
+ }
+ SHA1Update(context, (u_int8_t *)"\200", 1);
+ while ((context->count & 504) != 448)
+ SHA1Update(context, (u_int8_t *)"\0", 1);
+ SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */
+}
+DEF_WEAK(SHA1Pad);
+
+void
+SHA1Final(u_int8_t digest[SHA1_DIGEST_LENGTH], SHA1_CTX *context)
+{
+ u_int i;
+
+ SHA1Pad(context);
+ for (i = 0; i < SHA1_DIGEST_LENGTH; i++) {
+ digest[i] = (u_int8_t)
+ ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
+ }
+ explicit_bzero(context, sizeof(*context));
+}
+DEF_WEAK(SHA1Final);
diff --git a/lib/libc/hash/sha2.c b/lib/libc/hash/sha2.c
new file mode 100644
index 0000000..3374197
--- /dev/null
+++ b/lib/libc/hash/sha2.c
@@ -0,0 +1,977 @@
+/* $OpenBSD: sha2.c,v 1.28 2019/07/23 12:35:22 dtucker Exp $ */
+
+/*
+ * FILE: sha2.c
+ * AUTHOR: Aaron D. Gifford <me@aarongifford.com>
+ *
+ * Copyright (c) 2000-2001, Aaron D. Gifford
+ * 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 copyright holder nor the names of contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``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 CONTRIBUTOR(S) 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: sha2.c,v 1.1 2001/11/08 00:01:51 adg Exp adg $
+ */
+
+#include <sys/types.h>
+#include <sys/cdefs.h>
+#include <sys/compat.h>
+
+#include <string.h>
+#include <sha2.h>
+
+/*
+ * UNROLLED TRANSFORM LOOP NOTE:
+ * You can define SHA2_UNROLL_TRANSFORM to use the unrolled transform
+ * loop version for the hash transform rounds (defined using macros
+ * later in this file). Either define on the command line, for example:
+ *
+ * cc -DSHA2_UNROLL_TRANSFORM -o sha2 sha2.c sha2prog.c
+ *
+ * or define below:
+ *
+ * #define SHA2_UNROLL_TRANSFORM
+ *
+ */
+#ifndef SHA2_SMALL
+#if defined(__amd64__) || defined(__i386__)
+#define SHA2_UNROLL_TRANSFORM
+#endif
+#endif
+
+/*** SHA-224/256/384/512 Machine Architecture Definitions *****************/
+/*
+ * BYTE_ORDER NOTE:
+ *
+ * Please make sure that your system defines BYTE_ORDER. If your
+ * architecture is little-endian, make sure it also defines
+ * LITTLE_ENDIAN and that the two (BYTE_ORDER and LITTLE_ENDIAN) are
+ * equivalent.
+ *
+ * If your system does not define the above, then you can do so by
+ * hand like this:
+ *
+ * #define LITTLE_ENDIAN 1234
+ * #define BIG_ENDIAN 4321
+ *
+ * And for little-endian machines, add:
+ *
+ * #define BYTE_ORDER LITTLE_ENDIAN
+ *
+ * Or for big-endian machines:
+ *
+ * #define BYTE_ORDER BIG_ENDIAN
+ *
+ * The FreeBSD machine this was written on defines BYTE_ORDER
+ * appropriately by including <sys/types.h> (which in turn includes
+ * <machine/endian.h> where the appropriate definitions are actually
+ * made).
+ */
+#if !defined(BYTE_ORDER) || (BYTE_ORDER != LITTLE_ENDIAN && BYTE_ORDER != BIG_ENDIAN)
+#error Define BYTE_ORDER to be equal to either LITTLE_ENDIAN or BIG_ENDIAN
+#endif
+
+
+/*** SHA-224/256/384/512 Various Length Definitions ***********************/
+/* NOTE: Most of these are in sha2.h */
+#define SHA224_SHORT_BLOCK_LENGTH (SHA224_BLOCK_LENGTH - 8)
+#define SHA256_SHORT_BLOCK_LENGTH (SHA256_BLOCK_LENGTH - 8)
+#define SHA384_SHORT_BLOCK_LENGTH (SHA384_BLOCK_LENGTH - 16)
+#define SHA512_SHORT_BLOCK_LENGTH (SHA512_BLOCK_LENGTH - 16)
+
+/*** ENDIAN SPECIFIC COPY MACROS **************************************/
+#define BE_8_TO_32(dst, cp) do { \
+ (dst) = (u_int32_t)(cp)[3] | ((u_int32_t)(cp)[2] << 8) | \
+ ((u_int32_t)(cp)[1] << 16) | ((u_int32_t)(cp)[0] << 24); \
+} while(0)
+
+#define BE_8_TO_64(dst, cp) do { \
+ (dst) = (u_int64_t)(cp)[7] | ((u_int64_t)(cp)[6] << 8) | \
+ ((u_int64_t)(cp)[5] << 16) | ((u_int64_t)(cp)[4] << 24) | \
+ ((u_int64_t)(cp)[3] << 32) | ((u_int64_t)(cp)[2] << 40) | \
+ ((u_int64_t)(cp)[1] << 48) | ((u_int64_t)(cp)[0] << 56); \
+} while (0)
+
+#define BE_64_TO_8(cp, src) do { \
+ (cp)[0] = (src) >> 56; \
+ (cp)[1] = (src) >> 48; \
+ (cp)[2] = (src) >> 40; \
+ (cp)[3] = (src) >> 32; \
+ (cp)[4] = (src) >> 24; \
+ (cp)[5] = (src) >> 16; \
+ (cp)[6] = (src) >> 8; \
+ (cp)[7] = (src); \
+} while (0)
+
+#define BE_32_TO_8(cp, src) do { \
+ (cp)[0] = (src) >> 24; \
+ (cp)[1] = (src) >> 16; \
+ (cp)[2] = (src) >> 8; \
+ (cp)[3] = (src); \
+} while (0)
+
+/*
+ * Macro for incrementally adding the unsigned 64-bit integer n to the
+ * unsigned 128-bit integer (represented using a two-element array of
+ * 64-bit words):
+ */
+#define ADDINC128(w,n) do { \
+ (w)[0] += (u_int64_t)(n); \
+ if ((w)[0] < (n)) { \
+ (w)[1]++; \
+ } \
+} while (0)
+
+/*** THE SIX LOGICAL FUNCTIONS ****************************************/
+/*
+ * Bit shifting and rotation (used by the six SHA-XYZ logical functions:
+ *
+ * NOTE: The naming of R and S appears backwards here (R is a SHIFT and
+ * S is a ROTATION) because the SHA-224/256/384/512 description document
+ * (see http://csrc.nist.gov/cryptval/shs/sha256-384-512.pdf) uses this
+ * same "backwards" definition.
+ */
+/* Shift-right (used in SHA-224, SHA-256, SHA-384, and SHA-512): */
+#define R(b,x) ((x) >> (b))
+/* 32-bit Rotate-right (used in SHA-224 and SHA-256): */
+#define S32(b,x) (((x) >> (b)) | ((x) << (32 - (b))))
+/* 64-bit Rotate-right (used in SHA-384 and SHA-512): */
+#define S64(b,x) (((x) >> (b)) | ((x) << (64 - (b))))
+
+/* Two of six logical functions used in SHA-224, SHA-256, SHA-384, and SHA-512: */
+#define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z)))
+#define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
+
+/* Four of six logical functions used in SHA-224 and SHA-256: */
+#define Sigma0_256(x) (S32(2, (x)) ^ S32(13, (x)) ^ S32(22, (x)))
+#define Sigma1_256(x) (S32(6, (x)) ^ S32(11, (x)) ^ S32(25, (x)))
+#define sigma0_256(x) (S32(7, (x)) ^ S32(18, (x)) ^ R(3 , (x)))
+#define sigma1_256(x) (S32(17, (x)) ^ S32(19, (x)) ^ R(10, (x)))
+
+/* Four of six logical functions used in SHA-384 and SHA-512: */
+#define Sigma0_512(x) (S64(28, (x)) ^ S64(34, (x)) ^ S64(39, (x)))
+#define Sigma1_512(x) (S64(14, (x)) ^ S64(18, (x)) ^ S64(41, (x)))
+#define sigma0_512(x) (S64( 1, (x)) ^ S64( 8, (x)) ^ R( 7, (x)))
+#define sigma1_512(x) (S64(19, (x)) ^ S64(61, (x)) ^ R( 6, (x)))
+
+
+/*** SHA-XYZ INITIAL HASH VALUES AND CONSTANTS ************************/
+/* Hash constant words K for SHA-224 and SHA-256: */
+static const u_int32_t K256[64] = {
+ 0x428a2f98UL, 0x71374491UL, 0xb5c0fbcfUL, 0xe9b5dba5UL,
+ 0x3956c25bUL, 0x59f111f1UL, 0x923f82a4UL, 0xab1c5ed5UL,
+ 0xd807aa98UL, 0x12835b01UL, 0x243185beUL, 0x550c7dc3UL,
+ 0x72be5d74UL, 0x80deb1feUL, 0x9bdc06a7UL, 0xc19bf174UL,
+ 0xe49b69c1UL, 0xefbe4786UL, 0x0fc19dc6UL, 0x240ca1ccUL,
+ 0x2de92c6fUL, 0x4a7484aaUL, 0x5cb0a9dcUL, 0x76f988daUL,
+ 0x983e5152UL, 0xa831c66dUL, 0xb00327c8UL, 0xbf597fc7UL,
+ 0xc6e00bf3UL, 0xd5a79147UL, 0x06ca6351UL, 0x14292967UL,
+ 0x27b70a85UL, 0x2e1b2138UL, 0x4d2c6dfcUL, 0x53380d13UL,
+ 0x650a7354UL, 0x766a0abbUL, 0x81c2c92eUL, 0x92722c85UL,
+ 0xa2bfe8a1UL, 0xa81a664bUL, 0xc24b8b70UL, 0xc76c51a3UL,
+ 0xd192e819UL, 0xd6990624UL, 0xf40e3585UL, 0x106aa070UL,
+ 0x19a4c116UL, 0x1e376c08UL, 0x2748774cUL, 0x34b0bcb5UL,
+ 0x391c0cb3UL, 0x4ed8aa4aUL, 0x5b9cca4fUL, 0x682e6ff3UL,
+ 0x748f82eeUL, 0x78a5636fUL, 0x84c87814UL, 0x8cc70208UL,
+ 0x90befffaUL, 0xa4506cebUL, 0xbef9a3f7UL, 0xc67178f2UL
+};
+
+/* Initial hash value H for SHA-256: */
+static const u_int32_t sha256_initial_hash_value[8] = {
+ 0x6a09e667UL,
+ 0xbb67ae85UL,
+ 0x3c6ef372UL,
+ 0xa54ff53aUL,
+ 0x510e527fUL,
+ 0x9b05688cUL,
+ 0x1f83d9abUL,
+ 0x5be0cd19UL
+};
+
+/* Hash constant words K for SHA-384 and SHA-512: */
+static const u_int64_t K512[80] = {
+ 0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL,
+ 0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL,
+ 0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL,
+ 0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL,
+ 0xd807aa98a3030242ULL, 0x12835b0145706fbeULL,
+ 0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL,
+ 0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL,
+ 0x9bdc06a725c71235ULL, 0xc19bf174cf692694ULL,
+ 0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL,
+ 0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL,
+ 0x2de92c6f592b0275ULL, 0x4a7484aa6ea6e483ULL,
+ 0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL,
+ 0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL,
+ 0xb00327c898fb213fULL, 0xbf597fc7beef0ee4ULL,
+ 0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL,
+ 0x06ca6351e003826fULL, 0x142929670a0e6e70ULL,
+ 0x27b70a8546d22ffcULL, 0x2e1b21385c26c926ULL,
+ 0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL,
+ 0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL,
+ 0x81c2c92e47edaee6ULL, 0x92722c851482353bULL,
+ 0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL,
+ 0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL,
+ 0xd192e819d6ef5218ULL, 0xd69906245565a910ULL,
+ 0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL,
+ 0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL,
+ 0x2748774cdf8eeb99ULL, 0x34b0bcb5e19b48a8ULL,
+ 0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL,
+ 0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL,
+ 0x748f82ee5defb2fcULL, 0x78a5636f43172f60ULL,
+ 0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL,
+ 0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL,
+ 0xbef9a3f7b2c67915ULL, 0xc67178f2e372532bULL,
+ 0xca273eceea26619cULL, 0xd186b8c721c0c207ULL,
+ 0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL,
+ 0x06f067aa72176fbaULL, 0x0a637dc5a2c898a6ULL,
+ 0x113f9804bef90daeULL, 0x1b710b35131c471bULL,
+ 0x28db77f523047d84ULL, 0x32caab7b40c72493ULL,
+ 0x3c9ebe0a15c9bebcULL, 0x431d67c49c100d4cULL,
+ 0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL,
+ 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL
+};
+
+/* Initial hash value H for SHA-512 */
+static const u_int64_t sha512_initial_hash_value[8] = {
+ 0x6a09e667f3bcc908ULL,
+ 0xbb67ae8584caa73bULL,
+ 0x3c6ef372fe94f82bULL,
+ 0xa54ff53a5f1d36f1ULL,
+ 0x510e527fade682d1ULL,
+ 0x9b05688c2b3e6c1fULL,
+ 0x1f83d9abfb41bd6bULL,
+ 0x5be0cd19137e2179ULL
+};
+
+#if !defined(SHA2_SMALL)
+/* Initial hash value H for SHA-224: */
+static const u_int32_t sha224_initial_hash_value[8] = {
+ 0xc1059ed8UL,
+ 0x367cd507UL,
+ 0x3070dd17UL,
+ 0xf70e5939UL,
+ 0xffc00b31UL,
+ 0x68581511UL,
+ 0x64f98fa7UL,
+ 0xbefa4fa4UL
+};
+
+/* Initial hash value H for SHA-384 */
+static const u_int64_t sha384_initial_hash_value[8] = {
+ 0xcbbb9d5dc1059ed8ULL,
+ 0x629a292a367cd507ULL,
+ 0x9159015a3070dd17ULL,
+ 0x152fecd8f70e5939ULL,
+ 0x67332667ffc00b31ULL,
+ 0x8eb44a8768581511ULL,
+ 0xdb0c2e0d64f98fa7ULL,
+ 0x47b5481dbefa4fa4ULL
+};
+
+/* Initial hash value H for SHA-512-256 */
+static const u_int64_t sha512_256_initial_hash_value[8] = {
+ 0x22312194fc2bf72cULL,
+ 0x9f555fa3c84c64c2ULL,
+ 0x2393b86b6f53b151ULL,
+ 0x963877195940eabdULL,
+ 0x96283ee2a88effe3ULL,
+ 0xbe5e1e2553863992ULL,
+ 0x2b0199fc2c85b8aaULL,
+ 0x0eb72ddc81c52ca2ULL
+};
+
+/*** SHA-224: *********************************************************/
+void
+SHA224Init(SHA2_CTX *context)
+{
+ memcpy(context->state.st32, sha224_initial_hash_value,
+ sizeof(sha224_initial_hash_value));
+ memset(context->buffer, 0, sizeof(context->buffer));
+ context->bitcount[0] = 0;
+}
+DEF_WEAK(SHA224Init);
+
+MAKE_CLONE(SHA224Transform, SHA256Transform);
+MAKE_CLONE(SHA224Update, SHA256Update);
+MAKE_CLONE(SHA224Pad, SHA256Pad);
+DEF_WEAK(SHA224Transform);
+DEF_WEAK(SHA224Update);
+DEF_WEAK(SHA224Pad);
+
+void
+SHA224Final(u_int8_t digest[SHA224_DIGEST_LENGTH], SHA2_CTX *context)
+{
+ SHA224Pad(context);
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+ int i;
+
+ /* Convert TO host byte order */
+ for (i = 0; i < 7; i++)
+ BE_32_TO_8(digest + i * 4, context->state.st32[i]);
+#else
+ memcpy(digest, context->state.st32, SHA224_DIGEST_LENGTH);
+#endif
+ explicit_bzero(context, sizeof(*context));
+}
+DEF_WEAK(SHA224Final);
+#endif /* !defined(SHA2_SMALL) */
+
+/*** SHA-256: *********************************************************/
+void
+SHA256Init(SHA2_CTX *context)
+{
+ memcpy(context->state.st32, sha256_initial_hash_value,
+ sizeof(sha256_initial_hash_value));
+ memset(context->buffer, 0, sizeof(context->buffer));
+ context->bitcount[0] = 0;
+}
+DEF_WEAK(SHA256Init);
+
+#ifdef SHA2_UNROLL_TRANSFORM
+
+/* Unrolled SHA-256 round macros: */
+
+#define ROUND256_0_TO_15(a,b,c,d,e,f,g,h) do { \
+ BE_8_TO_32(W256[j], data); \
+ data += 4; \
+ T1 = (h) + Sigma1_256((e)) + Ch((e), (f), (g)) + K256[j] + W256[j]; \
+ (d) += T1; \
+ (h) = T1 + Sigma0_256((a)) + Maj((a), (b), (c)); \
+ j++; \
+} while(0)
+
+#define ROUND256(a,b,c,d,e,f,g,h) do { \
+ s0 = W256[(j+1)&0x0f]; \
+ s0 = sigma0_256(s0); \
+ s1 = W256[(j+14)&0x0f]; \
+ s1 = sigma1_256(s1); \
+ T1 = (h) + Sigma1_256((e)) + Ch((e), (f), (g)) + K256[j] + \
+ (W256[j&0x0f] += s1 + W256[(j+9)&0x0f] + s0); \
+ (d) += T1; \
+ (h) = T1 + Sigma0_256((a)) + Maj((a), (b), (c)); \
+ j++; \
+} while(0)
+
+void
+SHA256Transform(u_int32_t state[8], const u_int8_t data[SHA256_BLOCK_LENGTH])
+{
+ u_int32_t a, b, c, d, e, f, g, h, s0, s1;
+ u_int32_t T1, W256[16];
+ int j;
+
+ /* Initialize registers with the prev. intermediate value */
+ a = state[0];
+ b = state[1];
+ c = state[2];
+ d = state[3];
+ e = state[4];
+ f = state[5];
+ g = state[6];
+ h = state[7];
+
+ j = 0;
+ do {
+ /* Rounds 0 to 15 (unrolled): */
+ ROUND256_0_TO_15(a,b,c,d,e,f,g,h);
+ ROUND256_0_TO_15(h,a,b,c,d,e,f,g);
+ ROUND256_0_TO_15(g,h,a,b,c,d,e,f);
+ ROUND256_0_TO_15(f,g,h,a,b,c,d,e);
+ ROUND256_0_TO_15(e,f,g,h,a,b,c,d);
+ ROUND256_0_TO_15(d,e,f,g,h,a,b,c);
+ ROUND256_0_TO_15(c,d,e,f,g,h,a,b);
+ ROUND256_0_TO_15(b,c,d,e,f,g,h,a);
+ } while (j < 16);
+
+ /* Now for the remaining rounds up to 63: */
+ do {
+ ROUND256(a,b,c,d,e,f,g,h);
+ ROUND256(h,a,b,c,d,e,f,g);
+ ROUND256(g,h,a,b,c,d,e,f);
+ ROUND256(f,g,h,a,b,c,d,e);
+ ROUND256(e,f,g,h,a,b,c,d);
+ ROUND256(d,e,f,g,h,a,b,c);
+ ROUND256(c,d,e,f,g,h,a,b);
+ ROUND256(b,c,d,e,f,g,h,a);
+ } while (j < 64);
+
+ /* Compute the current intermediate hash value */
+ state[0] += a;
+ state[1] += b;
+ state[2] += c;
+ state[3] += d;
+ state[4] += e;
+ state[5] += f;
+ state[6] += g;
+ state[7] += h;
+
+ /* Clean up */
+ a = b = c = d = e = f = g = h = T1 = 0;
+}
+
+#else /* SHA2_UNROLL_TRANSFORM */
+
+void
+SHA256Transform(u_int32_t state[8], const u_int8_t data[SHA256_BLOCK_LENGTH])
+{
+ u_int32_t a, b, c, d, e, f, g, h, s0, s1;
+ u_int32_t T1, T2, W256[16];
+ int j;
+
+ /* Initialize registers with the prev. intermediate value */
+ a = state[0];
+ b = state[1];
+ c = state[2];
+ d = state[3];
+ e = state[4];
+ f = state[5];
+ g = state[6];
+ h = state[7];
+
+ j = 0;
+ do {
+ BE_8_TO_32(W256[j], data);
+ data += 4;
+ /* Apply the SHA-256 compression function to update a..h */
+ T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] + W256[j];
+ T2 = Sigma0_256(a) + Maj(a, b, c);
+ h = g;
+ g = f;
+ f = e;
+ e = d + T1;
+ d = c;
+ c = b;
+ b = a;
+ a = T1 + T2;
+
+ j++;
+ } while (j < 16);
+
+ do {
+ /* Part of the message block expansion: */
+ s0 = W256[(j+1)&0x0f];
+ s0 = sigma0_256(s0);
+ s1 = W256[(j+14)&0x0f];
+ s1 = sigma1_256(s1);
+
+ /* Apply the SHA-256 compression function to update a..h */
+ T1 = h + Sigma1_256(e) + Ch(e, f, g) + K256[j] +
+ (W256[j&0x0f] += s1 + W256[(j+9)&0x0f] + s0);
+ T2 = Sigma0_256(a) + Maj(a, b, c);
+ h = g;
+ g = f;
+ f = e;
+ e = d + T1;
+ d = c;
+ c = b;
+ b = a;
+ a = T1 + T2;
+
+ j++;
+ } while (j < 64);
+
+ /* Compute the current intermediate hash value */
+ state[0] += a;
+ state[1] += b;
+ state[2] += c;
+ state[3] += d;
+ state[4] += e;
+ state[5] += f;
+ state[6] += g;
+ state[7] += h;
+
+ /* Clean up */
+ a = b = c = d = e = f = g = h = T1 = T2 = 0;
+}
+
+#endif /* SHA2_UNROLL_TRANSFORM */
+DEF_WEAK(SHA256Transform);
+
+void
+SHA256Update(SHA2_CTX *context, const u_int8_t *data, size_t len)
+{
+ u_int64_t freespace, usedspace;
+
+ /* Calling with no data is valid (we do nothing) */
+ if (len == 0)
+ return;
+
+ usedspace = (context->bitcount[0] >> 3) % SHA256_BLOCK_LENGTH;
+ if (usedspace > 0) {
+ /* Calculate how much free space is available in the buffer */
+ freespace = SHA256_BLOCK_LENGTH - usedspace;
+
+ if (len >= freespace) {
+ /* Fill the buffer completely and process it */
+ memcpy(&context->buffer[usedspace], data, freespace);
+ context->bitcount[0] += freespace << 3;
+ len -= freespace;
+ data += freespace;
+ SHA256Transform(context->state.st32, context->buffer);
+ } else {
+ /* The buffer is not yet full */
+ memcpy(&context->buffer[usedspace], data, len);
+ context->bitcount[0] += (u_int64_t)len << 3;
+ /* Clean up: */
+ usedspace = freespace = 0;
+ return;
+ }
+ }
+ while (len >= SHA256_BLOCK_LENGTH) {
+ /* Process as many complete blocks as we can */
+ SHA256Transform(context->state.st32, data);
+ context->bitcount[0] += SHA256_BLOCK_LENGTH << 3;
+ len -= SHA256_BLOCK_LENGTH;
+ data += SHA256_BLOCK_LENGTH;
+ }
+ if (len > 0) {
+ /* There's left-overs, so save 'em */
+ memcpy(context->buffer, data, len);
+ context->bitcount[0] += len << 3;
+ }
+ /* Clean up: */
+ usedspace = freespace = 0;
+}
+DEF_WEAK(SHA256Update);
+
+void
+SHA256Pad(SHA2_CTX *context)
+{
+ unsigned int usedspace;
+
+ usedspace = (context->bitcount[0] >> 3) % SHA256_BLOCK_LENGTH;
+ if (usedspace > 0) {
+ /* Begin padding with a 1 bit: */
+ context->buffer[usedspace++] = 0x80;
+
+ if (usedspace <= SHA256_SHORT_BLOCK_LENGTH) {
+ /* Set-up for the last transform: */
+ memset(&context->buffer[usedspace], 0,
+ SHA256_SHORT_BLOCK_LENGTH - usedspace);
+ } else {
+ if (usedspace < SHA256_BLOCK_LENGTH) {
+ memset(&context->buffer[usedspace], 0,
+ SHA256_BLOCK_LENGTH - usedspace);
+ }
+ /* Do second-to-last transform: */
+ SHA256Transform(context->state.st32, context->buffer);
+
+ /* Prepare for last transform: */
+ memset(context->buffer, 0, SHA256_SHORT_BLOCK_LENGTH);
+ }
+ } else {
+ /* Set-up for the last transform: */
+ memset(context->buffer, 0, SHA256_SHORT_BLOCK_LENGTH);
+
+ /* Begin padding with a 1 bit: */
+ *context->buffer = 0x80;
+ }
+ /* Store the length of input data (in bits) in big endian format: */
+ BE_64_TO_8(&context->buffer[SHA256_SHORT_BLOCK_LENGTH],
+ context->bitcount[0]);
+
+ /* Final transform: */
+ SHA256Transform(context->state.st32, context->buffer);
+
+ /* Clean up: */
+ usedspace = 0;
+}
+DEF_WEAK(SHA256Pad);
+
+void
+SHA256Final(u_int8_t digest[SHA256_DIGEST_LENGTH], SHA2_CTX *context)
+{
+ SHA256Pad(context);
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+ int i;
+
+ /* Convert TO host byte order */
+ for (i = 0; i < 8; i++)
+ BE_32_TO_8(digest + i * 4, context->state.st32[i]);
+#else
+ memcpy(digest, context->state.st32, SHA256_DIGEST_LENGTH);
+#endif
+ explicit_bzero(context, sizeof(*context));
+}
+DEF_WEAK(SHA256Final);
+
+
+/*** SHA-512: *********************************************************/
+void
+SHA512Init(SHA2_CTX *context)
+{
+ memcpy(context->state.st64, sha512_initial_hash_value,
+ sizeof(sha512_initial_hash_value));
+ memset(context->buffer, 0, sizeof(context->buffer));
+ context->bitcount[0] = context->bitcount[1] = 0;
+}
+DEF_WEAK(SHA512Init);
+
+#ifdef SHA2_UNROLL_TRANSFORM
+
+/* Unrolled SHA-512 round macros: */
+
+#define ROUND512_0_TO_15(a,b,c,d,e,f,g,h) do { \
+ BE_8_TO_64(W512[j], data); \
+ data += 8; \
+ T1 = (h) + Sigma1_512((e)) + Ch((e), (f), (g)) + K512[j] + W512[j]; \
+ (d) += T1; \
+ (h) = T1 + Sigma0_512((a)) + Maj((a), (b), (c)); \
+ j++; \
+} while(0)
+
+
+#define ROUND512(a,b,c,d,e,f,g,h) do { \
+ s0 = W512[(j+1)&0x0f]; \
+ s0 = sigma0_512(s0); \
+ s1 = W512[(j+14)&0x0f]; \
+ s1 = sigma1_512(s1); \
+ T1 = (h) + Sigma1_512((e)) + Ch((e), (f), (g)) + K512[j] + \
+ (W512[j&0x0f] += s1 + W512[(j+9)&0x0f] + s0); \
+ (d) += T1; \
+ (h) = T1 + Sigma0_512((a)) + Maj((a), (b), (c)); \
+ j++; \
+} while(0)
+
+void
+SHA512Transform(u_int64_t state[8], const u_int8_t data[SHA512_BLOCK_LENGTH])
+{
+ u_int64_t a, b, c, d, e, f, g, h, s0, s1;
+ u_int64_t T1, W512[16];
+ int j;
+
+ /* Initialize registers with the prev. intermediate value */
+ a = state[0];
+ b = state[1];
+ c = state[2];
+ d = state[3];
+ e = state[4];
+ f = state[5];
+ g = state[6];
+ h = state[7];
+
+ j = 0;
+ do {
+ /* Rounds 0 to 15 (unrolled): */
+ ROUND512_0_TO_15(a,b,c,d,e,f,g,h);
+ ROUND512_0_TO_15(h,a,b,c,d,e,f,g);
+ ROUND512_0_TO_15(g,h,a,b,c,d,e,f);
+ ROUND512_0_TO_15(f,g,h,a,b,c,d,e);
+ ROUND512_0_TO_15(e,f,g,h,a,b,c,d);
+ ROUND512_0_TO_15(d,e,f,g,h,a,b,c);
+ ROUND512_0_TO_15(c,d,e,f,g,h,a,b);
+ ROUND512_0_TO_15(b,c,d,e,f,g,h,a);
+ } while (j < 16);
+
+ /* Now for the remaining rounds up to 79: */
+ do {
+ ROUND512(a,b,c,d,e,f,g,h);
+ ROUND512(h,a,b,c,d,e,f,g);
+ ROUND512(g,h,a,b,c,d,e,f);
+ ROUND512(f,g,h,a,b,c,d,e);
+ ROUND512(e,f,g,h,a,b,c,d);
+ ROUND512(d,e,f,g,h,a,b,c);
+ ROUND512(c,d,e,f,g,h,a,b);
+ ROUND512(b,c,d,e,f,g,h,a);
+ } while (j < 80);
+
+ /* Compute the current intermediate hash value */
+ state[0] += a;
+ state[1] += b;
+ state[2] += c;
+ state[3] += d;
+ state[4] += e;
+ state[5] += f;
+ state[6] += g;
+ state[7] += h;
+
+ /* Clean up */
+ a = b = c = d = e = f = g = h = T1 = 0;
+}
+
+#else /* SHA2_UNROLL_TRANSFORM */
+
+void
+SHA512Transform(u_int64_t state[8], const u_int8_t data[SHA512_BLOCK_LENGTH])
+{
+ u_int64_t a, b, c, d, e, f, g, h, s0, s1;
+ u_int64_t T1, T2, W512[16];
+ int j;
+
+ /* Initialize registers with the prev. intermediate value */
+ a = state[0];
+ b = state[1];
+ c = state[2];
+ d = state[3];
+ e = state[4];
+ f = state[5];
+ g = state[6];
+ h = state[7];
+
+ j = 0;
+ do {
+ BE_8_TO_64(W512[j], data);
+ data += 8;
+ /* Apply the SHA-512 compression function to update a..h */
+ T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] + W512[j];
+ T2 = Sigma0_512(a) + Maj(a, b, c);
+ h = g;
+ g = f;
+ f = e;
+ e = d + T1;
+ d = c;
+ c = b;
+ b = a;
+ a = T1 + T2;
+
+ j++;
+ } while (j < 16);
+
+ do {
+ /* Part of the message block expansion: */
+ s0 = W512[(j+1)&0x0f];
+ s0 = sigma0_512(s0);
+ s1 = W512[(j+14)&0x0f];
+ s1 = sigma1_512(s1);
+
+ /* Apply the SHA-512 compression function to update a..h */
+ T1 = h + Sigma1_512(e) + Ch(e, f, g) + K512[j] +
+ (W512[j&0x0f] += s1 + W512[(j+9)&0x0f] + s0);
+ T2 = Sigma0_512(a) + Maj(a, b, c);
+ h = g;
+ g = f;
+ f = e;
+ e = d + T1;
+ d = c;
+ c = b;
+ b = a;
+ a = T1 + T2;
+
+ j++;
+ } while (j < 80);
+
+ /* Compute the current intermediate hash value */
+ state[0] += a;
+ state[1] += b;
+ state[2] += c;
+ state[3] += d;
+ state[4] += e;
+ state[5] += f;
+ state[6] += g;
+ state[7] += h;
+
+ /* Clean up */
+ a = b = c = d = e = f = g = h = T1 = T2 = 0;
+}
+
+#endif /* SHA2_UNROLL_TRANSFORM */
+DEF_WEAK(SHA512Transform);
+
+void
+SHA512Update(SHA2_CTX *context, const u_int8_t *data, size_t len)
+{
+ size_t freespace, usedspace;
+
+ /* Calling with no data is valid (we do nothing) */
+ if (len == 0)
+ return;
+
+ usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH;
+ if (usedspace > 0) {
+ /* Calculate how much free space is available in the buffer */
+ freespace = SHA512_BLOCK_LENGTH - usedspace;
+
+ if (len >= freespace) {
+ /* Fill the buffer completely and process it */
+ memcpy(&context->buffer[usedspace], data, freespace);
+ ADDINC128(context->bitcount, freespace << 3);
+ len -= freespace;
+ data += freespace;
+ SHA512Transform(context->state.st64, context->buffer);
+ } else {
+ /* The buffer is not yet full */
+ memcpy(&context->buffer[usedspace], data, len);
+ ADDINC128(context->bitcount, len << 3);
+ /* Clean up: */
+ usedspace = freespace = 0;
+ return;
+ }
+ }
+ while (len >= SHA512_BLOCK_LENGTH) {
+ /* Process as many complete blocks as we can */
+ SHA512Transform(context->state.st64, data);
+ ADDINC128(context->bitcount, SHA512_BLOCK_LENGTH << 3);
+ len -= SHA512_BLOCK_LENGTH;
+ data += SHA512_BLOCK_LENGTH;
+ }
+ if (len > 0) {
+ /* There's left-overs, so save 'em */
+ memcpy(context->buffer, data, len);
+ ADDINC128(context->bitcount, len << 3);
+ }
+ /* Clean up: */
+ usedspace = freespace = 0;
+}
+DEF_WEAK(SHA512Update);
+
+void
+SHA512Pad(SHA2_CTX *context)
+{
+ unsigned int usedspace;
+
+ usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH;
+ if (usedspace > 0) {
+ /* Begin padding with a 1 bit: */
+ context->buffer[usedspace++] = 0x80;
+
+ if (usedspace <= SHA512_SHORT_BLOCK_LENGTH) {
+ /* Set-up for the last transform: */
+ memset(&context->buffer[usedspace], 0, SHA512_SHORT_BLOCK_LENGTH - usedspace);
+ } else {
+ if (usedspace < SHA512_BLOCK_LENGTH) {
+ memset(&context->buffer[usedspace], 0, SHA512_BLOCK_LENGTH - usedspace);
+ }
+ /* Do second-to-last transform: */
+ SHA512Transform(context->state.st64, context->buffer);
+
+ /* And set-up for the last transform: */
+ memset(context->buffer, 0, SHA512_BLOCK_LENGTH - 2);
+ }
+ } else {
+ /* Prepare for final transform: */
+ memset(context->buffer, 0, SHA512_SHORT_BLOCK_LENGTH);
+
+ /* Begin padding with a 1 bit: */
+ *context->buffer = 0x80;
+ }
+ /* Store the length of input data (in bits) in big endian format: */
+ BE_64_TO_8(&context->buffer[SHA512_SHORT_BLOCK_LENGTH],
+ context->bitcount[1]);
+ BE_64_TO_8(&context->buffer[SHA512_SHORT_BLOCK_LENGTH + 8],
+ context->bitcount[0]);
+
+ /* Final transform: */
+ SHA512Transform(context->state.st64, context->buffer);
+
+ /* Clean up: */
+ usedspace = 0;
+}
+DEF_WEAK(SHA512Pad);
+
+void
+SHA512Final(u_int8_t digest[SHA512_DIGEST_LENGTH], SHA2_CTX *context)
+{
+ SHA512Pad(context);
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+ int i;
+
+ /* Convert TO host byte order */
+ for (i = 0; i < 8; i++)
+ BE_64_TO_8(digest + i * 8, context->state.st64[i]);
+#else
+ memcpy(digest, context->state.st64, SHA512_DIGEST_LENGTH);
+#endif
+ explicit_bzero(context, sizeof(*context));
+}
+DEF_WEAK(SHA512Final);
+
+#if !defined(SHA2_SMALL)
+
+/*** SHA-384: *********************************************************/
+void
+SHA384Init(SHA2_CTX *context)
+{
+ memcpy(context->state.st64, sha384_initial_hash_value,
+ sizeof(sha384_initial_hash_value));
+ memset(context->buffer, 0, sizeof(context->buffer));
+ context->bitcount[0] = context->bitcount[1] = 0;
+}
+DEF_WEAK(SHA384Init);
+
+MAKE_CLONE(SHA384Transform, SHA512Transform);
+MAKE_CLONE(SHA384Update, SHA512Update);
+MAKE_CLONE(SHA384Pad, SHA512Pad);
+DEF_WEAK(SHA384Transform);
+DEF_WEAK(SHA384Update);
+DEF_WEAK(SHA384Pad);
+
+void
+SHA384Final(u_int8_t digest[SHA384_DIGEST_LENGTH], SHA2_CTX *context)
+{
+ SHA384Pad(context);
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+ int i;
+
+ /* Convert TO host byte order */
+ for (i = 0; i < 6; i++)
+ BE_64_TO_8(digest + i * 8, context->state.st64[i]);
+#else
+ memcpy(digest, context->state.st64, SHA384_DIGEST_LENGTH);
+#endif
+ /* Zero out state data */
+ explicit_bzero(context, sizeof(*context));
+}
+DEF_WEAK(SHA384Final);
+
+/*** SHA-512/256: *********************************************************/
+void
+SHA512_256Init(SHA2_CTX *context)
+{
+ memcpy(context->state.st64, sha512_256_initial_hash_value,
+ sizeof(sha512_256_initial_hash_value));
+ memset(context->buffer, 0, sizeof(context->buffer));
+ context->bitcount[0] = context->bitcount[1] = 0;
+}
+DEF_WEAK(SHA512_256Init);
+
+MAKE_CLONE(SHA512_256Transform, SHA512Transform);
+MAKE_CLONE(SHA512_256Update, SHA512Update);
+MAKE_CLONE(SHA512_256Pad, SHA512Pad);
+DEF_WEAK(SHA512_256Transform);
+DEF_WEAK(SHA512_256Update);
+DEF_WEAK(SHA512_256Pad);
+
+void
+SHA512_256Final(u_int8_t digest[SHA512_256_DIGEST_LENGTH], SHA2_CTX *context)
+{
+ SHA512_256Pad(context);
+
+#if BYTE_ORDER == LITTLE_ENDIAN
+ int i;
+
+ /* Convert TO host byte order */
+ for (i = 0; i < 4; i++)
+ BE_64_TO_8(digest + i * 8, context->state.st64[i]);
+#else
+ memcpy(digest, context->state.st64, SHA512_256_DIGEST_LENGTH);
+#endif
+ /* Zero out state data */
+ explicit_bzero(context, sizeof(*context));
+}
+DEF_WEAK(SHA512_256Final);
+#endif /* !defined(SHA2_SMALL) */
diff --git a/lib/libc/net/base64.c b/lib/libc/net/base64.c
new file mode 100644
index 0000000..e90696d
--- /dev/null
+++ b/lib/libc/net/base64.c
@@ -0,0 +1,315 @@
+/* $OpenBSD: base64.c,v 1.8 2015/01/16 16:48:51 deraadt Exp $ */
+
+/*
+ * Copyright (c) 1996 by Internet Software Consortium.
+ *
+ * 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 INTERNET SOFTWARE CONSORTIUM DISCLAIMS
+ * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
+ * CONSORTIUM 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.
+ */
+
+/*
+ * Portions Copyright (c) 1995 by International Business Machines, Inc.
+ *
+ * International Business Machines, Inc. (hereinafter called IBM) grants
+ * permission under its copyrights to use, copy, modify, and distribute this
+ * Software with or without fee, provided that the above copyright notice and
+ * all paragraphs of this notice appear in all copies, and that the name of IBM
+ * not be used in connection with the marketing of any product incorporating
+ * the Software or modifications thereof, without specific, written prior
+ * permission.
+ *
+ * To the extent it has a right to do so, IBM grants an immunity from suit
+ * under its patents, if any, for the use, sale or manufacture of products to
+ * the extent that such products are used for performing Domain Name System
+ * dynamic updates in TCP/IP networks by means of the Software. No immunity is
+ * granted for any product per se or for any other function of any product.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
+ * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL,
+ * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN
+ * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES.
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+#include <ctype.h>
+#include <resolv.h>
+#include <stdio.h>
+
+#include <stdlib.h>
+#include <string.h>
+
+static const char Base64[] =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+static const char Pad64 = '=';
+
+/* (From RFC1521 and draft-ietf-dnssec-secext-03.txt)
+ The following encoding technique is taken from RFC 1521 by Borenstein
+ and Freed. It is reproduced here in a slightly edited form for
+ convenience.
+
+ A 65-character subset of US-ASCII is used, enabling 6 bits to be
+ represented per printable character. (The extra 65th character, "=",
+ is used to signify a special processing function.)
+
+ The encoding process represents 24-bit groups of input bits as output
+ strings of 4 encoded characters. Proceeding from left to right, a
+ 24-bit input group is formed by concatenating 3 8-bit input groups.
+ These 24 bits are then treated as 4 concatenated 6-bit groups, each
+ of which is translated into a single digit in the base64 alphabet.
+
+ Each 6-bit group is used as an index into an array of 64 printable
+ characters. The character referenced by the index is placed in the
+ output string.
+
+ Table 1: The Base64 Alphabet
+
+ Value Encoding Value Encoding Value Encoding Value Encoding
+ 0 A 17 R 34 i 51 z
+ 1 B 18 S 35 j 52 0
+ 2 C 19 T 36 k 53 1
+ 3 D 20 U 37 l 54 2
+ 4 E 21 V 38 m 55 3
+ 5 F 22 W 39 n 56 4
+ 6 G 23 X 40 o 57 5
+ 7 H 24 Y 41 p 58 6
+ 8 I 25 Z 42 q 59 7
+ 9 J 26 a 43 r 60 8
+ 10 K 27 b 44 s 61 9
+ 11 L 28 c 45 t 62 +
+ 12 M 29 d 46 u 63 /
+ 13 N 30 e 47 v
+ 14 O 31 f 48 w (pad) =
+ 15 P 32 g 49 x
+ 16 Q 33 h 50 y
+
+ Special processing is performed if fewer than 24 bits are available
+ at the end of the data being encoded. A full encoding quantum is
+ always completed at the end of a quantity. When fewer than 24 input
+ bits are available in an input group, zero bits are added (on the
+ right) to form an integral number of 6-bit groups. Padding at the
+ end of the data is performed using the '=' character.
+
+ Since all base64 input is an integral number of octets, only the
+ -------------------------------------------------
+ following cases can arise:
+
+ (1) the final quantum of encoding input is an integral
+ multiple of 24 bits; here, the final unit of encoded
+ output will be an integral multiple of 4 characters
+ with no "=" padding,
+ (2) the final quantum of encoding input is exactly 8 bits;
+ here, the final unit of encoded output will be two
+ characters followed by two "=" padding characters, or
+ (3) the final quantum of encoding input is exactly 16 bits;
+ here, the final unit of encoded output will be three
+ characters followed by one "=" padding character.
+ */
+
+int
+b64_ntop(src, srclength, target, targsize)
+ u_char const *src;
+ size_t srclength;
+ char *target;
+ size_t targsize;
+{
+ size_t datalength = 0;
+ u_char input[3];
+ u_char output[4];
+ int i;
+
+ while (2 < srclength) {
+ input[0] = *src++;
+ input[1] = *src++;
+ input[2] = *src++;
+ srclength -= 3;
+
+ output[0] = input[0] >> 2;
+ output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
+ output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
+ output[3] = input[2] & 0x3f;
+
+ if (datalength + 4 > targsize)
+ return (-1);
+ target[datalength++] = Base64[output[0]];
+ target[datalength++] = Base64[output[1]];
+ target[datalength++] = Base64[output[2]];
+ target[datalength++] = Base64[output[3]];
+ }
+
+ /* Now we worry about padding. */
+ if (0 != srclength) {
+ /* Get what's left. */
+ input[0] = input[1] = input[2] = '\0';
+ for (i = 0; i < srclength; i++)
+ input[i] = *src++;
+
+ output[0] = input[0] >> 2;
+ output[1] = ((input[0] & 0x03) << 4) + (input[1] >> 4);
+ output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
+
+ if (datalength + 4 > targsize)
+ return (-1);
+ target[datalength++] = Base64[output[0]];
+ target[datalength++] = Base64[output[1]];
+ if (srclength == 1)
+ target[datalength++] = Pad64;
+ else
+ target[datalength++] = Base64[output[2]];
+ target[datalength++] = Pad64;
+ }
+ if (datalength >= targsize)
+ return (-1);
+ target[datalength] = '\0'; /* Returned value doesn't count \0. */
+ return (datalength);
+}
+
+/* skips all whitespace anywhere.
+ converts characters, four at a time, starting at (or after)
+ src from base - 64 numbers into three 8 bit bytes in the target area.
+ it returns the number of data bytes stored at the target, or -1 on error.
+ */
+
+int
+b64_pton(src, target, targsize)
+ char const *src;
+ u_char *target;
+ size_t targsize;
+{
+ int tarindex, state, ch;
+ u_char nextbyte;
+ char *pos;
+
+ state = 0;
+ tarindex = 0;
+
+ while ((ch = (unsigned char)*src++) != '\0') {
+ if (isspace(ch)) /* Skip whitespace anywhere. */
+ continue;
+
+ if (ch == Pad64)
+ break;
+
+ pos = strchr(Base64, ch);
+ if (pos == 0) /* A non-base64 character. */
+ return (-1);
+
+ switch (state) {
+ case 0:
+ if (target) {
+ if (tarindex >= targsize)
+ return (-1);
+ target[tarindex] = (pos - Base64) << 2;
+ }
+ state = 1;
+ break;
+ case 1:
+ if (target) {
+ if (tarindex >= targsize)
+ return (-1);
+ target[tarindex] |= (pos - Base64) >> 4;
+ nextbyte = ((pos - Base64) & 0x0f) << 4;
+ if (tarindex + 1 < targsize)
+ target[tarindex+1] = nextbyte;
+ else if (nextbyte)
+ return (-1);
+ }
+ tarindex++;
+ state = 2;
+ break;
+ case 2:
+ if (target) {
+ if (tarindex >= targsize)
+ return (-1);
+ target[tarindex] |= (pos - Base64) >> 2;
+ nextbyte = ((pos - Base64) & 0x03) << 6;
+ if (tarindex + 1 < targsize)
+ target[tarindex+1] = nextbyte;
+ else if (nextbyte)
+ return (-1);
+ }
+ tarindex++;
+ state = 3;
+ break;
+ case 3:
+ if (target) {
+ if (tarindex >= targsize)
+ return (-1);
+ target[tarindex] |= (pos - Base64);
+ }
+ tarindex++;
+ state = 0;
+ break;
+ }
+ }
+
+ /*
+ * We are done decoding Base-64 chars. Let's see if we ended
+ * on a byte boundary, and/or with erroneous trailing characters.
+ */
+
+ if (ch == Pad64) { /* We got a pad char. */
+ ch = (unsigned char)*src++; /* Skip it, get next. */
+ switch (state) {
+ case 0: /* Invalid = in first position */
+ case 1: /* Invalid = in second position */
+ return (-1);
+
+ case 2: /* Valid, means one byte of info */
+ /* Skip any number of spaces. */
+ for (; ch != '\0'; ch = (unsigned char)*src++)
+ if (!isspace(ch))
+ break;
+ /* Make sure there is another trailing = sign. */
+ if (ch != Pad64)
+ return (-1);
+ ch = (unsigned char)*src++; /* Skip the = */
+ /* Fall through to "single trailing =" case. */
+ /* FALLTHROUGH */
+
+ case 3: /* Valid, means two bytes of info */
+ /*
+ * We know this char is an =. Is there anything but
+ * whitespace after it?
+ */
+ for (; ch != '\0'; ch = (unsigned char)*src++)
+ if (!isspace(ch))
+ return (-1);
+
+ /*
+ * Now make sure for cases 2 and 3 that the "extra"
+ * bits that slopped past the last full byte were
+ * zeros. If we don't check them, they become a
+ * subliminal channel.
+ */
+ if (target && tarindex < targsize &&
+ target[tarindex] != 0)
+ return (-1);
+ }
+ } else {
+ /*
+ * We ended by seeing the end of the string. Make sure we
+ * have no partial bytes lying around.
+ */
+ if (state != 0)
+ return (-1);
+ }
+
+ return (tarindex);
+}
diff --git a/lib/libc/stdlib/freezero.c b/lib/libc/stdlib/freezero.c
new file mode 100644
index 0000000..31face3
--- /dev/null
+++ b/lib/libc/stdlib/freezero.c
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net>
+ * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org>
+ * Copyright (c) 2008 Damien Miller <djm@openbsd.org>
+ * Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org>
+ *
+ * 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 <string.h>
+#include <stdlib.h>
+
+void
+freezero(void *ptr, size_t sz)
+{
+ /* This is legal. */
+ if (ptr == NULL)
+ return;
+
+ explicit_bzero(ptr, sz);
+ free(ptr);
+}
diff --git a/lib/libc/stdlib/reallocarray.c b/lib/libc/stdlib/reallocarray.c
new file mode 100644
index 0000000..baea252
--- /dev/null
+++ b/lib/libc/stdlib/reallocarray.c
@@ -0,0 +1,39 @@
+/* $OpenBSD: reallocarray.c,v 1.3 2015/09/13 08:31:47 guenther Exp $ */
+/*
+ * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net>
+ *
+ * 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 <sys/types.h>
+#include <errno.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+/*
+ * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
+ * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
+ */
+#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
+
+void *
+reallocarray(void *optr, size_t nmemb, size_t size)
+{
+ if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
+ nmemb > 0 && SIZE_MAX / nmemb < size) {
+ errno = ENOMEM;
+ return NULL;
+ }
+ return realloc(optr, size * nmemb);
+}
+DEF_WEAK(reallocarray);
diff --git a/lib/libc/stdlib/recallocarray.c b/lib/libc/stdlib/recallocarray.c
new file mode 100644
index 0000000..a2f37fe
--- /dev/null
+++ b/lib/libc/stdlib/recallocarray.c
@@ -0,0 +1,81 @@
+/* $OpenBSD: recallocarray.c,v 1.1 2017/03/06 18:44:21 otto Exp $ */
+/*
+ * Copyright (c) 2008, 2017 Otto Moerbeek <otto@drijf.net>
+ *
+ * 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 <errno.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <unistd.h>
+
+/*
+ * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
+ * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
+ */
+#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
+
+void *
+recallocarray(void *ptr, size_t oldnmemb, size_t newnmemb, size_t size)
+{
+ size_t oldsize, newsize;
+ void *newptr;
+
+ if (ptr == NULL)
+ return calloc(newnmemb, size);
+
+ if ((newnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
+ newnmemb > 0 && SIZE_MAX / newnmemb < size) {
+ errno = ENOMEM;
+ return NULL;
+ }
+ newsize = newnmemb * size;
+
+ if ((oldnmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
+ oldnmemb > 0 && SIZE_MAX / oldnmemb < size) {
+ errno = EINVAL;
+ return NULL;
+ }
+ oldsize = oldnmemb * size;
+
+ /*
+ * Don't bother too much if we're shrinking just a bit,
+ * we do not shrink for series of small steps, oh well.
+ */
+ if (newsize <= oldsize) {
+ size_t d = oldsize - newsize;
+
+ if (d < oldsize / 2 && d < getpagesize()) {
+ memset((char *)ptr + newsize, 0, d);
+ return ptr;
+ }
+ }
+
+ newptr = malloc(newsize);
+ if (newptr == NULL)
+ return NULL;
+
+ if (newsize > oldsize) {
+ memcpy(newptr, ptr, oldsize);
+ memset((char *)newptr + oldsize, 0, newsize - oldsize);
+ } else
+ memcpy(newptr, ptr, newsize);
+
+ explicit_bzero(ptr, oldsize);
+ free(ptr);
+
+ return newptr;
+}
+DEF_WEAK(recallocarray);
diff --git a/lib/libc/stdlib/strtonum.c b/lib/libc/stdlib/strtonum.c
new file mode 100644
index 0000000..ad22d1c
--- /dev/null
+++ b/lib/libc/stdlib/strtonum.c
@@ -0,0 +1,66 @@
+/* $OpenBSD: strtonum.c,v 1.8 2015/09/13 08:31:48 guenther Exp $ */
+
+/*
+ * Copyright (c) 2004 Ted Unangst and Todd Miller
+ * All rights reserved.
+ *
+ * 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 <errno.h>
+#include <limits.h>
+#include <stdlib.h>
+
+#define INVALID 1
+#define TOOSMALL 2
+#define TOOLARGE 3
+
+long long
+strtonum(const char *numstr, long long minval, long long maxval,
+ const char **errstrp)
+{
+ long long ll = 0;
+ int error = 0;
+ char *ep;
+ struct errval {
+ const char *errstr;
+ int err;
+ } ev[4] = {
+ { NULL, 0 },
+ { "invalid", EINVAL },
+ { "too small", ERANGE },
+ { "too large", ERANGE },
+ };
+
+ ev[0].err = errno;
+ errno = 0;
+ if (minval > maxval) {
+ error = INVALID;
+ } else {
+ ll = strtoll(numstr, &ep, 10);
+ if (numstr == ep || *ep != '\0')
+ error = INVALID;
+ else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval)
+ error = TOOSMALL;
+ else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval)
+ error = TOOLARGE;
+ }
+ if (errstrp != NULL)
+ *errstrp = ev[error].errstr;
+ errno = ev[error].err;
+ if (error)
+ ll = 0;
+
+ return (ll);
+}
+DEF_WEAK(strtonum);
diff --git a/lib/libc/string/strmode.c b/lib/libc/string/strmode.c
new file mode 100644
index 0000000..609b893
--- /dev/null
+++ b/lib/libc/string/strmode.c
@@ -0,0 +1,141 @@
+/* $OpenBSD: strmode.c,v 1.8 2015/08/31 02:53:57 guenther Exp $ */
+/*-
+ * Copyright (c) 1990 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.
+ */
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <string.h>
+
+/* XXX mode should be mode_t */
+
+void
+strmode(int mode, char *p)
+{
+ /* print type */
+ switch (mode & S_IFMT) {
+ case S_IFDIR: /* directory */
+ *p++ = 'd';
+ break;
+ case S_IFCHR: /* character special */
+ *p++ = 'c';
+ break;
+ case S_IFBLK: /* block special */
+ *p++ = 'b';
+ break;
+ case S_IFREG: /* regular */
+ *p++ = '-';
+ break;
+ case S_IFLNK: /* symbolic link */
+ *p++ = 'l';
+ break;
+ case S_IFSOCK: /* socket */
+ *p++ = 's';
+ break;
+#ifdef S_IFIFO
+ case S_IFIFO: /* fifo */
+ *p++ = 'p';
+ break;
+#endif
+ default: /* unknown */
+ *p++ = '?';
+ break;
+ }
+ /* usr */
+ if (mode & S_IRUSR)
+ *p++ = 'r';
+ else
+ *p++ = '-';
+ if (mode & S_IWUSR)
+ *p++ = 'w';
+ else
+ *p++ = '-';
+ switch (mode & (S_IXUSR | S_ISUID)) {
+ case 0:
+ *p++ = '-';
+ break;
+ case S_IXUSR:
+ *p++ = 'x';
+ break;
+ case S_ISUID:
+ *p++ = 'S';
+ break;
+ case S_IXUSR | S_ISUID:
+ *p++ = 's';
+ break;
+ }
+ /* group */
+ if (mode & S_IRGRP)
+ *p++ = 'r';
+ else
+ *p++ = '-';
+ if (mode & S_IWGRP)
+ *p++ = 'w';
+ else
+ *p++ = '-';
+ switch (mode & (S_IXGRP | S_ISGID)) {
+ case 0:
+ *p++ = '-';
+ break;
+ case S_IXGRP:
+ *p++ = 'x';
+ break;
+ case S_ISGID:
+ *p++ = 'S';
+ break;
+ case S_IXGRP | S_ISGID:
+ *p++ = 's';
+ break;
+ }
+ /* other */
+ if (mode & S_IROTH)
+ *p++ = 'r';
+ else
+ *p++ = '-';
+ if (mode & S_IWOTH)
+ *p++ = 'w';
+ else
+ *p++ = '-';
+ switch (mode & (S_IXOTH | S_ISVTX)) {
+ case 0:
+ *p++ = '-';
+ break;
+ case S_IXOTH:
+ *p++ = 'x';
+ break;
+ case S_ISVTX:
+ *p++ = 'T';
+ break;
+ case S_IXOTH | S_ISVTX:
+ *p++ = 't';
+ break;
+ }
+ *p++ = ' '; /* will be a '+' if ACL's implemented */
+ *p = '\0';
+}
+DEF_WEAK(strmode);
diff --git a/lib/libc/string/timingsafe_bcmp.c b/lib/libc/string/timingsafe_bcmp.c
new file mode 100644
index 0000000..0409ec3
--- /dev/null
+++ b/lib/libc/string/timingsafe_bcmp.c
@@ -0,0 +1,30 @@
+/* $OpenBSD: timingsafe_bcmp.c,v 1.3 2015/08/31 02:53:57 guenther Exp $ */
+/*
+ * Copyright (c) 2010 Damien Miller. All rights reserved.
+ *
+ * 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 <string.h>
+
+int
+timingsafe_bcmp(const void *b1, const void *b2, size_t n)
+{
+ const unsigned char *p1 = b1, *p2 = b2;
+ int ret = 0;
+
+ for (; n > 0; n--)
+ ret |= *p1++ ^ *p2++;
+ return (ret != 0);
+}
+DEF_WEAK(timingsafe_bcmp);
diff --git a/lib/libc/string/timingsafe_memcmp.c b/lib/libc/string/timingsafe_memcmp.c
new file mode 100644
index 0000000..373f8cb
--- /dev/null
+++ b/lib/libc/string/timingsafe_memcmp.c
@@ -0,0 +1,47 @@
+/* $OpenBSD: timingsafe_memcmp.c,v 1.2 2015/08/31 02:53:57 guenther Exp $ */
+/*
+ * Copyright (c) 2014 Google Inc.
+ *
+ * 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 <limits.h>
+#include <string.h>
+
+int
+timingsafe_memcmp(const void *b1, const void *b2, size_t len)
+{
+ const unsigned char *p1 = b1, *p2 = b2;
+ size_t i;
+ int res = 0, done = 0;
+
+ for (i = 0; i < len; i++) {
+ /* lt is -1 if p1[i] < p2[i]; else 0. */
+ int lt = (p1[i] - p2[i]) >> CHAR_BIT;
+
+ /* gt is -1 if p1[i] > p2[i]; else 0. */
+ int gt = (p2[i] - p1[i]) >> CHAR_BIT;
+
+ /* cmp is 1 if p1[i] > p2[i]; -1 if p1[i] < p2[i]; else 0. */
+ int cmp = lt - gt;
+
+ /* set res = cmp if !done. */
+ res |= cmp & ~done;
+
+ /* set done if p1[i] != p2[i]. */
+ done |= lt | gt;
+ }
+
+ return (res);
+}
+DEF_WEAK(timingsafe_memcmp);
diff --git a/lib/libcrypto/arc4random/arc4random_linux.h b/lib/libcrypto/arc4random/arc4random_linux.h
new file mode 100644
index 0000000..5e1cf34
--- /dev/null
+++ b/lib/libcrypto/arc4random/arc4random_linux.h
@@ -0,0 +1,88 @@
+/* $OpenBSD: arc4random_linux.h,v 1.12 2019/07/11 10:37:28 inoguchi Exp $ */
+
+/*
+ * Copyright (c) 1996, David Mazieres <dm@uun.org>
+ * Copyright (c) 2008, Damien Miller <djm@openbsd.org>
+ * Copyright (c) 2013, Markus Friedl <markus@openbsd.org>
+ * Copyright (c) 2014, Theo de Raadt <deraadt@openbsd.org>
+ *
+ * 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.
+ */
+
+/*
+ * Stub functions for portability.
+ */
+
+#include <sys/mman.h>
+
+#include <pthread.h>
+#include <signal.h>
+
+static pthread_mutex_t arc4random_mtx = PTHREAD_MUTEX_INITIALIZER;
+#define _ARC4_LOCK() pthread_mutex_lock(&arc4random_mtx)
+#define _ARC4_UNLOCK() pthread_mutex_unlock(&arc4random_mtx)
+
+#if defined(__GLIBC__) && !(defined(__UCLIBC__) && !defined(__ARCH_USE_MMU__))
+extern void *__dso_handle;
+extern int __register_atfork(void (*)(void), void(*)(void), void (*)(void), void *);
+#define _ARC4_ATFORK(f) __register_atfork(NULL, NULL, (f), __dso_handle)
+#else
+#define _ARC4_ATFORK(f) pthread_atfork(NULL, NULL, (f))
+#endif
+
+static inline void
+_getentropy_fail(void)
+{
+ raise(SIGKILL);
+}
+
+static volatile sig_atomic_t _rs_forked;
+
+static inline void
+_rs_forkhandler(void)
+{
+ _rs_forked = 1;
+}
+
+static inline void
+_rs_forkdetect(void)
+{
+ static pid_t _rs_pid = 0;
+ pid_t pid = getpid();
+
+ /* XXX unusual calls to clone() can bypass checks */
+ if (_rs_pid == 0 || _rs_pid == 1 || _rs_pid != pid || _rs_forked) {
+ _rs_pid = pid;
+ _rs_forked = 0;
+ if (rs)
+ memset(rs, 0, sizeof(*rs));
+ }
+}
+
+static inline int
+_rs_allocate(struct _rs **rsp, struct _rsx **rsxp)
+{
+ if ((*rsp = mmap(NULL, sizeof(**rsp), PROT_READ|PROT_WRITE,
+ MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED)
+ return (-1);
+
+ if ((*rsxp = mmap(NULL, sizeof(**rsxp), PROT_READ|PROT_WRITE,
+ MAP_ANON|MAP_PRIVATE, -1, 0)) == MAP_FAILED) {
+ munmap(*rsp, sizeof(**rsp));
+ *rsp = NULL;
+ return (-1);
+ }
+
+ _ARC4_ATFORK(_rs_forkhandler);
+ return (0);
+}
diff --git a/lib/libcrypto/md32_common.h b/lib/libcrypto/md32_common.h
new file mode 100644
index 0000000..0dca617
--- /dev/null
+++ b/lib/libcrypto/md32_common.h
@@ -0,0 +1,345 @@
+/* $OpenBSD: md32_common.h,v 1.22 2016/11/04 13:56:04 miod Exp $ */
+/* ====================================================================
+ * Copyright (c) 1999-2007 The OpenSSL Project. 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. All advertising materials mentioning features or use of this
+ * software must display the following acknowledgment:
+ * "This product includes software developed by the OpenSSL Project
+ * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ * endorse or promote products derived from this software without
+ * prior written permission. For written permission, please contact
+ * licensing@OpenSSL.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ * nor may "OpenSSL" appear in their names without prior written
+ * permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ * acknowledgment:
+ * "This product includes software developed by the OpenSSL Project
+ * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
+ * EXPRESSED 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 OpenSSL PROJECT OR
+ * ITS 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 is a generic 32 bit "collector" for message digest algorithms.
+ * Whenever needed it collects input character stream into chunks of
+ * 32 bit values and invokes a block function that performs actual hash
+ * calculations.
+ *
+ * Porting guide.
+ *
+ * Obligatory macros:
+ *
+ * DATA_ORDER_IS_BIG_ENDIAN or DATA_ORDER_IS_LITTLE_ENDIAN
+ * this macro defines byte order of input stream.
+ * HASH_CBLOCK
+ * size of a unit chunk HASH_BLOCK operates on.
+ * HASH_LONG
+ * has to be at least 32 bit wide.
+ * HASH_CTX
+ * context structure that at least contains following
+ * members:
+ * typedef struct {
+ * ...
+ * HASH_LONG Nl,Nh;
+ * either {
+ * HASH_LONG data[HASH_LBLOCK];
+ * unsigned char data[HASH_CBLOCK];
+ * };
+ * unsigned int num;
+ * ...
+ * } HASH_CTX;
+ * data[] vector is expected to be zeroed upon first call to
+ * HASH_UPDATE.
+ * HASH_UPDATE
+ * name of "Update" function, implemented here.
+ * HASH_TRANSFORM
+ * name of "Transform" function, implemented here.
+ * HASH_FINAL
+ * name of "Final" function, implemented here.
+ * HASH_BLOCK_DATA_ORDER
+ * name of "block" function capable of treating *unaligned* input
+ * message in original (data) byte order, implemented externally.
+ * HASH_MAKE_STRING
+ * macro convering context variables to an ASCII hash string.
+ *
+ * MD5 example:
+ *
+ * #define DATA_ORDER_IS_LITTLE_ENDIAN
+ *
+ * #define HASH_LONG MD5_LONG
+ * #define HASH_CTX MD5_CTX
+ * #define HASH_CBLOCK MD5_CBLOCK
+ * #define HASH_UPDATE MD5_Update
+ * #define HASH_TRANSFORM MD5_Transform
+ * #define HASH_FINAL MD5_Final
+ * #define HASH_BLOCK_DATA_ORDER md5_block_data_order
+ *
+ * <appro@fy.chalmers.se>
+ */
+
+#include <stdint.h>
+
+#include <openssl/opensslconf.h>
+
+#if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN)
+#error "DATA_ORDER must be defined!"
+#endif
+
+#ifndef HASH_CBLOCK
+#error "HASH_CBLOCK must be defined!"
+#endif
+#ifndef HASH_LONG
+#error "HASH_LONG must be defined!"
+#endif
+#ifndef HASH_CTX
+#error "HASH_CTX must be defined!"
+#endif
+
+#ifndef HASH_UPDATE
+#error "HASH_UPDATE must be defined!"
+#endif
+#ifndef HASH_TRANSFORM
+#error "HASH_TRANSFORM must be defined!"
+#endif
+#if !defined(HASH_FINAL) && !defined(HASH_NO_FINAL)
+#error "HASH_FINAL or HASH_NO_FINAL must be defined!"
+#endif
+
+#ifndef HASH_BLOCK_DATA_ORDER
+#error "HASH_BLOCK_DATA_ORDER must be defined!"
+#endif
+
+/*
+ * This common idiom is recognized by the compiler and turned into a
+ * CPU-specific intrinsic as appropriate.
+ * e.g. GCC optimizes to roll on amd64 at -O0
+ */
+static inline uint32_t ROTATE(uint32_t a, uint32_t n)
+{
+ return (a<<n)|(a>>(32-n));
+}
+
+#if defined(DATA_ORDER_IS_BIG_ENDIAN)
+
+#if defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
+# if (defined(__i386) || defined(__i386__) || \
+ defined(__x86_64) || defined(__x86_64__))
+ /*
+ * This gives ~30-40% performance improvement in SHA-256 compiled
+ * with gcc [on P4]. Well, first macro to be frank. We can pull
+ * this trick on x86* platforms only, because these CPUs can fetch
+ * unaligned data without raising an exception.
+ */
+# define HOST_c2l(c,l) ({ unsigned int r=*((const unsigned int *)(c)); \
+ asm ("bswapl %0":"=r"(r):"0"(r)); \
+ (c)+=4; (l)=r; })
+# define HOST_l2c(l,c) ({ unsigned int r=(l); \
+ asm ("bswapl %0":"=r"(r):"0"(r)); \
+ *((unsigned int *)(c))=r; (c)+=4; })
+# endif
+#endif
+
+#ifndef HOST_c2l
+#define HOST_c2l(c,l) do {l =(((unsigned long)(*((c)++)))<<24); \
+ l|=(((unsigned long)(*((c)++)))<<16); \
+ l|=(((unsigned long)(*((c)++)))<< 8); \
+ l|=(((unsigned long)(*((c)++))) ); \
+ } while (0)
+#endif
+#ifndef HOST_l2c
+#define HOST_l2c(l,c) do {*((c)++)=(unsigned char)(((l)>>24)&0xff); \
+ *((c)++)=(unsigned char)(((l)>>16)&0xff); \
+ *((c)++)=(unsigned char)(((l)>> 8)&0xff); \
+ *((c)++)=(unsigned char)(((l) )&0xff); \
+ } while (0)
+#endif
+
+#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
+
+#if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)
+# define HOST_c2l(c,l) ((l)=*((const unsigned int *)(c)), (c)+=4)
+# define HOST_l2c(l,c) (*((unsigned int *)(c))=(l), (c)+=4)
+#endif
+
+#ifndef HOST_c2l
+#define HOST_c2l(c,l) do {l =(((unsigned long)(*((c)++))) ); \
+ l|=(((unsigned long)(*((c)++)))<< 8); \
+ l|=(((unsigned long)(*((c)++)))<<16); \
+ l|=(((unsigned long)(*((c)++)))<<24); \
+ } while (0)
+#endif
+#ifndef HOST_l2c
+#define HOST_l2c(l,c) do {*((c)++)=(unsigned char)(((l) )&0xff); \
+ *((c)++)=(unsigned char)(((l)>> 8)&0xff); \
+ *((c)++)=(unsigned char)(((l)>>16)&0xff); \
+ *((c)++)=(unsigned char)(((l)>>24)&0xff); \
+ } while (0)
+#endif
+
+#endif
+
+/*
+ * Time for some action:-)
+ */
+
+int
+HASH_UPDATE(HASH_CTX *c, const void *data_, size_t len)
+{
+ const unsigned char *data = data_;
+ unsigned char *p;
+ HASH_LONG l;
+ size_t n;
+
+ if (len == 0)
+ return 1;
+
+ l = (c->Nl + (((HASH_LONG)len) << 3))&0xffffffffUL;
+ /* 95-05-24 eay Fixed a bug with the overflow handling, thanks to
+ * Wei Dai <weidai@eskimo.com> for pointing it out. */
+ if (l < c->Nl) /* overflow */
+ c->Nh++;
+ c->Nh+=(HASH_LONG)(len>>29); /* might cause compiler warning on 16-bit */
+ c->Nl = l;
+
+ n = c->num;
+ if (n != 0) {
+ p = (unsigned char *)c->data;
+
+ if (len >= HASH_CBLOCK || len + n >= HASH_CBLOCK) {
+ memcpy (p + n, data, HASH_CBLOCK - n);
+ HASH_BLOCK_DATA_ORDER (c, p, 1);
+ n = HASH_CBLOCK - n;
+ data += n;
+ len -= n;
+ c->num = 0;
+ memset (p,0,HASH_CBLOCK); /* keep it zeroed */
+ } else {
+ memcpy (p + n, data, len);
+ c->num += (unsigned int)len;
+ return 1;
+ }
+ }
+
+ n = len/HASH_CBLOCK;
+ if (n > 0) {
+ HASH_BLOCK_DATA_ORDER (c, data, n);
+ n *= HASH_CBLOCK;
+ data += n;
+ len -= n;
+ }
+
+ if (len != 0) {
+ p = (unsigned char *)c->data;
+ c->num = (unsigned int)len;
+ memcpy (p, data, len);
+ }
+ return 1;
+}
+
+
+void HASH_TRANSFORM (HASH_CTX *c, const unsigned char *data)
+{
+ HASH_BLOCK_DATA_ORDER (c, data, 1);
+}
+
+
+#ifndef HASH_NO_FINAL
+int HASH_FINAL (unsigned char *md, HASH_CTX *c)
+{
+ unsigned char *p = (unsigned char *)c->data;
+ size_t n = c->num;
+
+ p[n] = 0x80; /* there is always room for one */
+ n++;
+
+ if (n > (HASH_CBLOCK - 8)) {
+ memset (p + n, 0, HASH_CBLOCK - n);
+ n = 0;
+ HASH_BLOCK_DATA_ORDER (c, p, 1);
+ }
+ memset (p + n, 0, HASH_CBLOCK - 8 - n);
+
+ p += HASH_CBLOCK - 8;
+#if defined(DATA_ORDER_IS_BIG_ENDIAN)
+ HOST_l2c(c->Nh, p);
+ HOST_l2c(c->Nl, p);
+#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
+ HOST_l2c(c->Nl, p);
+ HOST_l2c(c->Nh, p);
+#endif
+ p -= HASH_CBLOCK;
+ HASH_BLOCK_DATA_ORDER (c, p, 1);
+ c->num = 0;
+ memset (p, 0, HASH_CBLOCK);
+
+#ifndef HASH_MAKE_STRING
+#error "HASH_MAKE_STRING must be defined!"
+#else
+ HASH_MAKE_STRING(c, md);
+#endif
+
+ return 1;
+}
+#endif
+
+#ifndef MD32_REG_T
+#if defined(__alpha) || defined(__sparcv9) || defined(__mips)
+#define MD32_REG_T long
+/*
+ * This comment was originaly written for MD5, which is why it
+ * discusses A-D. But it basically applies to all 32-bit digests,
+ * which is why it was moved to common header file.
+ *
+ * In case you wonder why A-D are declared as long and not
+ * as MD5_LONG. Doing so results in slight performance
+ * boost on LP64 architectures. The catch is we don't
+ * really care if 32 MSBs of a 64-bit register get polluted
+ * with eventual overflows as we *save* only 32 LSBs in
+ * *either* case. Now declaring 'em long excuses the compiler
+ * from keeping 32 MSBs zeroed resulting in 13% performance
+ * improvement under SPARC Solaris7/64 and 5% under AlphaLinux.
+ * Well, to be honest it should say that this *prevents*
+ * performance degradation.
+ * <appro@fy.chalmers.se>
+ */
+#else
+/*
+ * Above is not absolute and there are LP64 compilers that
+ * generate better code if MD32_REG_T is defined int. The above
+ * pre-processor condition reflects the circumstances under which
+ * the conclusion was made and is subject to further extension.
+ * <appro@fy.chalmers.se>
+ */
+#define MD32_REG_T int
+#endif
+#endif
diff --git a/lib/libcrypto/sha/sha256.c b/lib/libcrypto/sha/sha256.c
new file mode 100644
index 0000000..9c05d3b
--- /dev/null
+++ b/lib/libcrypto/sha/sha256.c
@@ -0,0 +1,284 @@
+/* $OpenBSD: sha256.c,v 1.10 2019/01/21 23:20:31 jsg Exp $ */
+/* ====================================================================
+ * Copyright (c) 2004 The OpenSSL Project. All rights reserved
+ * according to the OpenSSL license [found in ../../LICENSE].
+ * ====================================================================
+ */
+
+#include <openssl/opensslconf.h>
+
+#if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA256)
+
+#include <machine/endian.h>
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <openssl/crypto.h>
+#include <openssl/sha.h>
+#include <openssl/opensslv.h>
+
+int SHA224_Init(SHA256_CTX *c)
+ {
+ memset (c,0,sizeof(*c));
+ c->h[0]=0xc1059ed8UL; c->h[1]=0x367cd507UL;
+ c->h[2]=0x3070dd17UL; c->h[3]=0xf70e5939UL;
+ c->h[4]=0xffc00b31UL; c->h[5]=0x68581511UL;
+ c->h[6]=0x64f98fa7UL; c->h[7]=0xbefa4fa4UL;
+ c->md_len=SHA224_DIGEST_LENGTH;
+ return 1;
+ }
+
+int SHA256_Init(SHA256_CTX *c)
+ {
+ memset (c,0,sizeof(*c));
+ c->h[0]=0x6a09e667UL; c->h[1]=0xbb67ae85UL;
+ c->h[2]=0x3c6ef372UL; c->h[3]=0xa54ff53aUL;
+ c->h[4]=0x510e527fUL; c->h[5]=0x9b05688cUL;
+ c->h[6]=0x1f83d9abUL; c->h[7]=0x5be0cd19UL;
+ c->md_len=SHA256_DIGEST_LENGTH;
+ return 1;
+ }
+
+unsigned char *SHA224(const unsigned char *d, size_t n, unsigned char *md)
+ {
+ SHA256_CTX c;
+ static unsigned char m[SHA224_DIGEST_LENGTH];
+
+ if (md == NULL) md=m;
+ SHA224_Init(&c);
+ SHA256_Update(&c,d,n);
+ SHA256_Final(md,&c);
+ explicit_bzero(&c,sizeof(c));
+ return(md);
+ }
+
+unsigned char *SHA256(const unsigned char *d, size_t n, unsigned char *md)
+ {
+ SHA256_CTX c;
+ static unsigned char m[SHA256_DIGEST_LENGTH];
+
+ if (md == NULL) md=m;
+ SHA256_Init(&c);
+ SHA256_Update(&c,d,n);
+ SHA256_Final(md,&c);
+ explicit_bzero(&c,sizeof(c));
+ return(md);
+ }
+
+int SHA224_Update(SHA256_CTX *c, const void *data, size_t len)
+{ return SHA256_Update (c,data,len); }
+int SHA224_Final (unsigned char *md, SHA256_CTX *c)
+{ return SHA256_Final (md,c); }
+
+#define DATA_ORDER_IS_BIG_ENDIAN
+
+#define HASH_LONG SHA_LONG
+#define HASH_CTX SHA256_CTX
+#define HASH_CBLOCK SHA_CBLOCK
+/*
+ * Note that FIPS180-2 discusses "Truncation of the Hash Function Output."
+ * default: case below covers for it. It's not clear however if it's
+ * permitted to truncate to amount of bytes not divisible by 4. I bet not,
+ * but if it is, then default: case shall be extended. For reference.
+ * Idea behind separate cases for pre-defined lengths is to let the
+ * compiler decide if it's appropriate to unroll small loops.
+ */
+#define HASH_MAKE_STRING(c,s) do { \
+ unsigned long ll; \
+ unsigned int nn; \
+ switch ((c)->md_len) \
+ { case SHA224_DIGEST_LENGTH: \
+ for (nn=0;nn<SHA224_DIGEST_LENGTH/4;nn++) \
+ { ll=(c)->h[nn]; HOST_l2c(ll,(s)); } \
+ break; \
+ case SHA256_DIGEST_LENGTH: \
+ for (nn=0;nn<SHA256_DIGEST_LENGTH/4;nn++) \
+ { ll=(c)->h[nn]; HOST_l2c(ll,(s)); } \
+ break; \
+ default: \
+ if ((c)->md_len > SHA256_DIGEST_LENGTH) \
+ return 0; \
+ for (nn=0;nn<(c)->md_len/4;nn++) \
+ { ll=(c)->h[nn]; HOST_l2c(ll,(s)); } \
+ break; \
+ } \
+ } while (0)
+
+#define HASH_UPDATE SHA256_Update
+#define HASH_TRANSFORM SHA256_Transform
+#define HASH_FINAL SHA256_Final
+#define HASH_BLOCK_DATA_ORDER sha256_block_data_order
+#ifndef SHA256_ASM
+static
+#endif
+void sha256_block_data_order (SHA256_CTX *ctx, const void *in, size_t num);
+
+#include "md32_common.h"
+
+#ifndef SHA256_ASM
+static const SHA_LONG K256[64] = {
+ 0x428a2f98UL,0x71374491UL,0xb5c0fbcfUL,0xe9b5dba5UL,
+ 0x3956c25bUL,0x59f111f1UL,0x923f82a4UL,0xab1c5ed5UL,
+ 0xd807aa98UL,0x12835b01UL,0x243185beUL,0x550c7dc3UL,
+ 0x72be5d74UL,0x80deb1feUL,0x9bdc06a7UL,0xc19bf174UL,
+ 0xe49b69c1UL,0xefbe4786UL,0x0fc19dc6UL,0x240ca1ccUL,
+ 0x2de92c6fUL,0x4a7484aaUL,0x5cb0a9dcUL,0x76f988daUL,
+ 0x983e5152UL,0xa831c66dUL,0xb00327c8UL,0xbf597fc7UL,
+ 0xc6e00bf3UL,0xd5a79147UL,0x06ca6351UL,0x14292967UL,
+ 0x27b70a85UL,0x2e1b2138UL,0x4d2c6dfcUL,0x53380d13UL,
+ 0x650a7354UL,0x766a0abbUL,0x81c2c92eUL,0x92722c85UL,
+ 0xa2bfe8a1UL,0xa81a664bUL,0xc24b8b70UL,0xc76c51a3UL,
+ 0xd192e819UL,0xd6990624UL,0xf40e3585UL,0x106aa070UL,
+ 0x19a4c116UL,0x1e376c08UL,0x2748774cUL,0x34b0bcb5UL,
+ 0x391c0cb3UL,0x4ed8aa4aUL,0x5b9cca4fUL,0x682e6ff3UL,
+ 0x748f82eeUL,0x78a5636fUL,0x84c87814UL,0x8cc70208UL,
+ 0x90befffaUL,0xa4506cebUL,0xbef9a3f7UL,0xc67178f2UL };
+
+/*
+ * FIPS specification refers to right rotations, while our ROTATE macro
+ * is left one. This is why you might notice that rotation coefficients
+ * differ from those observed in FIPS document by 32-N...
+ */
+#define Sigma0(x) (ROTATE((x),30) ^ ROTATE((x),19) ^ ROTATE((x),10))
+#define Sigma1(x) (ROTATE((x),26) ^ ROTATE((x),21) ^ ROTATE((x),7))
+#define sigma0(x) (ROTATE((x),25) ^ ROTATE((x),14) ^ ((x)>>3))
+#define sigma1(x) (ROTATE((x),15) ^ ROTATE((x),13) ^ ((x)>>10))
+
+#define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z)))
+#define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
+
+#ifdef OPENSSL_SMALL_FOOTPRINT
+
+static void sha256_block_data_order (SHA256_CTX *ctx, const void *in, size_t num)
+ {
+ unsigned MD32_REG_T a,b,c,d,e,f,g,h,s0,s1,T1,T2;
+ SHA_LONG X[16],l;
+ int i;
+ const unsigned char *data=in;
+
+ while (num--) {
+
+ a = ctx->h[0]; b = ctx->h[1]; c = ctx->h[2]; d = ctx->h[3];
+ e = ctx->h[4]; f = ctx->h[5]; g = ctx->h[6]; h = ctx->h[7];
+
+ for (i=0;i<16;i++)
+ {
+ HOST_c2l(data,l); T1 = X[i] = l;
+ T1 += h + Sigma1(e) + Ch(e,f,g) + K256[i];
+ T2 = Sigma0(a) + Maj(a,b,c);
+ h = g; g = f; f = e; e = d + T1;
+ d = c; c = b; b = a; a = T1 + T2;
+ }
+
+ for (;i<64;i++)
+ {
+ s0 = X[(i+1)&0x0f]; s0 = sigma0(s0);
+ s1 = X[(i+14)&0x0f]; s1 = sigma1(s1);
+
+ T1 = X[i&0xf] += s0 + s1 + X[(i+9)&0xf];
+ T1 += h + Sigma1(e) + Ch(e,f,g) + K256[i];
+ T2 = Sigma0(a) + Maj(a,b,c);
+ h = g; g = f; f = e; e = d + T1;
+ d = c; c = b; b = a; a = T1 + T2;
+ }
+
+ ctx->h[0] += a; ctx->h[1] += b; ctx->h[2] += c; ctx->h[3] += d;
+ ctx->h[4] += e; ctx->h[5] += f; ctx->h[6] += g; ctx->h[7] += h;
+
+ }
+}
+
+#else
+
+#define ROUND_00_15(i,a,b,c,d,e,f,g,h) do { \
+ T1 += h + Sigma1(e) + Ch(e,f,g) + K256[i]; \
+ h = Sigma0(a) + Maj(a,b,c); \
+ d += T1; h += T1; } while (0)
+
+#define ROUND_16_63(i,a,b,c,d,e,f,g,h,X) do { \
+ s0 = X[(i+1)&0x0f]; s0 = sigma0(s0); \
+ s1 = X[(i+14)&0x0f]; s1 = sigma1(s1); \
+ T1 = X[(i)&0x0f] += s0 + s1 + X[(i+9)&0x0f]; \
+ ROUND_00_15(i,a,b,c,d,e,f,g,h); } while (0)
+
+static void sha256_block_data_order (SHA256_CTX *ctx, const void *in, size_t num)
+ {
+ unsigned MD32_REG_T a,b,c,d,e,f,g,h,s0,s1,T1;
+ SHA_LONG X[16];
+ int i;
+ const unsigned char *data=in;
+
+ while (num--) {
+
+ a = ctx->h[0]; b = ctx->h[1]; c = ctx->h[2]; d = ctx->h[3];
+ e = ctx->h[4]; f = ctx->h[5]; g = ctx->h[6]; h = ctx->h[7];
+
+ if (BYTE_ORDER != LITTLE_ENDIAN &&
+ sizeof(SHA_LONG)==4 && ((size_t)in%4)==0)
+ {
+ const SHA_LONG *W=(const SHA_LONG *)data;
+
+ T1 = X[0] = W[0]; ROUND_00_15(0,a,b,c,d,e,f,g,h);
+ T1 = X[1] = W[1]; ROUND_00_15(1,h,a,b,c,d,e,f,g);
+ T1 = X[2] = W[2]; ROUND_00_15(2,g,h,a,b,c,d,e,f);
+ T1 = X[3] = W[3]; ROUND_00_15(3,f,g,h,a,b,c,d,e);
+ T1 = X[4] = W[4]; ROUND_00_15(4,e,f,g,h,a,b,c,d);
+ T1 = X[5] = W[5]; ROUND_00_15(5,d,e,f,g,h,a,b,c);
+ T1 = X[6] = W[6]; ROUND_00_15(6,c,d,e,f,g,h,a,b);
+ T1 = X[7] = W[7]; ROUND_00_15(7,b,c,d,e,f,g,h,a);
+ T1 = X[8] = W[8]; ROUND_00_15(8,a,b,c,d,e,f,g,h);
+ T1 = X[9] = W[9]; ROUND_00_15(9,h,a,b,c,d,e,f,g);
+ T1 = X[10] = W[10]; ROUND_00_15(10,g,h,a,b,c,d,e,f);
+ T1 = X[11] = W[11]; ROUND_00_15(11,f,g,h,a,b,c,d,e);
+ T1 = X[12] = W[12]; ROUND_00_15(12,e,f,g,h,a,b,c,d);
+ T1 = X[13] = W[13]; ROUND_00_15(13,d,e,f,g,h,a,b,c);
+ T1 = X[14] = W[14]; ROUND_00_15(14,c,d,e,f,g,h,a,b);
+ T1 = X[15] = W[15]; ROUND_00_15(15,b,c,d,e,f,g,h,a);
+
+ data += SHA256_CBLOCK;
+ }
+ else
+ {
+ SHA_LONG l;
+
+ HOST_c2l(data,l); T1 = X[0] = l; ROUND_00_15(0,a,b,c,d,e,f,g,h);
+ HOST_c2l(data,l); T1 = X[1] = l; ROUND_00_15(1,h,a,b,c,d,e,f,g);
+ HOST_c2l(data,l); T1 = X[2] = l; ROUND_00_15(2,g,h,a,b,c,d,e,f);
+ HOST_c2l(data,l); T1 = X[3] = l; ROUND_00_15(3,f,g,h,a,b,c,d,e);
+ HOST_c2l(data,l); T1 = X[4] = l; ROUND_00_15(4,e,f,g,h,a,b,c,d);
+ HOST_c2l(data,l); T1 = X[5] = l; ROUND_00_15(5,d,e,f,g,h,a,b,c);
+ HOST_c2l(data,l); T1 = X[6] = l; ROUND_00_15(6,c,d,e,f,g,h,a,b);
+ HOST_c2l(data,l); T1 = X[7] = l; ROUND_00_15(7,b,c,d,e,f,g,h,a);
+ HOST_c2l(data,l); T1 = X[8] = l; ROUND_00_15(8,a,b,c,d,e,f,g,h);
+ HOST_c2l(data,l); T1 = X[9] = l; ROUND_00_15(9,h,a,b,c,d,e,f,g);
+ HOST_c2l(data,l); T1 = X[10] = l; ROUND_00_15(10,g,h,a,b,c,d,e,f);
+ HOST_c2l(data,l); T1 = X[11] = l; ROUND_00_15(11,f,g,h,a,b,c,d,e);
+ HOST_c2l(data,l); T1 = X[12] = l; ROUND_00_15(12,e,f,g,h,a,b,c,d);
+ HOST_c2l(data,l); T1 = X[13] = l; ROUND_00_15(13,d,e,f,g,h,a,b,c);
+ HOST_c2l(data,l); T1 = X[14] = l; ROUND_00_15(14,c,d,e,f,g,h,a,b);
+ HOST_c2l(data,l); T1 = X[15] = l; ROUND_00_15(15,b,c,d,e,f,g,h,a);
+ }
+
+ for (i=16;i<64;i+=8)
+ {
+ ROUND_16_63(i+0,a,b,c,d,e,f,g,h,X);
+ ROUND_16_63(i+1,h,a,b,c,d,e,f,g,X);
+ ROUND_16_63(i+2,g,h,a,b,c,d,e,f,X);
+ ROUND_16_63(i+3,f,g,h,a,b,c,d,e,X);
+ ROUND_16_63(i+4,e,f,g,h,a,b,c,d,X);
+ ROUND_16_63(i+5,d,e,f,g,h,a,b,c,X);
+ ROUND_16_63(i+6,c,d,e,f,g,h,a,b,X);
+ ROUND_16_63(i+7,b,c,d,e,f,g,h,a,X);
+ }
+
+ ctx->h[0] += a; ctx->h[1] += b; ctx->h[2] += c; ctx->h[3] += d;
+ ctx->h[4] += e; ctx->h[5] += f; ctx->h[6] += g; ctx->h[7] += h;
+
+ }
+ }
+
+#endif
+#endif /* SHA256_ASM */
+
+#endif /* OPENSSL_NO_SHA256 */
diff --git a/lib/libcrypto/sha/sha512.c b/lib/libcrypto/sha/sha512.c
new file mode 100644
index 0000000..6b95cfa
--- /dev/null
+++ b/lib/libcrypto/sha/sha512.c
@@ -0,0 +1,547 @@
+/* $OpenBSD: sha512.c,v 1.15 2016/11/04 13:56:05 miod Exp $ */
+/* ====================================================================
+ * Copyright (c) 2004 The OpenSSL Project. All rights reserved
+ * according to the OpenSSL license [found in ../../LICENSE].
+ * ====================================================================
+ */
+
+#include <machine/endian.h>
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <openssl/opensslconf.h>
+
+#if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA512)
+/*
+ * IMPLEMENTATION NOTES.
+ *
+ * As you might have noticed 32-bit hash algorithms:
+ *
+ * - permit SHA_LONG to be wider than 32-bit (case on CRAY);
+ * - optimized versions implement two transform functions: one operating
+ * on [aligned] data in host byte order and one - on data in input
+ * stream byte order;
+ * - share common byte-order neutral collector and padding function
+ * implementations, ../md32_common.h;
+ *
+ * Neither of the above applies to this SHA-512 implementations. Reasons
+ * [in reverse order] are:
+ *
+ * - it's the only 64-bit hash algorithm for the moment of this writing,
+ * there is no need for common collector/padding implementation [yet];
+ * - by supporting only one transform function [which operates on
+ * *aligned* data in input stream byte order, big-endian in this case]
+ * we minimize burden of maintenance in two ways: a) collector/padding
+ * function is simpler; b) only one transform function to stare at;
+ * - SHA_LONG64 is required to be exactly 64-bit in order to be able to
+ * apply a number of optimizations to mitigate potential performance
+ * penalties caused by previous design decision;
+ *
+ * Caveat lector.
+ *
+ * Implementation relies on the fact that "long long" is 64-bit on
+ * both 32- and 64-bit platforms. If some compiler vendor comes up
+ * with 128-bit long long, adjustment to sha.h would be required.
+ * As this implementation relies on 64-bit integer type, it's totally
+ * inappropriate for platforms which don't support it, most notably
+ * 16-bit platforms.
+ * <appro@fy.chalmers.se>
+ */
+
+#include <openssl/crypto.h>
+#include <openssl/opensslv.h>
+#include <openssl/sha.h>
+
+#if !defined(__STRICT_ALIGNMENT) || defined(SHA512_ASM)
+#define SHA512_BLOCK_CAN_MANAGE_UNALIGNED_DATA
+#endif
+
+int SHA384_Init(SHA512_CTX *c)
+ {
+ c->h[0]=U64(0xcbbb9d5dc1059ed8);
+ c->h[1]=U64(0x629a292a367cd507);
+ c->h[2]=U64(0x9159015a3070dd17);
+ c->h[3]=U64(0x152fecd8f70e5939);
+ c->h[4]=U64(0x67332667ffc00b31);
+ c->h[5]=U64(0x8eb44a8768581511);
+ c->h[6]=U64(0xdb0c2e0d64f98fa7);
+ c->h[7]=U64(0x47b5481dbefa4fa4);
+
+ c->Nl=0; c->Nh=0;
+ c->num=0; c->md_len=SHA384_DIGEST_LENGTH;
+ return 1;
+ }
+
+int SHA512_Init(SHA512_CTX *c)
+ {
+ c->h[0]=U64(0x6a09e667f3bcc908);
+ c->h[1]=U64(0xbb67ae8584caa73b);
+ c->h[2]=U64(0x3c6ef372fe94f82b);
+ c->h[3]=U64(0xa54ff53a5f1d36f1);
+ c->h[4]=U64(0x510e527fade682d1);
+ c->h[5]=U64(0x9b05688c2b3e6c1f);
+ c->h[6]=U64(0x1f83d9abfb41bd6b);
+ c->h[7]=U64(0x5be0cd19137e2179);
+
+ c->Nl=0; c->Nh=0;
+ c->num=0; c->md_len=SHA512_DIGEST_LENGTH;
+ return 1;
+ }
+
+#ifndef SHA512_ASM
+static
+#endif
+void sha512_block_data_order (SHA512_CTX *ctx, const void *in, size_t num);
+
+int SHA512_Final (unsigned char *md, SHA512_CTX *c)
+ {
+ unsigned char *p=(unsigned char *)c->u.p;
+ size_t n=c->num;
+
+ p[n]=0x80; /* There always is a room for one */
+ n++;
+ if (n > (sizeof(c->u)-16))
+ memset (p+n,0,sizeof(c->u)-n), n=0,
+ sha512_block_data_order (c,p,1);
+
+ memset (p+n,0,sizeof(c->u)-16-n);
+#if BYTE_ORDER == BIG_ENDIAN
+ c->u.d[SHA_LBLOCK-2] = c->Nh;
+ c->u.d[SHA_LBLOCK-1] = c->Nl;
+#else
+ p[sizeof(c->u)-1] = (unsigned char)(c->Nl);
+ p[sizeof(c->u)-2] = (unsigned char)(c->Nl>>8);
+ p[sizeof(c->u)-3] = (unsigned char)(c->Nl>>16);
+ p[sizeof(c->u)-4] = (unsigned char)(c->Nl>>24);
+ p[sizeof(c->u)-5] = (unsigned char)(c->Nl>>32);
+ p[sizeof(c->u)-6] = (unsigned char)(c->Nl>>40);
+ p[sizeof(c->u)-7] = (unsigned char)(c->Nl>>48);
+ p[sizeof(c->u)-8] = (unsigned char)(c->Nl>>56);
+ p[sizeof(c->u)-9] = (unsigned char)(c->Nh);
+ p[sizeof(c->u)-10] = (unsigned char)(c->Nh>>8);
+ p[sizeof(c->u)-11] = (unsigned char)(c->Nh>>16);
+ p[sizeof(c->u)-12] = (unsigned char)(c->Nh>>24);
+ p[sizeof(c->u)-13] = (unsigned char)(c->Nh>>32);
+ p[sizeof(c->u)-14] = (unsigned char)(c->Nh>>40);
+ p[sizeof(c->u)-15] = (unsigned char)(c->Nh>>48);
+ p[sizeof(c->u)-16] = (unsigned char)(c->Nh>>56);
+#endif
+
+ sha512_block_data_order (c,p,1);
+
+ if (md==0) return 0;
+
+ switch (c->md_len)
+ {
+ /* Let compiler decide if it's appropriate to unroll... */
+ case SHA384_DIGEST_LENGTH:
+ for (n=0;n<SHA384_DIGEST_LENGTH/8;n++)
+ {
+ SHA_LONG64 t = c->h[n];
+
+ *(md++) = (unsigned char)(t>>56);
+ *(md++) = (unsigned char)(t>>48);
+ *(md++) = (unsigned char)(t>>40);
+ *(md++) = (unsigned char)(t>>32);
+ *(md++) = (unsigned char)(t>>24);
+ *(md++) = (unsigned char)(t>>16);
+ *(md++) = (unsigned char)(t>>8);
+ *(md++) = (unsigned char)(t);
+ }
+ break;
+ case SHA512_DIGEST_LENGTH:
+ for (n=0;n<SHA512_DIGEST_LENGTH/8;n++)
+ {
+ SHA_LONG64 t = c->h[n];
+
+ *(md++) = (unsigned char)(t>>56);
+ *(md++) = (unsigned char)(t>>48);
+ *(md++) = (unsigned char)(t>>40);
+ *(md++) = (unsigned char)(t>>32);
+ *(md++) = (unsigned char)(t>>24);
+ *(md++) = (unsigned char)(t>>16);
+ *(md++) = (unsigned char)(t>>8);
+ *(md++) = (unsigned char)(t);
+ }
+ break;
+ /* ... as well as make sure md_len is not abused. */
+ default: return 0;
+ }
+
+ return 1;
+ }
+
+int SHA384_Final (unsigned char *md,SHA512_CTX *c)
+{ return SHA512_Final (md,c); }
+
+int SHA512_Update (SHA512_CTX *c, const void *_data, size_t len)
+ {
+ SHA_LONG64 l;
+ unsigned char *p=c->u.p;
+ const unsigned char *data=(const unsigned char *)_data;
+
+ if (len==0) return 1;
+
+ l = (c->Nl+(((SHA_LONG64)len)<<3))&U64(0xffffffffffffffff);
+ if (l < c->Nl) c->Nh++;
+ if (sizeof(len)>=8) c->Nh+=(((SHA_LONG64)len)>>61);
+ c->Nl=l;
+
+ if (c->num != 0)
+ {
+ size_t n = sizeof(c->u) - c->num;
+
+ if (len < n)
+ {
+ memcpy (p+c->num,data,len), c->num += (unsigned int)len;
+ return 1;
+ }
+ else {
+ memcpy (p+c->num,data,n), c->num = 0;
+ len-=n, data+=n;
+ sha512_block_data_order (c,p,1);
+ }
+ }
+
+ if (len >= sizeof(c->u))
+ {
+#ifndef SHA512_BLOCK_CAN_MANAGE_UNALIGNED_DATA
+ if ((size_t)data%sizeof(c->u.d[0]) != 0)
+ while (len >= sizeof(c->u))
+ memcpy (p,data,sizeof(c->u)),
+ sha512_block_data_order (c,p,1),
+ len -= sizeof(c->u),
+ data += sizeof(c->u);
+ else
+#endif
+ sha512_block_data_order (c,data,len/sizeof(c->u)),
+ data += len,
+ len %= sizeof(c->u),
+ data -= len;
+ }
+
+ if (len != 0) memcpy (p,data,len), c->num = (int)len;
+
+ return 1;
+ }
+
+int SHA384_Update (SHA512_CTX *c, const void *data, size_t len)
+{ return SHA512_Update (c,data,len); }
+
+void SHA512_Transform (SHA512_CTX *c, const unsigned char *data)
+ {
+#ifndef SHA512_BLOCK_CAN_MANAGE_UNALIGNED_DATA
+ if ((size_t)data%sizeof(c->u.d[0]) != 0)
+ memcpy(c->u.p,data,sizeof(c->u.p)),
+ data = c->u.p;
+#endif
+ sha512_block_data_order (c,data,1);
+ }
+
+unsigned char *SHA384(const unsigned char *d, size_t n, unsigned char *md)
+ {
+ SHA512_CTX c;
+ static unsigned char m[SHA384_DIGEST_LENGTH];
+
+ if (md == NULL) md=m;
+ SHA384_Init(&c);
+ SHA512_Update(&c,d,n);
+ SHA512_Final(md,&c);
+ explicit_bzero(&c,sizeof(c));
+ return(md);
+ }
+
+unsigned char *SHA512(const unsigned char *d, size_t n, unsigned char *md)
+ {
+ SHA512_CTX c;
+ static unsigned char m[SHA512_DIGEST_LENGTH];
+
+ if (md == NULL) md=m;
+ SHA512_Init(&c);
+ SHA512_Update(&c,d,n);
+ SHA512_Final(md,&c);
+ explicit_bzero(&c,sizeof(c));
+ return(md);
+ }
+
+#ifndef SHA512_ASM
+static const SHA_LONG64 K512[80] = {
+ U64(0x428a2f98d728ae22),U64(0x7137449123ef65cd),
+ U64(0xb5c0fbcfec4d3b2f),U64(0xe9b5dba58189dbbc),
+ U64(0x3956c25bf348b538),U64(0x59f111f1b605d019),
+ U64(0x923f82a4af194f9b),U64(0xab1c5ed5da6d8118),
+ U64(0xd807aa98a3030242),U64(0x12835b0145706fbe),
+ U64(0x243185be4ee4b28c),U64(0x550c7dc3d5ffb4e2),
+ U64(0x72be5d74f27b896f),U64(0x80deb1fe3b1696b1),
+ U64(0x9bdc06a725c71235),U64(0xc19bf174cf692694),
+ U64(0xe49b69c19ef14ad2),U64(0xefbe4786384f25e3),
+ U64(0x0fc19dc68b8cd5b5),U64(0x240ca1cc77ac9c65),
+ U64(0x2de92c6f592b0275),U64(0x4a7484aa6ea6e483),
+ U64(0x5cb0a9dcbd41fbd4),U64(0x76f988da831153b5),
+ U64(0x983e5152ee66dfab),U64(0xa831c66d2db43210),
+ U64(0xb00327c898fb213f),U64(0xbf597fc7beef0ee4),
+ U64(0xc6e00bf33da88fc2),U64(0xd5a79147930aa725),
+ U64(0x06ca6351e003826f),U64(0x142929670a0e6e70),
+ U64(0x27b70a8546d22ffc),U64(0x2e1b21385c26c926),
+ U64(0x4d2c6dfc5ac42aed),U64(0x53380d139d95b3df),
+ U64(0x650a73548baf63de),U64(0x766a0abb3c77b2a8),
+ U64(0x81c2c92e47edaee6),U64(0x92722c851482353b),
+ U64(0xa2bfe8a14cf10364),U64(0xa81a664bbc423001),
+ U64(0xc24b8b70d0f89791),U64(0xc76c51a30654be30),
+ U64(0xd192e819d6ef5218),U64(0xd69906245565a910),
+ U64(0xf40e35855771202a),U64(0x106aa07032bbd1b8),
+ U64(0x19a4c116b8d2d0c8),U64(0x1e376c085141ab53),
+ U64(0x2748774cdf8eeb99),U64(0x34b0bcb5e19b48a8),
+ U64(0x391c0cb3c5c95a63),U64(0x4ed8aa4ae3418acb),
+ U64(0x5b9cca4f7763e373),U64(0x682e6ff3d6b2b8a3),
+ U64(0x748f82ee5defb2fc),U64(0x78a5636f43172f60),
+ U64(0x84c87814a1f0ab72),U64(0x8cc702081a6439ec),
+ U64(0x90befffa23631e28),U64(0xa4506cebde82bde9),
+ U64(0xbef9a3f7b2c67915),U64(0xc67178f2e372532b),
+ U64(0xca273eceea26619c),U64(0xd186b8c721c0c207),
+ U64(0xeada7dd6cde0eb1e),U64(0xf57d4f7fee6ed178),
+ U64(0x06f067aa72176fba),U64(0x0a637dc5a2c898a6),
+ U64(0x113f9804bef90dae),U64(0x1b710b35131c471b),
+ U64(0x28db77f523047d84),U64(0x32caab7b40c72493),
+ U64(0x3c9ebe0a15c9bebc),U64(0x431d67c49c100d4c),
+ U64(0x4cc5d4becb3e42b6),U64(0x597f299cfc657e2a),
+ U64(0x5fcb6fab3ad6faec),U64(0x6c44198c4a475817) };
+
+#if defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
+# if defined(__x86_64) || defined(__x86_64__)
+# define ROTR(a,n) ({ SHA_LONG64 ret; \
+ asm ("rorq %1,%0" \
+ : "=r"(ret) \
+ : "J"(n),"0"(a) \
+ : "cc"); ret; })
+# define PULL64(x) ({ SHA_LONG64 ret=*((const SHA_LONG64 *)(&(x))); \
+ asm ("bswapq %0" \
+ : "=r"(ret) \
+ : "0"(ret)); ret; })
+# elif (defined(__i386) || defined(__i386__))
+# define PULL64(x) ({ const unsigned int *p=(const unsigned int *)(&(x));\
+ unsigned int hi=p[0],lo=p[1]; \
+ asm ("bswapl %0; bswapl %1;" \
+ : "=r"(lo),"=r"(hi) \
+ : "0"(lo),"1"(hi)); \
+ ((SHA_LONG64)hi)<<32|lo; })
+# elif (defined(_ARCH_PPC) && defined(__64BIT__)) || defined(_ARCH_PPC64)
+# define ROTR(a,n) ({ SHA_LONG64 ret; \
+ asm ("rotrdi %0,%1,%2" \
+ : "=r"(ret) \
+ : "r"(a),"K"(n)); ret; })
+# endif
+#endif
+
+#ifndef PULL64
+#define B(x,j) (((SHA_LONG64)(*(((const unsigned char *)(&x))+j)))<<((7-j)*8))
+#define PULL64(x) (B(x,0)|B(x,1)|B(x,2)|B(x,3)|B(x,4)|B(x,5)|B(x,6)|B(x,7))
+#endif
+
+#ifndef ROTR
+#define ROTR(x,s) (((x)>>s) | (x)<<(64-s))
+#endif
+
+#define Sigma0(x) (ROTR((x),28) ^ ROTR((x),34) ^ ROTR((x),39))
+#define Sigma1(x) (ROTR((x),14) ^ ROTR((x),18) ^ ROTR((x),41))
+#define sigma0(x) (ROTR((x),1) ^ ROTR((x),8) ^ ((x)>>7))
+#define sigma1(x) (ROTR((x),19) ^ ROTR((x),61) ^ ((x)>>6))
+
+#define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z)))
+#define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
+
+
+#if defined(__i386) || defined(__i386__) || defined(_M_IX86)
+/*
+ * This code should give better results on 32-bit CPU with less than
+ * ~24 registers, both size and performance wise...
+ */
+static void sha512_block_data_order (SHA512_CTX *ctx, const void *in, size_t num)
+ {
+ const SHA_LONG64 *W=in;
+ SHA_LONG64 A,E,T;
+ SHA_LONG64 X[9+80],*F;
+ int i;
+
+ while (num--) {
+
+ F = X+80;
+ A = ctx->h[0]; F[1] = ctx->h[1];
+ F[2] = ctx->h[2]; F[3] = ctx->h[3];
+ E = ctx->h[4]; F[5] = ctx->h[5];
+ F[6] = ctx->h[6]; F[7] = ctx->h[7];
+
+ for (i=0;i<16;i++,F--)
+ {
+ T = PULL64(W[i]);
+ F[0] = A;
+ F[4] = E;
+ F[8] = T;
+ T += F[7] + Sigma1(E) + Ch(E,F[5],F[6]) + K512[i];
+ E = F[3] + T;
+ A = T + Sigma0(A) + Maj(A,F[1],F[2]);
+ }
+
+ for (;i<80;i++,F--)
+ {
+ T = sigma0(F[8+16-1]);
+ T += sigma1(F[8+16-14]);
+ T += F[8+16] + F[8+16-9];
+
+ F[0] = A;
+ F[4] = E;
+ F[8] = T;
+ T += F[7] + Sigma1(E) + Ch(E,F[5],F[6]) + K512[i];
+ E = F[3] + T;
+ A = T + Sigma0(A) + Maj(A,F[1],F[2]);
+ }
+
+ ctx->h[0] += A; ctx->h[1] += F[1];
+ ctx->h[2] += F[2]; ctx->h[3] += F[3];
+ ctx->h[4] += E; ctx->h[5] += F[5];
+ ctx->h[6] += F[6]; ctx->h[7] += F[7];
+
+ W+=SHA_LBLOCK;
+ }
+ }
+
+#elif defined(OPENSSL_SMALL_FOOTPRINT)
+
+static void sha512_block_data_order (SHA512_CTX *ctx, const void *in, size_t num)
+ {
+ const SHA_LONG64 *W=in;
+ SHA_LONG64 a,b,c,d,e,f,g,h,s0,s1,T1,T2;
+ SHA_LONG64 X[16];
+ int i;
+
+ while (num--) {
+
+ a = ctx->h[0]; b = ctx->h[1]; c = ctx->h[2]; d = ctx->h[3];
+ e = ctx->h[4]; f = ctx->h[5]; g = ctx->h[6]; h = ctx->h[7];
+
+ for (i=0;i<16;i++)
+ {
+#if BYTE_ORDER == BIG_ENDIAN
+ T1 = X[i] = W[i];
+#else
+ T1 = X[i] = PULL64(W[i]);
+#endif
+ T1 += h + Sigma1(e) + Ch(e,f,g) + K512[i];
+ T2 = Sigma0(a) + Maj(a,b,c);
+ h = g; g = f; f = e; e = d + T1;
+ d = c; c = b; b = a; a = T1 + T2;
+ }
+
+ for (;i<80;i++)
+ {
+ s0 = X[(i+1)&0x0f]; s0 = sigma0(s0);
+ s1 = X[(i+14)&0x0f]; s1 = sigma1(s1);
+
+ T1 = X[i&0xf] += s0 + s1 + X[(i+9)&0xf];
+ T1 += h + Sigma1(e) + Ch(e,f,g) + K512[i];
+ T2 = Sigma0(a) + Maj(a,b,c);
+ h = g; g = f; f = e; e = d + T1;
+ d = c; c = b; b = a; a = T1 + T2;
+ }
+
+ ctx->h[0] += a; ctx->h[1] += b; ctx->h[2] += c; ctx->h[3] += d;
+ ctx->h[4] += e; ctx->h[5] += f; ctx->h[6] += g; ctx->h[7] += h;
+
+ W+=SHA_LBLOCK;
+ }
+ }
+
+#else
+
+#define ROUND_00_15(i,a,b,c,d,e,f,g,h) do { \
+ T1 += h + Sigma1(e) + Ch(e,f,g) + K512[i]; \
+ h = Sigma0(a) + Maj(a,b,c); \
+ d += T1; h += T1; } while (0)
+
+#define ROUND_16_80(i,j,a,b,c,d,e,f,g,h,X) do { \
+ s0 = X[(j+1)&0x0f]; s0 = sigma0(s0); \
+ s1 = X[(j+14)&0x0f]; s1 = sigma1(s1); \
+ T1 = X[(j)&0x0f] += s0 + s1 + X[(j+9)&0x0f]; \
+ ROUND_00_15(i+j,a,b,c,d,e,f,g,h); } while (0)
+
+static void sha512_block_data_order (SHA512_CTX *ctx, const void *in, size_t num)
+ {
+ const SHA_LONG64 *W=in;
+ SHA_LONG64 a,b,c,d,e,f,g,h,s0,s1,T1;
+ SHA_LONG64 X[16];
+ int i;
+
+ while (num--) {
+
+ a = ctx->h[0]; b = ctx->h[1]; c = ctx->h[2]; d = ctx->h[3];
+ e = ctx->h[4]; f = ctx->h[5]; g = ctx->h[6]; h = ctx->h[7];
+
+#if BYTE_ORDER == BIG_ENDIAN
+ T1 = X[0] = W[0]; ROUND_00_15(0,a,b,c,d,e,f,g,h);
+ T1 = X[1] = W[1]; ROUND_00_15(1,h,a,b,c,d,e,f,g);
+ T1 = X[2] = W[2]; ROUND_00_15(2,g,h,a,b,c,d,e,f);
+ T1 = X[3] = W[3]; ROUND_00_15(3,f,g,h,a,b,c,d,e);
+ T1 = X[4] = W[4]; ROUND_00_15(4,e,f,g,h,a,b,c,d);
+ T1 = X[5] = W[5]; ROUND_00_15(5,d,e,f,g,h,a,b,c);
+ T1 = X[6] = W[6]; ROUND_00_15(6,c,d,e,f,g,h,a,b);
+ T1 = X[7] = W[7]; ROUND_00_15(7,b,c,d,e,f,g,h,a);
+ T1 = X[8] = W[8]; ROUND_00_15(8,a,b,c,d,e,f,g,h);
+ T1 = X[9] = W[9]; ROUND_00_15(9,h,a,b,c,d,e,f,g);
+ T1 = X[10] = W[10]; ROUND_00_15(10,g,h,a,b,c,d,e,f);
+ T1 = X[11] = W[11]; ROUND_00_15(11,f,g,h,a,b,c,d,e);
+ T1 = X[12] = W[12]; ROUND_00_15(12,e,f,g,h,a,b,c,d);
+ T1 = X[13] = W[13]; ROUND_00_15(13,d,e,f,g,h,a,b,c);
+ T1 = X[14] = W[14]; ROUND_00_15(14,c,d,e,f,g,h,a,b);
+ T1 = X[15] = W[15]; ROUND_00_15(15,b,c,d,e,f,g,h,a);
+#else
+ T1 = X[0] = PULL64(W[0]); ROUND_00_15(0,a,b,c,d,e,f,g,h);
+ T1 = X[1] = PULL64(W[1]); ROUND_00_15(1,h,a,b,c,d,e,f,g);
+ T1 = X[2] = PULL64(W[2]); ROUND_00_15(2,g,h,a,b,c,d,e,f);
+ T1 = X[3] = PULL64(W[3]); ROUND_00_15(3,f,g,h,a,b,c,d,e);
+ T1 = X[4] = PULL64(W[4]); ROUND_00_15(4,e,f,g,h,a,b,c,d);
+ T1 = X[5] = PULL64(W[5]); ROUND_00_15(5,d,e,f,g,h,a,b,c);
+ T1 = X[6] = PULL64(W[6]); ROUND_00_15(6,c,d,e,f,g,h,a,b);
+ T1 = X[7] = PULL64(W[7]); ROUND_00_15(7,b,c,d,e,f,g,h,a);
+ T1 = X[8] = PULL64(W[8]); ROUND_00_15(8,a,b,c,d,e,f,g,h);
+ T1 = X[9] = PULL64(W[9]); ROUND_00_15(9,h,a,b,c,d,e,f,g);
+ T1 = X[10] = PULL64(W[10]); ROUND_00_15(10,g,h,a,b,c,d,e,f);
+ T1 = X[11] = PULL64(W[11]); ROUND_00_15(11,f,g,h,a,b,c,d,e);
+ T1 = X[12] = PULL64(W[12]); ROUND_00_15(12,e,f,g,h,a,b,c,d);
+ T1 = X[13] = PULL64(W[13]); ROUND_00_15(13,d,e,f,g,h,a,b,c);
+ T1 = X[14] = PULL64(W[14]); ROUND_00_15(14,c,d,e,f,g,h,a,b);
+ T1 = X[15] = PULL64(W[15]); ROUND_00_15(15,b,c,d,e,f,g,h,a);
+#endif
+
+ for (i=16;i<80;i+=16)
+ {
+ ROUND_16_80(i, 0,a,b,c,d,e,f,g,h,X);
+ ROUND_16_80(i, 1,h,a,b,c,d,e,f,g,X);
+ ROUND_16_80(i, 2,g,h,a,b,c,d,e,f,X);
+ ROUND_16_80(i, 3,f,g,h,a,b,c,d,e,X);
+ ROUND_16_80(i, 4,e,f,g,h,a,b,c,d,X);
+ ROUND_16_80(i, 5,d,e,f,g,h,a,b,c,X);
+ ROUND_16_80(i, 6,c,d,e,f,g,h,a,b,X);
+ ROUND_16_80(i, 7,b,c,d,e,f,g,h,a,X);
+ ROUND_16_80(i, 8,a,b,c,d,e,f,g,h,X);
+ ROUND_16_80(i, 9,h,a,b,c,d,e,f,g,X);
+ ROUND_16_80(i,10,g,h,a,b,c,d,e,f,X);
+ ROUND_16_80(i,11,f,g,h,a,b,c,d,e,X);
+ ROUND_16_80(i,12,e,f,g,h,a,b,c,d,X);
+ ROUND_16_80(i,13,d,e,f,g,h,a,b,c,X);
+ ROUND_16_80(i,14,c,d,e,f,g,h,a,b,X);
+ ROUND_16_80(i,15,b,c,d,e,f,g,h,a,X);
+ }
+
+ ctx->h[0] += a; ctx->h[1] += b; ctx->h[2] += c; ctx->h[3] += d;
+ ctx->h[4] += e; ctx->h[5] += f; ctx->h[6] += g; ctx->h[7] += h;
+
+ W+=SHA_LBLOCK;
+ }
+ }
+
+#endif
+
+#endif /* SHA512_ASM */
+
+#endif /* !OPENSSL_NO_SHA512 */
diff --git a/lib/libutil/bcrypt_pbkdf.c b/lib/libutil/bcrypt_pbkdf.c
new file mode 100644
index 0000000..e937194
--- /dev/null
+++ b/lib/libutil/bcrypt_pbkdf.c
@@ -0,0 +1,176 @@
+/* $OpenBSD: bcrypt_pbkdf.c,v 1.15 2019/11/21 16:13:39 tedu Exp $ */
+/*
+ * Copyright (c) 2013 Ted Unangst <tedu@openbsd.org>
+ *
+ * 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 <sys/types.h>
+#include <sys/cdefs.h>
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <blf.h>
+#include <sha2.h>
+#include <string.h>
+#include <util.h>
+
+#define MINIMUM(a,b) (((a) < (b)) ? (a) : (b))
+
+/*
+ * pkcs #5 pbkdf2 implementation using the "bcrypt" hash
+ *
+ * The bcrypt hash function is derived from the bcrypt password hashing
+ * function with the following modifications:
+ * 1. The input password and salt are preprocessed with SHA512.
+ * 2. The output length is expanded to 256 bits.
+ * 3. Subsequently the magic string to be encrypted is lengthened and modifed
+ * to "OxychromaticBlowfishSwatDynamite"
+ * 4. The hash function is defined to perform 64 rounds of initial state
+ * expansion. (More rounds are performed by iterating the hash.)
+ *
+ * Note that this implementation pulls the SHA512 operations into the caller
+ * as a performance optimization.
+ *
+ * One modification from official pbkdf2. Instead of outputting key material
+ * linearly, we mix it. pbkdf2 has a known weakness where if one uses it to
+ * generate (e.g.) 512 bits of key material for use as two 256 bit keys, an
+ * attacker can merely run once through the outer loop, but the user
+ * always runs it twice. Shuffling output bytes requires computing the
+ * entirety of the key material to assemble any subkey. This is something a
+ * wise caller could do; we just do it for you.
+ */
+
+#define BCRYPT_WORDS 8
+#define BCRYPT_HASHSIZE (BCRYPT_WORDS * 4)
+
+static void
+bcrypt_hash(uint8_t *sha2pass, uint8_t *sha2salt, uint8_t *out)
+{
+ blf_ctx state;
+ uint8_t ciphertext[BCRYPT_HASHSIZE] =
+ "OxychromaticBlowfishSwatDynamite";
+ uint32_t cdata[BCRYPT_WORDS];
+ int i;
+ uint16_t j;
+ size_t shalen = SHA512_DIGEST_LENGTH;
+
+ /* key expansion */
+ Blowfish_initstate(&state);
+ Blowfish_expandstate(&state, sha2salt, shalen, sha2pass, shalen);
+ for (i = 0; i < 64; i++) {
+ Blowfish_expand0state(&state, sha2salt, shalen);
+ Blowfish_expand0state(&state, sha2pass, shalen);
+ }
+
+ /* encryption */
+ j = 0;
+ for (i = 0; i < BCRYPT_WORDS; i++)
+ cdata[i] = Blowfish_stream2word(ciphertext, sizeof(ciphertext),
+ &j);
+ for (i = 0; i < 64; i++)
+ blf_enc(&state, cdata, sizeof(cdata) / sizeof(uint64_t));
+
+ /* copy out */
+ for (i = 0; i < BCRYPT_WORDS; i++) {
+ out[4 * i + 3] = (cdata[i] >> 24) & 0xff;
+ out[4 * i + 2] = (cdata[i] >> 16) & 0xff;
+ out[4 * i + 1] = (cdata[i] >> 8) & 0xff;
+ out[4 * i + 0] = cdata[i] & 0xff;
+ }
+
+ /* zap */
+ explicit_bzero(ciphertext, sizeof(ciphertext));
+ explicit_bzero(cdata, sizeof(cdata));
+ explicit_bzero(&state, sizeof(state));
+}
+
+int
+bcrypt_pbkdf(const char *pass, size_t passlen, const uint8_t *salt, size_t saltlen,
+ uint8_t *key, size_t keylen, unsigned int rounds)
+{
+ SHA2_CTX ctx;
+ uint8_t sha2pass[SHA512_DIGEST_LENGTH];
+ uint8_t sha2salt[SHA512_DIGEST_LENGTH];
+ uint8_t out[BCRYPT_HASHSIZE];
+ uint8_t tmpout[BCRYPT_HASHSIZE];
+ uint8_t countsalt[4];
+ size_t i, j, amt, stride;
+ uint32_t count;
+ size_t origkeylen = keylen;
+
+ /* nothing crazy */
+ if (rounds < 1)
+ goto bad;
+ if (passlen == 0 || saltlen == 0 || keylen == 0 ||
+ keylen > sizeof(out) * sizeof(out))
+ goto bad;
+ stride = (keylen + sizeof(out) - 1) / sizeof(out);
+ amt = (keylen + stride - 1) / stride;
+
+ /* collapse password */
+ SHA512Init(&ctx);
+ SHA512Update(&ctx, pass, passlen);
+ SHA512Final(sha2pass, &ctx);
+
+
+ /* generate key, sizeof(out) at a time */
+ for (count = 1; keylen > 0; count++) {
+ countsalt[0] = (count >> 24) & 0xff;
+ countsalt[1] = (count >> 16) & 0xff;
+ countsalt[2] = (count >> 8) & 0xff;
+ countsalt[3] = count & 0xff;
+
+ /* first round, salt is salt */
+ SHA512Init(&ctx);
+ SHA512Update(&ctx, salt, saltlen);
+ SHA512Update(&ctx, countsalt, sizeof(countsalt));
+ SHA512Final(sha2salt, &ctx);
+ bcrypt_hash(sha2pass, sha2salt, tmpout);
+ memcpy(out, tmpout, sizeof(out));
+
+ for (i = 1; i < rounds; i++) {
+ /* subsequent rounds, salt is previous output */
+ SHA512Init(&ctx);
+ SHA512Update(&ctx, tmpout, sizeof(tmpout));
+ SHA512Final(sha2salt, &ctx);
+ bcrypt_hash(sha2pass, sha2salt, tmpout);
+ for (j = 0; j < sizeof(out); j++)
+ out[j] ^= tmpout[j];
+ }
+
+ /*
+ * pbkdf2 deviation: output the key material non-linearly.
+ */
+ amt = MINIMUM(amt, keylen);
+ for (i = 0; i < amt; i++) {
+ size_t dest = i * stride + (count - 1);
+ if (dest >= origkeylen)
+ break;
+ key[dest] = out[i];
+ }
+ keylen -= i;
+ }
+
+ /* zap */
+ explicit_bzero(&ctx, sizeof(ctx));
+ explicit_bzero(out, sizeof(out));
+ explicit_bzero(tmpout, sizeof(tmpout));
+
+ return 0;
+
+bad:
+ /* overwrite with random in case caller doesn't check return code */
+ arc4random_buf(key, keylen);
+ return -1;
+}
diff --git a/lib/libutil/ohash.c b/lib/libutil/ohash.c
new file mode 100644
index 0000000..9537c60
--- /dev/null
+++ b/lib/libutil/ohash.c
@@ -0,0 +1,328 @@
+/* $OpenBSD: ohash.c,v 1.1 2014/06/02 18:52:03 deraadt Exp $ */
+
+/* Copyright (c) 1999, 2004 Marc Espie <espie@openbsd.org>
+ *
+ * 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 <sys/cdefs.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include "ohash.h"
+
+struct _ohash_record {
+ uint32_t hv;
+ const char *p;
+};
+
+#define DELETED ((const char *)h)
+#define NONE (h->size)
+
+/* Don't bother changing the hash table if the change is small enough. */
+#define MINSIZE (1UL << 4)
+#define MINDELETED 4
+
+static void ohash_resize(struct ohash *);
+
+
+/* This handles the common case of variable length keys, where the
+ * key is stored at the end of the record.
+ */
+void *
+ohash_create_entry(struct ohash_info *i, const char *start, const char **end)
+{
+ char *p;
+
+ if (!*end)
+ *end = start + strlen(start);
+ p = (i->alloc)(i->key_offset + (*end - start) + 1, i->data);
+ if (p) {
+ memcpy(p+i->key_offset, start, *end-start);
+ p[i->key_offset + (*end - start)] = '\0';
+ }
+ return (void *)p;
+}
+
+/* hash_delete only frees the hash structure. Use hash_first/hash_next
+ * to free entries as well. */
+void
+ohash_delete(struct ohash *h)
+{
+ (h->info.free)(h->t, h->info.data);
+#ifndef NDEBUG
+ h->t = NULL;
+#endif
+}
+
+static void
+ohash_resize(struct ohash *h)
+{
+ struct _ohash_record *n;
+ size_t ns;
+ unsigned int j;
+ unsigned int i, incr;
+
+ if (4 * h->deleted < h->total) {
+ if (h->size >= (UINT_MAX >> 1U))
+ ns = UINT_MAX;
+ else
+ ns = h->size << 1U;
+ } else if (3 * h->deleted > 2 * h->total)
+ ns = h->size >> 1U;
+ else
+ ns = h->size;
+ if (ns < MINSIZE)
+ ns = MINSIZE;
+#ifdef STATS_HASH
+ STAT_HASH_EXPAND++;
+ STAT_HASH_SIZE += ns - h->size;
+#endif
+
+ n = (h->info.calloc)(ns, sizeof(struct _ohash_record), h->info.data);
+ if (!n)
+ return;
+
+ for (j = 0; j < h->size; j++) {
+ if (h->t[j].p != NULL && h->t[j].p != DELETED) {
+ i = h->t[j].hv % ns;
+ incr = ((h->t[j].hv % (ns - 2)) & ~1) + 1;
+ while (n[i].p != NULL) {
+ i += incr;
+ if (i >= ns)
+ i -= ns;
+ }
+ n[i].hv = h->t[j].hv;
+ n[i].p = h->t[j].p;
+ }
+ }
+ (h->info.free)(h->t, h->info.data);
+ h->t = n;
+ h->size = ns;
+ h->total -= h->deleted;
+ h->deleted = 0;
+}
+
+void *
+ohash_remove(struct ohash *h, unsigned int i)
+{
+ void *result = (void *)h->t[i].p;
+
+ if (result == NULL || result == DELETED)
+ return NULL;
+
+#ifdef STATS_HASH
+ STAT_HASH_ENTRIES--;
+#endif
+ h->t[i].p = DELETED;
+ h->deleted++;
+ if (h->deleted >= MINDELETED && 4 * h->deleted > h->total)
+ ohash_resize(h);
+ return result;
+}
+
+void *
+ohash_find(struct ohash *h, unsigned int i)
+{
+ if (h->t[i].p == DELETED)
+ return NULL;
+ else
+ return (void *)h->t[i].p;
+}
+
+void *
+ohash_insert(struct ohash *h, unsigned int i, void *p)
+{
+#ifdef STATS_HASH
+ STAT_HASH_ENTRIES++;
+#endif
+ if (h->t[i].p == DELETED) {
+ h->deleted--;
+ h->t[i].p = p;
+ } else {
+ h->t[i].p = p;
+ /* Arbitrary resize boundary. Tweak if not efficient enough. */
+ if (++h->total * 4 > h->size * 3)
+ ohash_resize(h);
+ }
+ return p;
+}
+
+unsigned int
+ohash_entries(struct ohash *h)
+{
+ return h->total - h->deleted;
+}
+
+void *
+ohash_first(struct ohash *h, unsigned int *pos)
+{
+ *pos = 0;
+ return ohash_next(h, pos);
+}
+
+void *
+ohash_next(struct ohash *h, unsigned int *pos)
+{
+ for (; *pos < h->size; (*pos)++)
+ if (h->t[*pos].p != DELETED && h->t[*pos].p != NULL)
+ return (void *)h->t[(*pos)++].p;
+ return NULL;
+}
+
+void
+ohash_init(struct ohash *h, unsigned int size, struct ohash_info *info)
+{
+ h->size = 1UL << size;
+ if (h->size < MINSIZE)
+ h->size = MINSIZE;
+#ifdef STATS_HASH
+ STAT_HASH_CREATION++;
+ STAT_HASH_SIZE += h->size;
+#endif
+ /* Copy info so that caller may free it. */
+ h->info.key_offset = info->key_offset;
+ h->info.calloc = info->calloc;
+ h->info.free = info->free;
+ h->info.alloc = info->alloc;
+ h->info.data = info->data;
+ h->t = (h->info.calloc)(h->size, sizeof(struct _ohash_record),
+ h->info.data);
+ h->total = h->deleted = 0;
+}
+
+uint32_t
+ohash_interval(const char *s, const char **e)
+{
+ uint32_t k;
+
+ if (!*e)
+ *e = s + strlen(s);
+ if (s == *e)
+ k = 0;
+ else
+ k = *s++;
+ while (s != *e)
+ k = ((k << 2) | (k >> 30)) ^ *s++;
+ return k;
+}
+
+unsigned int
+ohash_lookup_interval(struct ohash *h, const char *start, const char *end,
+ uint32_t hv)
+{
+ unsigned int i, incr;
+ unsigned int empty;
+
+#ifdef STATS_HASH
+ STAT_HASH_LOOKUP++;
+#endif
+ empty = NONE;
+ i = hv % h->size;
+ incr = ((hv % (h->size-2)) & ~1) + 1;
+ while (h->t[i].p != NULL) {
+#ifdef STATS_HASH
+ STAT_HASH_LENGTH++;
+#endif
+ if (h->t[i].p == DELETED) {
+ if (empty == NONE)
+ empty = i;
+ } else if (h->t[i].hv == hv &&
+ strncmp(h->t[i].p+h->info.key_offset, start,
+ end - start) == 0 &&
+ (h->t[i].p+h->info.key_offset)[end-start] == '\0') {
+ if (empty != NONE) {
+ h->t[empty].hv = hv;
+ h->t[empty].p = h->t[i].p;
+ h->t[i].p = DELETED;
+ return empty;
+ } else {
+#ifdef STATS_HASH
+ STAT_HASH_POSITIVE++;
+#endif
+ return i;
+ }
+ }
+ i += incr;
+ if (i >= h->size)
+ i -= h->size;
+ }
+
+ /* Found an empty position. */
+ if (empty != NONE)
+ i = empty;
+ h->t[i].hv = hv;
+ return i;
+}
+
+unsigned int
+ohash_lookup_memory(struct ohash *h, const char *k, size_t size, uint32_t hv)
+{
+ unsigned int i, incr;
+ unsigned int empty;
+
+#ifdef STATS_HASH
+ STAT_HASH_LOOKUP++;
+#endif
+ empty = NONE;
+ i = hv % h->size;
+ incr = ((hv % (h->size-2)) & ~1) + 1;
+ while (h->t[i].p != NULL) {
+#ifdef STATS_HASH
+ STAT_HASH_LENGTH++;
+#endif
+ if (h->t[i].p == DELETED) {
+ if (empty == NONE)
+ empty = i;
+ } else if (h->t[i].hv == hv &&
+ memcmp(h->t[i].p+h->info.key_offset, k, size) == 0) {
+ if (empty != NONE) {
+ h->t[empty].hv = hv;
+ h->t[empty].p = h->t[i].p;
+ h->t[i].p = DELETED;
+ return empty;
+ } else {
+#ifdef STATS_HASH
+ STAT_HASH_POSITIVE++;
+#endif
+ } return i;
+ }
+ i += incr;
+ if (i >= h->size)
+ i -= h->size;
+ }
+
+ /* Found an empty position. */
+ if (empty != NONE)
+ i = empty;
+ h->t[i].hv = hv;
+ return i;
+}
+
+unsigned int
+ohash_qlookup(struct ohash *h, const char *s)
+{
+ const char *e = NULL;
+ return ohash_qlookupi(h, s, &e);
+}
+
+unsigned int
+ohash_qlookupi(struct ohash *h, const char *s, const char **e)
+{
+ uint32_t hv;
+
+ hv = ohash_interval(s, e);
+ return ohash_lookup_interval(h, s, *e, hv);
+}
diff --git a/lib/libutil/ohash.h b/lib/libutil/ohash.h
new file mode 100644
index 0000000..c5f81ec
--- /dev/null
+++ b/lib/libutil/ohash.h
@@ -0,0 +1,74 @@
+/* $OpenBSD: ohash.h,v 1.2 2014/06/02 18:52:03 deraadt Exp $ */
+
+/* Copyright (c) 1999, 2004 Marc Espie <espie@openbsd.org>
+ *
+ * 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.
+ */
+
+#ifndef OHASH_H
+#define OHASH_H
+
+/* Open hashing support.
+ * Open hashing was chosen because it is much lighter than other hash
+ * techniques, and more efficient in most cases.
+ */
+
+/* user-visible data structure */
+struct ohash_info {
+ ptrdiff_t key_offset;
+ void *data; /* user data */
+ void *(*calloc)(size_t, size_t, void *);
+ void (*free)(void *, void *);
+ void *(*alloc)(size_t, void *);
+};
+
+struct _ohash_record;
+
+/* private structure. It's there just so you can do a sizeof */
+struct ohash {
+ struct _ohash_record *t;
+ struct ohash_info info;
+ unsigned int size;
+ unsigned int total;
+ unsigned int deleted;
+};
+
+/* For this to be tweakable, we use small primitives, and leave part of the
+ * logic to the client application. e.g., hashing is left to the client
+ * application. We also provide a simple table entry lookup that yields
+ * a hashing table index (opaque) to be used in find/insert/remove.
+ * The keys are stored at a known position in the client data.
+ */
+__BEGIN_DECLS
+void ohash_init(struct ohash *, unsigned, struct ohash_info *);
+void ohash_delete(struct ohash *);
+
+unsigned int ohash_lookup_interval(struct ohash *, const char *,
+ const char *, uint32_t);
+unsigned int ohash_lookup_memory(struct ohash *, const char *,
+ size_t, uint32_t)
+ __attribute__ ((__bounded__(__string__,2,3)));
+void *ohash_find(struct ohash *, unsigned int);
+void *ohash_remove(struct ohash *, unsigned int);
+void *ohash_insert(struct ohash *, unsigned int, void *);
+void *ohash_first(struct ohash *, unsigned int *);
+void *ohash_next(struct ohash *, unsigned int *);
+unsigned int ohash_entries(struct ohash *);
+
+void *ohash_create_entry(struct ohash_info *, const char *, const char **);
+uint32_t ohash_interval(const char *, const char **);
+
+unsigned int ohash_qlookupi(struct ohash *, const char *, const char **);
+unsigned int ohash_qlookup(struct ohash *, const char *);
+__END_DECLS
+#endif
diff --git a/lib/libutil/pidfile.c b/lib/libutil/pidfile.c
new file mode 100644
index 0000000..7c07a20
--- /dev/null
+++ b/lib/libutil/pidfile.c
@@ -0,0 +1,106 @@
+/* $OpenBSD: pidfile.c,v 1.14 2019/06/28 14:20:40 schwarze Exp $ */
+/* $NetBSD: pidfile.c,v 1.4 2001/02/19 22:43:42 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <paths.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <util.h>
+
+static char *pidfile_path;
+static pid_t pidfile_pid;
+
+static void pidfile_cleanup(void);
+
+extern char *__progname;
+
+int
+pidfile(const char *basename)
+{
+ int save_errno;
+ pid_t pid;
+ FILE *f;
+
+ if (basename == NULL)
+ basename = __progname;
+
+ free(pidfile_path);
+ pidfile_path = NULL;
+
+ /* _PATH_VARRUN includes trailing / */
+ if (asprintf(&pidfile_path, "%s%s.pid", _PATH_VARRUN, basename) == -1)
+ return (-1);
+
+ if ((f = fopen(pidfile_path, "w")) == NULL) {
+ save_errno = errno;
+ free(pidfile_path);
+ pidfile_path = NULL;
+ errno = save_errno;
+ return (-1);
+ }
+
+ pid = getpid();
+ if (fprintf(f, "%ld\n", (long)pid) <= 0 || fflush(f) != 0) {
+ save_errno = errno;
+ (void) fclose(f);
+ (void) unlink(pidfile_path);
+ free(pidfile_path);
+ pidfile_path = NULL;
+ errno = save_errno;
+ return (-1);
+ }
+ (void) fclose(f);
+
+ pidfile_pid = pid;
+ if (atexit(pidfile_cleanup) != 0) {
+ save_errno = errno;
+ (void) unlink(pidfile_path);
+ free(pidfile_path);
+ pidfile_path = NULL;
+ pidfile_pid = 0;
+ errno = save_errno;
+ return (-1);
+ }
+
+ return (0);
+}
+
+static void
+pidfile_cleanup(void)
+{
+
+ if (pidfile_path != NULL && pidfile_pid == getpid())
+ (void) unlink(pidfile_path);
+}
diff --git a/lib/libutil/util.h b/lib/libutil/util.h
new file mode 100644
index 0000000..d7aa8fa
--- /dev/null
+++ b/lib/libutil/util.h
@@ -0,0 +1,127 @@
+/* $OpenBSD: util.h,v 1.36 2019/08/30 03:57:56 deraadt Exp $ */
+/* $NetBSD: util.h,v 1.2 1996/05/16 07:00:22 thorpej Exp $ */
+
+/*-
+ * Copyright (c) 1995
+ * The Regents of the University of California. All rights reserved.
+ * Portions Copyright (c) 1996, Jason Downs. 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 <sys/types.h>
+
+/*
+ * fparseln() specific operation flags.
+ */
+#define FPARSELN_UNESCESC 0x01
+#define FPARSELN_UNESCCONT 0x02
+#define FPARSELN_UNESCCOMM 0x04
+#define FPARSELN_UNESCREST 0x08
+#define FPARSELN_UNESCALL 0x0f
+
+/*
+ * opendev() specific operation flags.
+ */
+#define OPENDEV_PART 0x01 /* Try to open the raw partition. */
+#define OPENDEV_BLCK 0x04 /* Open block, not character device. */
+
+/*
+ * uu_lock(3) specific flags.
+ */
+#define UU_LOCK_INUSE (1)
+#define UU_LOCK_OK (0)
+#define UU_LOCK_OPEN_ERR (-1)
+#define UU_LOCK_READ_ERR (-2)
+#define UU_LOCK_CREAT_ERR (-3)
+#define UU_LOCK_WRITE_ERR (-4)
+#define UU_LOCK_LINK_ERR (-5)
+#define UU_LOCK_TRY_ERR (-6)
+#define UU_LOCK_OWNER_ERR (-7)
+
+/*
+ * fmt_scaled(3) specific flags.
+ */
+#define FMT_SCALED_STRSIZE 7 /* minus sign, 4 digits, suffix, null byte */
+
+/*
+ * stub struct definitions.
+ */
+struct __sFILE;
+struct login_cap;
+struct passwd;
+struct termios;
+struct utmp;
+struct winsize;
+
+__BEGIN_DECLS
+char *fparseln(struct __sFILE *, size_t *, size_t *, const char[3], int);
+void login(struct utmp *);
+int login_tty(int);
+int logout(const char *);
+void logwtmp(const char *, const char *, const char *);
+int opendev(const char *, int, int, char **);
+int pidfile(const char *);
+void pw_setdir(const char *);
+char *pw_file(const char *);
+int pw_lock(int);
+int pw_mkdb(char *, int);
+int pw_abort(void);
+void pw_init(void);
+void pw_edit(int, const char *);
+void pw_prompt(void);
+void pw_copy(int, int, const struct passwd *, const struct passwd *);
+int pw_scan(char *, struct passwd *, int *);
+void pw_error(const char *, int, int);
+int getptmfd(void);
+int openpty(int *, int *, char *, struct termios *, struct winsize *);
+int fdopenpty(int, int *, int *, char *, struct termios *,
+ struct winsize *);
+int opendisk(const char *, int, char *, size_t, int);
+pid_t forkpty(int *, char *, struct termios *, struct winsize *);
+pid_t fdforkpty(int, int *, char *, struct termios *, struct winsize *);
+int getmaxpartitions(void);
+int getrawpartition(void);
+void login_fbtab(const char *, uid_t, gid_t);
+int login_check_expire(struct __sFILE *, struct passwd *, char *, int);
+char *readlabelfs(char *, int);
+const char *uu_lockerr(int);
+int uu_lock(const char *);
+int uu_lock_txfr(const char *, pid_t);
+int uu_unlock(const char *);
+int fmt_scaled(long long, char *);
+int scan_scaled(char *, long long *);
+int isduid(const char *, int);
+int pkcs5_pbkdf2(const char *, size_t, const uint8_t *, size_t,
+ uint8_t *, size_t, unsigned int);
+int bcrypt_pbkdf(const char *, size_t, const uint8_t *, size_t,
+ uint8_t *, size_t, unsigned int);
+
+__END_DECLS
+
+#endif /* !_UTIL_H_ */
diff --git a/lib/libz/CVS/Entries b/lib/libz/CVS/Entries
new file mode 100644
index 0000000..baf70f2
--- /dev/null
+++ b/lib/libz/CVS/Entries
@@ -0,0 +1,30 @@
+/ChangeLog/1.4/Wed Jul 20 15:56:40 2005//
+/Makefile/1.20/Wed Sep 14 06:26:03 2016//
+/README/1.7/Wed Jul 20 15:56:40 2005//
+/adler32.c/1.6/Wed Jul 20 15:56:40 2005//
+/algorithm.doc/1.3/Tue Dec 16 22:33:02 2003//
+/compress.3/1.19/Fri Mar 16 16:58:26 2018//
+/compress.c/1.6/Wed Jul 20 15:56:41 2005//
+/crc32.c/1.8/Wed Jul 20 15:56:41 2005//
+/crc32.h/1.1/Tue Dec 16 22:33:02 2003//
+/deflate.c/1.11/Tue Oct 27 23:59:31 2009//
+/deflate.h/1.8/Mon Nov 26 09:28:33 2007//
+/generate_pkgconfig.sh/1.2/Thu May 5 20:58:15 2011//
+/gzio.c/1.15/Sat Apr 18 17:11:37 2020//
+/infback.c/1.6/Sat Jun 1 11:39:57 2019//
+/inffast.c/1.8/Sat Jun 1 11:39:57 2019//
+/inffast.h/1.4/Tue Dec 16 22:33:02 2003//
+/inffixed.h/1.3/Tue Dec 16 22:33:02 2003//
+/inflate.c/1.10/Sat Jun 1 11:39:57 2019//
+/inflate.h/1.2/Wed Jul 20 15:56:41 2005//
+/inftrees.c/1.9/Tue Oct 27 23:59:31 2009//
+/inftrees.h/1.5/Wed Jul 20 15:56:41 2005//
+/shlib_version/1.10/Tue Aug 13 05:52:17 2013//
+/trees.c/1.8/Wed Jul 20 15:56:41 2005//
+/trees.h/1.2/Tue Mar 12 00:25:57 2002//
+/uncompr.c/1.5/Tue Dec 16 22:33:02 2003//
+/zconf.h/1.8/Sun May 12 15:56:56 2019//
+/zlib.h/1.11/Sun May 12 15:56:56 2019//
+/zutil.c/1.9/Fri Aug 21 23:30:59 2015//
+/zutil.h/1.9/Wed Jul 20 15:56:42 2005//
+D
diff --git a/lib/libz/CVS/Repository b/lib/libz/CVS/Repository
new file mode 100644
index 0000000..f89f39e
--- /dev/null
+++ b/lib/libz/CVS/Repository
@@ -0,0 +1 @@
+src/lib/libz
diff --git a/lib/libz/CVS/Root b/lib/libz/CVS/Root
new file mode 100644
index 0000000..3811072
--- /dev/null
+++ b/lib/libz/CVS/Root
@@ -0,0 +1 @@
+/cvs
diff --git a/lib/libz/ChangeLog b/lib/libz/ChangeLog
new file mode 100644
index 0000000..c1b187d
--- /dev/null
+++ b/lib/libz/ChangeLog
@@ -0,0 +1,855 @@
+
+ ChangeLog file for zlib
+
+Changes in 1.2.3 (18 July 2005)
+- Apply security vulnerability fixes to contrib/infback9 as well
+- Clean up some text files (carriage returns, trailing space)
+- Update testzlib, vstudio, masmx64, and masmx86 in contrib [Vollant]
+
+Changes in 1.2.2.4 (11 July 2005)
+- Add inflatePrime() function for starting inflation at bit boundary
+- Avoid some Visual C warnings in deflate.c
+- Avoid more silly Visual C warnings in inflate.c and inftrees.c for 64-bit
+ compile
+- Fix some spelling errors in comments [Betts]
+- Correct inflateInit2() error return documentation in zlib.h
+- Added zran.c example of compressed data random access to examples
+ directory, shows use of inflatePrime()
+- Fix cast for assignments to strm->state in inflate.c and infback.c
+- Fix zlibCompileFlags() in zutil.c to use 1L for long shifts [Oberhumer]
+- Move declarations of gf2 functions to right place in crc32.c [Oberhumer]
+- Add cast in trees.c t avoid a warning [Oberhumer]
+- Avoid some warnings in fitblk.c, gun.c, gzjoin.c in examples [Oberhumer]
+- Update make_vms.com [Zinser]
+- Initialize state->write in inflateReset() since copied in inflate_fast()
+- Be more strict on incomplete code sets in inflate_table() and increase
+ ENOUGH and MAXD -- this repairs a possible security vulnerability for
+ invalid inflate input. Thanks to Tavis Ormandy and Markus Oberhumer for
+ discovering the vulnerability and providing test cases.
+- Add ia64 support to configure for HP-UX [Smith]
+- Add error return to gzread() for format or i/o error [Levin]
+- Use malloc.h for OS/2 [Necasek]
+
+Changes in 1.2.2.3 (27 May 2005)
+- Replace 1U constants in inflate.c and inftrees.c for 64-bit compile
+- Typecast fread() return values in gzio.c [Vollant]
+- Remove trailing space in minigzip.c outmode (VC++ can't deal with it)
+- Fix crc check bug in gzread() after gzungetc() [Heiner]
+- Add the deflateTune() function to adjust internal compression parameters
+- Add a fast gzip decompressor, gun.c, to examples (use of inflateBack)
+- Remove an incorrect assertion in examples/zpipe.c
+- Add C++ wrapper in infback9.h [Donais]
+- Fix bug in inflateCopy() when decoding fixed codes
+- Note in zlib.h how much deflateSetDictionary() actually uses
+- Remove USE_DICT_HEAD in deflate.c (would mess up inflate if used)
+- Add _WIN32_WCE to define WIN32 in zconf.in.h [Spencer]
+- Don't include stderr.h or errno.h for _WIN32_WCE in zutil.h [Spencer]
+- Add gzdirect() function to indicate transparent reads
+- Update contrib/minizip [Vollant]
+- Fix compilation of deflate.c when both ASMV and FASTEST [Oberhumer]
+- Add casts in crc32.c to avoid warnings [Oberhumer]
+- Add contrib/masmx64 [Vollant]
+- Update contrib/asm586, asm686, masmx86, testzlib, vstudio [Vollant]
+
+Changes in 1.2.2.2 (30 December 2004)
+- Replace structure assignments in deflate.c and inflate.c with zmemcpy to
+ avoid implicit memcpy calls (portability for no-library compilation)
+- Increase sprintf() buffer size in gzdopen() to allow for large numbers
+- Add INFLATE_STRICT to check distances against zlib header
+- Improve WinCE errno handling and comments [Chang]
+- Remove comment about no gzip header processing in FAQ
+- Add Z_FIXED strategy option to deflateInit2() to force fixed trees
+- Add updated make_vms.com [Coghlan], update README
+- Create a new "examples" directory, move gzappend.c there, add zpipe.c,
+ fitblk.c, gzlog.[ch], gzjoin.c, and zlib_how.html.
+- Add FAQ entry and comments in deflate.c on uninitialized memory access
+- Add Solaris 9 make options in configure [Gilbert]
+- Allow strerror() usage in gzio.c for STDC
+- Fix DecompressBuf in contrib/delphi/ZLib.pas [ManChesTer]
+- Update contrib/masmx86/inffas32.asm and gvmat32.asm [Vollant]
+- Use z_off_t for adler32_combine() and crc32_combine() lengths
+- Make adler32() much faster for small len
+- Use OS_CODE in deflate() default gzip header
+
+Changes in 1.2.2.1 (31 October 2004)
+- Allow inflateSetDictionary() call for raw inflate
+- Fix inflate header crc check bug for file names and comments
+- Add deflateSetHeader() and gz_header structure for custom gzip headers
+- Add inflateGetheader() to retrieve gzip headers
+- Add crc32_combine() and adler32_combine() functions
+- Add alloc_func, free_func, in_func, out_func to Z_PREFIX list
+- Use zstreamp consistently in zlib.h (inflate_back functions)
+- Remove GUNZIP condition from definition of inflate_mode in inflate.h
+ and in contrib/inflate86/inffast.S [Truta, Anderson]
+- Add support for AMD64 in contrib/inflate86/inffas86.c [Anderson]
+- Update projects/README.projects and projects/visualc6 [Truta]
+- Update win32/DLL_FAQ.txt [Truta]
+- Avoid warning under NO_GZCOMPRESS in gzio.c; fix typo [Truta]
+- Deprecate Z_ASCII; use Z_TEXT instead [Truta]
+- Use a new algorithm for setting strm->data_type in trees.c [Truta]
+- Do not define an exit() prototype in zutil.c unless DEBUG defined
+- Remove prototype of exit() from zutil.c, example.c, minigzip.c [Truta]
+- Add comment in zlib.h for Z_NO_FLUSH parameter to deflate()
+- Fix Darwin build version identification [Peterson]
+
+Changes in 1.2.2 (3 October 2004)
+- Update zlib.h comments on gzip in-memory processing
+- Set adler to 1 in inflateReset() to support Java test suite [Walles]
+- Add contrib/dotzlib [Ravn]
+- Update win32/DLL_FAQ.txt [Truta]
+- Update contrib/minizip [Vollant]
+- Move contrib/visual-basic.txt to old/ [Truta]
+- Fix assembler builds in projects/visualc6/ [Truta]
+
+Changes in 1.2.1.2 (9 September 2004)
+- Update INDEX file
+- Fix trees.c to update strm->data_type (no one ever noticed!)
+- Fix bug in error case in inflate.c, infback.c, and infback9.c [Brown]
+- Add "volatile" to crc table flag declaration (for DYNAMIC_CRC_TABLE)
+- Add limited multitasking protection to DYNAMIC_CRC_TABLE
+- Add NO_vsnprintf for VMS in zutil.h [Mozilla]
+- Don't declare strerror() under VMS [Mozilla]
+- Add comment to DYNAMIC_CRC_TABLE to use get_crc_table() to initialize
+- Update contrib/ada [Anisimkov]
+- Update contrib/minizip [Vollant]
+- Fix configure to not hardcode directories for Darwin [Peterson]
+- Fix gzio.c to not return error on empty files [Brown]
+- Fix indentation; update version in contrib/delphi/ZLib.pas and
+ contrib/pascal/zlibpas.pas [Truta]
+- Update mkasm.bat in contrib/masmx86 [Truta]
+- Update contrib/untgz [Truta]
+- Add projects/README.projects [Truta]
+- Add project for MS Visual C++ 6.0 in projects/visualc6 [Cadieux, Truta]
+- Update win32/DLL_FAQ.txt [Truta]
+- Update list of Z_PREFIX symbols in zconf.h [Randers-Pehrson, Truta]
+- Remove an unnecessary assignment to curr in inftrees.c [Truta]
+- Add OS/2 to exe builds in configure [Poltorak]
+- Remove err dummy parameter in zlib.h [Kientzle]
+
+Changes in 1.2.1.1 (9 January 2004)
+- Update email address in README
+- Several FAQ updates
+- Fix a big fat bug in inftrees.c that prevented decoding valid
+ dynamic blocks with only literals and no distance codes --
+ Thanks to "Hot Emu" for the bug report and sample file
+- Add a note to puff.c on no distance codes case.
+
+Changes in 1.2.1 (17 November 2003)
+- Remove a tab in contrib/gzappend/gzappend.c
+- Update some interfaces in contrib for new zlib functions
+- Update zlib version number in some contrib entries
+- Add Windows CE definition for ptrdiff_t in zutil.h [Mai, Truta]
+- Support shared libraries on Hurd and KFreeBSD [Brown]
+- Fix error in NO_DIVIDE option of adler32.c
+
+Changes in 1.2.0.8 (4 November 2003)
+- Update version in contrib/delphi/ZLib.pas and contrib/pascal/zlibpas.pas
+- Add experimental NO_DIVIDE #define in adler32.c
+ - Possibly faster on some processors (let me know if it is)
+- Correct Z_BLOCK to not return on first inflate call if no wrap
+- Fix strm->data_type on inflate() return to correctly indicate EOB
+- Add deflatePrime() function for appending in the middle of a byte
+- Add contrib/gzappend for an example of appending to a stream
+- Update win32/DLL_FAQ.txt [Truta]
+- Delete Turbo C comment in README [Truta]
+- Improve some indentation in zconf.h [Truta]
+- Fix infinite loop on bad input in configure script [Church]
+- Fix gzeof() for concatenated gzip files [Johnson]
+- Add example to contrib/visual-basic.txt [Michael B.]
+- Add -p to mkdir's in Makefile.in [vda]
+- Fix configure to properly detect presence or lack of printf functions
+- Add AS400 support [Monnerat]
+- Add a little Cygwin support [Wilson]
+
+Changes in 1.2.0.7 (21 September 2003)
+- Correct some debug formats in contrib/infback9
+- Cast a type in a debug statement in trees.c
+- Change search and replace delimiter in configure from % to # [Beebe]
+- Update contrib/untgz to 0.2 with various fixes [Truta]
+- Add build support for Amiga [Nikl]
+- Remove some directories in old that have been updated to 1.2
+- Add dylib building for Mac OS X in configure and Makefile.in
+- Remove old distribution stuff from Makefile
+- Update README to point to DLL_FAQ.txt, and add comment on Mac OS X
+- Update links in README
+
+Changes in 1.2.0.6 (13 September 2003)
+- Minor FAQ updates
+- Update contrib/minizip to 1.00 [Vollant]
+- Remove test of gz functions in example.c when GZ_COMPRESS defined [Truta]
+- Update POSTINC comment for 68060 [Nikl]
+- Add contrib/infback9 with deflate64 decoding (unsupported)
+- For MVS define NO_vsnprintf and undefine FAR [van Burik]
+- Add pragma for fdopen on MVS [van Burik]
+
+Changes in 1.2.0.5 (8 September 2003)
+- Add OF to inflateBackEnd() declaration in zlib.h
+- Remember start when using gzdopen in the middle of a file
+- Use internal off_t counters in gz* functions to properly handle seeks
+- Perform more rigorous check for distance-too-far in inffast.c
+- Add Z_BLOCK flush option to return from inflate at block boundary
+- Set strm->data_type on return from inflate
+ - Indicate bits unused, if at block boundary, and if in last block
+- Replace size_t with ptrdiff_t in crc32.c, and check for correct size
+- Add condition so old NO_DEFLATE define still works for compatibility
+- FAQ update regarding the Windows DLL [Truta]
+- INDEX update: add qnx entry, remove aix entry [Truta]
+- Install zlib.3 into mandir [Wilson]
+- Move contrib/zlib_dll_FAQ.txt to win32/DLL_FAQ.txt; update [Truta]
+- Adapt the zlib interface to the new DLL convention guidelines [Truta]
+- Introduce ZLIB_WINAPI macro to allow the export of functions using
+ the WINAPI calling convention, for Visual Basic [Vollant, Truta]
+- Update msdos and win32 scripts and makefiles [Truta]
+- Export symbols by name, not by ordinal, in win32/zlib.def [Truta]
+- Add contrib/ada [Anisimkov]
+- Move asm files from contrib/vstudio/vc70_32 to contrib/asm386 [Truta]
+- Rename contrib/asm386 to contrib/masmx86 [Truta, Vollant]
+- Add contrib/masm686 [Truta]
+- Fix offsets in contrib/inflate86 and contrib/masmx86/inffas32.asm
+ [Truta, Vollant]
+- Update contrib/delphi; rename to contrib/pascal; add example [Truta]
+- Remove contrib/delphi2; add a new contrib/delphi [Truta]
+- Avoid inclusion of the nonstandard <memory.h> in contrib/iostream,
+ and fix some method prototypes [Truta]
+- Fix the ZCR_SEED2 constant to avoid warnings in contrib/minizip
+ [Truta]
+- Avoid the use of backslash (\) in contrib/minizip [Vollant]
+- Fix file time handling in contrib/untgz; update makefiles [Truta]
+- Update contrib/vstudio/vc70_32 to comply with the new DLL guidelines
+ [Vollant]
+- Remove contrib/vstudio/vc15_16 [Vollant]
+- Rename contrib/vstudio/vc70_32 to contrib/vstudio/vc7 [Truta]
+- Update README.contrib [Truta]
+- Invert the assignment order of match_head and s->prev[...] in
+ INSERT_STRING [Truta]
+- Compare TOO_FAR with 32767 instead of 32768, to avoid 16-bit warnings
+ [Truta]
+- Compare function pointers with 0, not with NULL or Z_NULL [Truta]
+- Fix prototype of syncsearch in inflate.c [Truta]
+- Introduce ASMINF macro to be enabled when using an ASM implementation
+ of inflate_fast [Truta]
+- Change NO_DEFLATE to NO_GZCOMPRESS [Truta]
+- Modify test_gzio in example.c to take a single file name as a
+ parameter [Truta]
+- Exit the example.c program if gzopen fails [Truta]
+- Add type casts around strlen in example.c [Truta]
+- Remove casting to sizeof in minigzip.c; give a proper type
+ to the variable compared with SUFFIX_LEN [Truta]
+- Update definitions of STDC and STDC99 in zconf.h [Truta]
+- Synchronize zconf.h with the new Windows DLL interface [Truta]
+- Use SYS16BIT instead of __32BIT__ to distinguish between
+ 16- and 32-bit platforms [Truta]
+- Use far memory allocators in small 16-bit memory models for
+ Turbo C [Truta]
+- Add info about the use of ASMV, ASMINF and ZLIB_WINAPI in
+ zlibCompileFlags [Truta]
+- Cygwin has vsnprintf [Wilson]
+- In Windows16, OS_CODE is 0, as in MSDOS [Truta]
+- In Cygwin, OS_CODE is 3 (Unix), not 11 (Windows32) [Wilson]
+
+Changes in 1.2.0.4 (10 August 2003)
+- Minor FAQ updates
+- Be more strict when checking inflateInit2's windowBits parameter
+- Change NO_GUNZIP compile option to NO_GZIP to cover deflate as well
+- Add gzip wrapper option to deflateInit2 using windowBits
+- Add updated QNX rule in configure and qnx directory [Bonnefoy]
+- Make inflate distance-too-far checks more rigorous
+- Clean up FAR usage in inflate
+- Add casting to sizeof() in gzio.c and minigzip.c
+
+Changes in 1.2.0.3 (19 July 2003)
+- Fix silly error in gzungetc() implementation [Vollant]
+- Update contrib/minizip and contrib/vstudio [Vollant]
+- Fix printf format in example.c
+- Correct cdecl support in zconf.in.h [Anisimkov]
+- Minor FAQ updates
+
+Changes in 1.2.0.2 (13 July 2003)
+- Add ZLIB_VERNUM in zlib.h for numerical preprocessor comparisons
+- Attempt to avoid warnings in crc32.c for pointer-int conversion
+- Add AIX to configure, remove aix directory [Bakker]
+- Add some casts to minigzip.c
+- Improve checking after insecure sprintf() or vsprintf() calls
+- Remove #elif's from crc32.c
+- Change leave label to inf_leave in inflate.c and infback.c to avoid
+ library conflicts
+- Remove inflate gzip decoding by default--only enable gzip decoding by
+ special request for stricter backward compatibility
+- Add zlibCompileFlags() function to return compilation information
+- More typecasting in deflate.c to avoid warnings
+- Remove leading underscore from _Capital #defines [Truta]
+- Fix configure to link shared library when testing
+- Add some Windows CE target adjustments [Mai]
+- Remove #define ZLIB_DLL in zconf.h [Vollant]
+- Add zlib.3 [Rodgers]
+- Update RFC URL in deflate.c and algorithm.txt [Mai]
+- Add zlib_dll_FAQ.txt to contrib [Truta]
+- Add UL to some constants [Truta]
+- Update minizip and vstudio [Vollant]
+- Remove vestigial NEED_DUMMY_RETURN from zconf.in.h
+- Expand use of NO_DUMMY_DECL to avoid all dummy structures
+- Added iostream3 to contrib [Schwardt]
+- Replace rewind() with fseek() for WinCE [Truta]
+- Improve setting of zlib format compression level flags
+ - Report 0 for huffman and rle strategies and for level == 0 or 1
+ - Report 2 only for level == 6
+- Only deal with 64K limit when necessary at compile time [Truta]
+- Allow TOO_FAR check to be turned off at compile time [Truta]
+- Add gzclearerr() function [Souza]
+- Add gzungetc() function
+
+Changes in 1.2.0.1 (17 March 2003)
+- Add Z_RLE strategy for run-length encoding [Truta]
+ - When Z_RLE requested, restrict matches to distance one
+ - Update zlib.h, minigzip.c, gzopen(), gzdopen() for Z_RLE
+- Correct FASTEST compilation to allow level == 0
+- Clean up what gets compiled for FASTEST
+- Incorporate changes to zconf.in.h [Vollant]
+ - Refine detection of Turbo C need for dummy returns
+ - Refine ZLIB_DLL compilation
+ - Include additional header file on VMS for off_t typedef
+- Try to use _vsnprintf where it supplants vsprintf [Vollant]
+- Add some casts in inffast.c
+- Enchance comments in zlib.h on what happens if gzprintf() tries to
+ write more than 4095 bytes before compression
+- Remove unused state from inflateBackEnd()
+- Remove exit(0) from minigzip.c, example.c
+- Get rid of all those darn tabs
+- Add "check" target to Makefile.in that does the same thing as "test"
+- Add "mostlyclean" and "maintainer-clean" targets to Makefile.in
+- Update contrib/inflate86 [Anderson]
+- Update contrib/testzlib, contrib/vstudio, contrib/minizip [Vollant]
+- Add msdos and win32 directories with makefiles [Truta]
+- More additions and improvements to the FAQ
+
+Changes in 1.2.0 (9 March 2003)
+- New and improved inflate code
+ - About 20% faster
+ - Does not allocate 32K window unless and until needed
+ - Automatically detects and decompresses gzip streams
+ - Raw inflate no longer needs an extra dummy byte at end
+ - Added inflateBack functions using a callback interface--even faster
+ than inflate, useful for file utilities (gzip, zip)
+ - Added inflateCopy() function to record state for random access on
+ externally generated deflate streams (e.g. in gzip files)
+ - More readable code (I hope)
+- New and improved crc32()
+ - About 50% faster, thanks to suggestions from Rodney Brown
+- Add deflateBound() and compressBound() functions
+- Fix memory leak in deflateInit2()
+- Permit setting dictionary for raw deflate (for parallel deflate)
+- Fix const declaration for gzwrite()
+- Check for some malloc() failures in gzio.c
+- Fix bug in gzopen() on single-byte file 0x1f
+- Fix bug in gzread() on concatenated file with 0x1f at end of buffer
+ and next buffer doesn't start with 0x8b
+- Fix uncompress() to return Z_DATA_ERROR on truncated input
+- Free memory at end of example.c
+- Remove MAX #define in trees.c (conflicted with some libraries)
+- Fix static const's in deflate.c, gzio.c, and zutil.[ch]
+- Declare malloc() and free() in gzio.c if STDC not defined
+- Use malloc() instead of calloc() in zutil.c if int big enough
+- Define STDC for AIX
+- Add aix/ with approach for compiling shared library on AIX
+- Add HP-UX support for shared libraries in configure
+- Add OpenUNIX support for shared libraries in configure
+- Use $cc instead of gcc to build shared library
+- Make prefix directory if needed when installing
+- Correct Macintosh avoidance of typedef Byte in zconf.h
+- Correct Turbo C memory allocation when under Linux
+- Use libz.a instead of -lz in Makefile (assure use of compiled library)
+- Update configure to check for snprintf or vsnprintf functions and their
+ return value, warn during make if using an insecure function
+- Fix configure problem with compile-time knowledge of HAVE_UNISTD_H that
+ is lost when library is used--resolution is to build new zconf.h
+- Documentation improvements (in zlib.h):
+ - Document raw deflate and inflate
+ - Update RFCs URL
+ - Point out that zlib and gzip formats are different
+ - Note that Z_BUF_ERROR is not fatal
+ - Document string limit for gzprintf() and possible buffer overflow
+ - Note requirement on avail_out when flushing
+ - Note permitted values of flush parameter of inflate()
+- Add some FAQs (and even answers) to the FAQ
+- Add contrib/inflate86/ for x86 faster inflate
+- Add contrib/blast/ for PKWare Data Compression Library decompression
+- Add contrib/puff/ simple inflate for deflate format description
+
+Changes in 1.1.4 (11 March 2002)
+- ZFREE was repeated on same allocation on some error conditions.
+ This creates a security problem described in
+ http://www.zlib.org/advisory-2002-03-11.txt
+- Returned incorrect error (Z_MEM_ERROR) on some invalid data
+- Avoid accesses before window for invalid distances with inflate window
+ less than 32K.
+- force windowBits > 8 to avoid a bug in the encoder for a window size
+ of 256 bytes. (A complete fix will be available in 1.1.5).
+
+Changes in 1.1.3 (9 July 1998)
+- fix "an inflate input buffer bug that shows up on rare but persistent
+ occasions" (Mark)
+- fix gzread and gztell for concatenated .gz files (Didier Le Botlan)
+- fix gzseek(..., SEEK_SET) in write mode
+- fix crc check after a gzeek (Frank Faubert)
+- fix miniunzip when the last entry in a zip file is itself a zip file
+ (J Lillge)
+- add contrib/asm586 and contrib/asm686 (Brian Raiter)
+ See http://www.muppetlabs.com/~breadbox/software/assembly.html
+- add support for Delphi 3 in contrib/delphi (Bob Dellaca)
+- add support for C++Builder 3 and Delphi 3 in contrib/delphi2 (Davide Moretti)
+- do not exit prematurely in untgz if 0 at start of block (Magnus Holmgren)
+- use macro EXTERN instead of extern to support DLL for BeOS (Sander Stoks)
+- added a FAQ file
+
+- Support gzdopen on Mac with Metrowerks (Jason Linhart)
+- Do not redefine Byte on Mac (Brad Pettit & Jason Linhart)
+- define SEEK_END too if SEEK_SET is not defined (Albert Chin-A-Young)
+- avoid some warnings with Borland C (Tom Tanner)
+- fix a problem in contrib/minizip/zip.c for 16-bit MSDOS (Gilles Vollant)
+- emulate utime() for WIN32 in contrib/untgz (Gilles Vollant)
+- allow several arguments to configure (Tim Mooney, Frodo Looijaard)
+- use libdir and includedir in Makefile.in (Tim Mooney)
+- support shared libraries on OSF1 V4 (Tim Mooney)
+- remove so_locations in "make clean" (Tim Mooney)
+- fix maketree.c compilation error (Glenn, Mark)
+- Python interface to zlib now in Python 1.5 (Jeremy Hylton)
+- new Makefile.riscos (Rich Walker)
+- initialize static descriptors in trees.c for embedded targets (Nick Smith)
+- use "foo-gz" in example.c for RISCOS and VMS (Nick Smith)
+- add the OS/2 files in Makefile.in too (Andrew Zabolotny)
+- fix fdopen and halloc macros for Microsoft C 6.0 (Tom Lane)
+- fix maketree.c to allow clean compilation of inffixed.h (Mark)
+- fix parameter check in deflateCopy (Gunther Nikl)
+- cleanup trees.c, use compressed_len only in debug mode (Christian Spieler)
+- Many portability patches by Christian Spieler:
+ . zutil.c, zutil.h: added "const" for zmem*
+ . Make_vms.com: fixed some typos
+ . Make_vms.com: msdos/Makefile.*: removed zutil.h from some dependency lists
+ . msdos/Makefile.msc: remove "default rtl link library" info from obj files
+ . msdos/Makefile.*: use model-dependent name for the built zlib library
+ . msdos/Makefile.emx, nt/Makefile.emx, nt/Makefile.gcc:
+ new makefiles, for emx (DOS/OS2), emx&rsxnt and mingw32 (Windows 9x / NT)
+- use define instead of typedef for Bytef also for MSC small/medium (Tom Lane)
+- replace __far with _far for better portability (Christian Spieler, Tom Lane)
+- fix test for errno.h in configure (Tim Newsham)
+
+Changes in 1.1.2 (19 March 98)
+- added contrib/minzip, mini zip and unzip based on zlib (Gilles Vollant)
+ See http://www.winimage.com/zLibDll/unzip.html
+- preinitialize the inflate tables for fixed codes, to make the code
+ completely thread safe (Mark)
+- some simplifications and slight speed-up to the inflate code (Mark)
+- fix gzeof on non-compressed files (Allan Schrum)
+- add -std1 option in configure for OSF1 to fix gzprintf (Martin Mokrejs)
+- use default value of 4K for Z_BUFSIZE for 16-bit MSDOS (Tim Wegner + Glenn)
+- added os2/Makefile.def and os2/zlib.def (Andrew Zabolotny)
+- add shared lib support for UNIX_SV4.2MP (MATSUURA Takanori)
+- do not wrap extern "C" around system includes (Tom Lane)
+- mention zlib binding for TCL in README (Andreas Kupries)
+- added amiga/Makefile.pup for Amiga powerUP SAS/C PPC (Andreas Kleinert)
+- allow "make install prefix=..." even after configure (Glenn Randers-Pehrson)
+- allow "configure --prefix $HOME" (Tim Mooney)
+- remove warnings in example.c and gzio.c (Glenn Randers-Pehrson)
+- move Makefile.sas to amiga/Makefile.sas
+
+Changes in 1.1.1 (27 Feb 98)
+- fix macros _tr_tally_* in deflate.h for debug mode (Glenn Randers-Pehrson)
+- remove block truncation heuristic which had very marginal effect for zlib
+ (smaller lit_bufsize than in gzip 1.2.4) and degraded a little the
+ compression ratio on some files. This also allows inlining _tr_tally for
+ matches in deflate_slow.
+- added msdos/Makefile.w32 for WIN32 Microsoft Visual C++ (Bob Frazier)
+
+Changes in 1.1.0 (24 Feb 98)
+- do not return STREAM_END prematurely in inflate (John Bowler)
+- revert to the zlib 1.0.8 inflate to avoid the gcc 2.8.0 bug (Jeremy Buhler)
+- compile with -DFASTEST to get compression code optimized for speed only
+- in minigzip, try mmap'ing the input file first (Miguel Albrecht)
+- increase size of I/O buffers in minigzip.c and gzio.c (not a big gain
+ on Sun but significant on HP)
+
+- add a pointer to experimental unzip library in README (Gilles Vollant)
+- initialize variable gcc in configure (Chris Herborth)
+
+Changes in 1.0.9 (17 Feb 1998)
+- added gzputs and gzgets functions
+- do not clear eof flag in gzseek (Mark Diekhans)
+- fix gzseek for files in transparent mode (Mark Diekhans)
+- do not assume that vsprintf returns the number of bytes written (Jens Krinke)
+- replace EXPORT with ZEXPORT to avoid conflict with other programs
+- added compress2 in zconf.h, zlib.def, zlib.dnt
+- new asm code from Gilles Vollant in contrib/asm386
+- simplify the inflate code (Mark):
+ . Replace ZALLOC's in huft_build() with single ZALLOC in inflate_blocks_new()
+ . ZALLOC the length list in inflate_trees_fixed() instead of using stack
+ . ZALLOC the value area for huft_build() instead of using stack
+ . Simplify Z_FINISH check in inflate()
+
+- Avoid gcc 2.8.0 comparison bug a little differently than zlib 1.0.8
+- in inftrees.c, avoid cc -O bug on HP (Farshid Elahi)
+- in zconf.h move the ZLIB_DLL stuff earlier to avoid problems with
+ the declaration of FAR (Gilles VOllant)
+- install libz.so* with mode 755 (executable) instead of 644 (Marc Lehmann)
+- read_buf buf parameter of type Bytef* instead of charf*
+- zmemcpy parameters are of type Bytef*, not charf* (Joseph Strout)
+- do not redeclare unlink in minigzip.c for WIN32 (John Bowler)
+- fix check for presence of directories in "make install" (Ian Willis)
+
+Changes in 1.0.8 (27 Jan 1998)
+- fixed offsets in contrib/asm386/gvmat32.asm (Gilles Vollant)
+- fix gzgetc and gzputc for big endian systems (Markus Oberhumer)
+- added compress2() to allow setting the compression level
+- include sys/types.h to get off_t on some systems (Marc Lehmann & QingLong)
+- use constant arrays for the static trees in trees.c instead of computing
+ them at run time (thanks to Ken Raeburn for this suggestion). To create
+ trees.h, compile with GEN_TREES_H and run "make test".
+- check return code of example in "make test" and display result
+- pass minigzip command line options to file_compress
+- simplifying code of inflateSync to avoid gcc 2.8 bug
+
+- support CC="gcc -Wall" in configure -s (QingLong)
+- avoid a flush caused by ftell in gzopen for write mode (Ken Raeburn)
+- fix test for shared library support to avoid compiler warnings
+- zlib.lib -> zlib.dll in msdos/zlib.rc (Gilles Vollant)
+- check for TARGET_OS_MAC in addition to MACOS (Brad Pettit)
+- do not use fdopen for Metrowerks on Mac (Brad Pettit))
+- add checks for gzputc and gzputc in example.c
+- avoid warnings in gzio.c and deflate.c (Andreas Kleinert)
+- use const for the CRC table (Ken Raeburn)
+- fixed "make uninstall" for shared libraries
+- use Tracev instead of Trace in infblock.c
+- in example.c use correct compressed length for test_sync
+- suppress +vnocompatwarnings in configure for HPUX (not always supported)
+
+Changes in 1.0.7 (20 Jan 1998)
+- fix gzseek which was broken in write mode
+- return error for gzseek to negative absolute position
+- fix configure for Linux (Chun-Chung Chen)
+- increase stack space for MSC (Tim Wegner)
+- get_crc_table and inflateSyncPoint are EXPORTed (Gilles Vollant)
+- define EXPORTVA for gzprintf (Gilles Vollant)
+- added man page zlib.3 (Rick Rodgers)
+- for contrib/untgz, fix makedir() and improve Makefile
+
+- check gzseek in write mode in example.c
+- allocate extra buffer for seeks only if gzseek is actually called
+- avoid signed/unsigned comparisons (Tim Wegner, Gilles Vollant)
+- add inflateSyncPoint in zconf.h
+- fix list of exported functions in nt/zlib.dnt and mdsos/zlib.def
+
+Changes in 1.0.6 (19 Jan 1998)
+- add functions gzprintf, gzputc, gzgetc, gztell, gzeof, gzseek, gzrewind and
+ gzsetparams (thanks to Roland Giersig and Kevin Ruland for some of this code)
+- Fix a deflate bug occurring only with compression level 0 (thanks to
+ Andy Buckler for finding this one).
+- In minigzip, pass transparently also the first byte for .Z files.
+- return Z_BUF_ERROR instead of Z_OK if output buffer full in uncompress()
+- check Z_FINISH in inflate (thanks to Marc Schluper)
+- Implement deflateCopy (thanks to Adam Costello)
+- make static libraries by default in configure, add --shared option.
+- move MSDOS or Windows specific files to directory msdos
+- suppress the notion of partial flush to simplify the interface
+ (but the symbol Z_PARTIAL_FLUSH is kept for compatibility with 1.0.4)
+- suppress history buffer provided by application to simplify the interface
+ (this feature was not implemented anyway in 1.0.4)
+- next_in and avail_in must be initialized before calling inflateInit or
+ inflateInit2
+- add EXPORT in all exported functions (for Windows DLL)
+- added Makefile.nt (thanks to Stephen Williams)
+- added the unsupported "contrib" directory:
+ contrib/asm386/ by Gilles Vollant <info@winimage.com>
+ 386 asm code replacing longest_match().
+ contrib/iostream/ by Kevin Ruland <kevin@rodin.wustl.edu>
+ A C++ I/O streams interface to the zlib gz* functions
+ contrib/iostream2/ by Tyge Løvset <Tyge.Lovset@cmr.no>
+ Another C++ I/O streams interface
+ contrib/untgz/ by "Pedro A. Aranda Guti\irrez" <paag@tid.es>
+ A very simple tar.gz file extractor using zlib
+ contrib/visual-basic.txt by Carlos Rios <c_rios@sonda.cl>
+ How to use compress(), uncompress() and the gz* functions from VB.
+- pass params -f (filtered data), -h (huffman only), -1 to -9 (compression
+ level) in minigzip (thanks to Tom Lane)
+
+- use const for rommable constants in deflate
+- added test for gzseek and gztell in example.c
+- add undocumented function inflateSyncPoint() (hack for Paul Mackerras)
+- add undocumented function zError to convert error code to string
+ (for Tim Smithers)
+- Allow compilation of gzio with -DNO_DEFLATE to avoid the compression code.
+- Use default memcpy for Symantec MSDOS compiler.
+- Add EXPORT keyword for check_func (needed for Windows DLL)
+- add current directory to LD_LIBRARY_PATH for "make test"
+- create also a link for libz.so.1
+- added support for FUJITSU UXP/DS (thanks to Toshiaki Nomura)
+- use $(SHAREDLIB) instead of libz.so in Makefile.in (for HPUX)
+- added -soname for Linux in configure (Chun-Chung Chen,
+- assign numbers to the exported functions in zlib.def (for Windows DLL)
+- add advice in zlib.h for best usage of deflateSetDictionary
+- work around compiler bug on Atari (cast Z_NULL in call of s->checkfn)
+- allow compilation with ANSI keywords only enabled for TurboC in large model
+- avoid "versionString"[0] (Borland bug)
+- add NEED_DUMMY_RETURN for Borland
+- use variable z_verbose for tracing in debug mode (L. Peter Deutsch).
+- allow compilation with CC
+- defined STDC for OS/2 (David Charlap)
+- limit external names to 8 chars for MVS (Thomas Lund)
+- in minigzip.c, use static buffers only for 16-bit systems
+- fix suffix check for "minigzip -d foo.gz"
+- do not return an error for the 2nd of two consecutive gzflush() (Felix Lee)
+- use _fdopen instead of fdopen for MSC >= 6.0 (Thomas Fanslau)
+- added makelcc.bat for lcc-win32 (Tom St Denis)
+- in Makefile.dj2, use copy and del instead of install and rm (Frank Donahoe)
+- Avoid expanded $Id. Use "rcs -kb" or "cvs admin -kb" to avoid Id expansion.
+- check for unistd.h in configure (for off_t)
+- remove useless check parameter in inflate_blocks_free
+- avoid useless assignment of s->check to itself in inflate_blocks_new
+- do not flush twice in gzclose (thanks to Ken Raeburn)
+- rename FOPEN as F_OPEN to avoid clash with /usr/include/sys/file.h
+- use NO_ERRNO_H instead of enumeration of operating systems with errno.h
+- work around buggy fclose on pipes for HP/UX
+- support zlib DLL with BORLAND C++ 5.0 (thanks to Glenn Randers-Pehrson)
+- fix configure if CC is already equal to gcc
+
+Changes in 1.0.5 (3 Jan 98)
+- Fix inflate to terminate gracefully when fed corrupted or invalid data
+- Use const for rommable constants in inflate
+- Eliminate memory leaks on error conditions in inflate
+- Removed some vestigial code in inflate
+- Update web address in README
+
+Changes in 1.0.4 (24 Jul 96)
+- In very rare conditions, deflate(s, Z_FINISH) could fail to produce an EOF
+ bit, so the decompressor could decompress all the correct data but went
+ on to attempt decompressing extra garbage data. This affected minigzip too.
+- zlibVersion and gzerror return const char* (needed for DLL)
+- port to RISCOS (no fdopen, no multiple dots, no unlink, no fileno)
+- use z_error only for DEBUG (avoid problem with DLLs)
+
+Changes in 1.0.3 (2 Jul 96)
+- use z_streamp instead of z_stream *, which is now a far pointer in MSDOS
+ small and medium models; this makes the library incompatible with previous
+ versions for these models. (No effect in large model or on other systems.)
+- return OK instead of BUF_ERROR if previous deflate call returned with
+ avail_out as zero but there is nothing to do
+- added memcmp for non STDC compilers
+- define NO_DUMMY_DECL for more Mac compilers (.h files merged incorrectly)
+- define __32BIT__ if __386__ or i386 is defined (pb. with Watcom and SCO)
+- better check for 16-bit mode MSC (avoids problem with Symantec)
+
+Changes in 1.0.2 (23 May 96)
+- added Windows DLL support
+- added a function zlibVersion (for the DLL support)
+- fixed declarations using Bytef in infutil.c (pb with MSDOS medium model)
+- Bytef is define's instead of typedef'd only for Borland C
+- avoid reading uninitialized memory in example.c
+- mention in README that the zlib format is now RFC1950
+- updated Makefile.dj2
+- added algorithm.doc
+
+Changes in 1.0.1 (20 May 96) [1.0 skipped to avoid confusion]
+- fix array overlay in deflate.c which sometimes caused bad compressed data
+- fix inflate bug with empty stored block
+- fix MSDOS medium model which was broken in 0.99
+- fix deflateParams() which could generated bad compressed data.
+- Bytef is define'd instead of typedef'ed (work around Borland bug)
+- added an INDEX file
+- new makefiles for DJGPP (Makefile.dj2), 32-bit Borland (Makefile.b32),
+ Watcom (Makefile.wat), Amiga SAS/C (Makefile.sas)
+- speed up adler32 for modern machines without auto-increment
+- added -ansi for IRIX in configure
+- static_init_done in trees.c is an int
+- define unlink as delete for VMS
+- fix configure for QNX
+- add configure branch for SCO and HPUX
+- avoid many warnings (unused variables, dead assignments, etc...)
+- no fdopen for BeOS
+- fix the Watcom fix for 32 bit mode (define FAR as empty)
+- removed redefinition of Byte for MKWERKS
+- work around an MWKERKS bug (incorrect merge of all .h files)
+
+Changes in 0.99 (27 Jan 96)
+- allow preset dictionary shared between compressor and decompressor
+- allow compression level 0 (no compression)
+- add deflateParams in zlib.h: allow dynamic change of compression level
+ and compression strategy.
+- test large buffers and deflateParams in example.c
+- add optional "configure" to build zlib as a shared library
+- suppress Makefile.qnx, use configure instead
+- fixed deflate for 64-bit systems (detected on Cray)
+- fixed inflate_blocks for 64-bit systems (detected on Alpha)
+- declare Z_DEFLATED in zlib.h (possible parameter for deflateInit2)
+- always return Z_BUF_ERROR when deflate() has nothing to do
+- deflateInit and inflateInit are now macros to allow version checking
+- prefix all global functions and types with z_ with -DZ_PREFIX
+- make falloc completely reentrant (inftrees.c)
+- fixed very unlikely race condition in ct_static_init
+- free in reverse order of allocation to help memory manager
+- use zlib-1.0/* instead of zlib/* inside the tar.gz
+- make zlib warning-free with "gcc -O3 -Wall -Wwrite-strings -Wpointer-arith
+ -Wconversion -Wstrict-prototypes -Wmissing-prototypes"
+- allow gzread on concatenated .gz files
+- deflateEnd now returns Z_DATA_ERROR if it was premature
+- deflate is finally (?) fully deterministic (no matches beyond end of input)
+- Document Z_SYNC_FLUSH
+- add uninstall in Makefile
+- Check for __cpluplus in zlib.h
+- Better test in ct_align for partial flush
+- avoid harmless warnings for Borland C++
+- initialize hash_head in deflate.c
+- avoid warning on fdopen (gzio.c) for HP cc -Aa
+- include stdlib.h for STDC compilers
+- include errno.h for Cray
+- ignore error if ranlib doesn't exist
+- call ranlib twice for NeXTSTEP
+- use exec_prefix instead of prefix for libz.a
+- renamed ct_* as _tr_* to avoid conflict with applications
+- clear z->msg in inflateInit2 before any error return
+- initialize opaque in example.c, gzio.c, deflate.c and inflate.c
+- fixed typo in zconf.h (_GNUC__ => __GNUC__)
+- check for WIN32 in zconf.h and zutil.c (avoid farmalloc in 32-bit mode)
+- fix typo in Make_vms.com (f$trnlnm -> f$getsyi)
+- in fcalloc, normalize pointer if size > 65520 bytes
+- don't use special fcalloc for 32 bit Borland C++
+- use STDC instead of __GO32__ to avoid redeclaring exit, calloc, etc...
+- use Z_BINARY instead of BINARY
+- document that gzclose after gzdopen will close the file
+- allow "a" as mode in gzopen.
+- fix error checking in gzread
+- allow skipping .gz extra-field on pipes
+- added reference to Perl interface in README
+- put the crc table in FAR data (I dislike more and more the medium model :)
+- added get_crc_table
+- added a dimension to all arrays (Borland C can't count).
+- workaround Borland C bug in declaration of inflate_codes_new & inflate_fast
+- guard against multiple inclusion of *.h (for precompiled header on Mac)
+- Watcom C pretends to be Microsoft C small model even in 32 bit mode.
+- don't use unsized arrays to avoid silly warnings by Visual C++:
+ warning C4746: 'inflate_mask' : unsized array treated as '__far'
+ (what's wrong with far data in far model?).
+- define enum out of inflate_blocks_state to allow compilation with C++
+
+Changes in 0.95 (16 Aug 95)
+- fix MSDOS small and medium model (now easier to adapt to any compiler)
+- inlined send_bits
+- fix the final (:-) bug for deflate with flush (output was correct but
+ not completely flushed in rare occasions).
+- default window size is same for compression and decompression
+ (it's now sufficient to set MAX_WBITS in zconf.h).
+- voidp -> voidpf and voidnp -> voidp (for consistency with other
+ typedefs and because voidnp was not near in large model).
+
+Changes in 0.94 (13 Aug 95)
+- support MSDOS medium model
+- fix deflate with flush (could sometimes generate bad output)
+- fix deflateReset (zlib header was incorrectly suppressed)
+- added support for VMS
+- allow a compression level in gzopen()
+- gzflush now calls fflush
+- For deflate with flush, flush even if no more input is provided.
+- rename libgz.a as libz.a
+- avoid complex expression in infcodes.c triggering Turbo C bug
+- work around a problem with gcc on Alpha (in INSERT_STRING)
+- don't use inline functions (problem with some gcc versions)
+- allow renaming of Byte, uInt, etc... with #define.
+- avoid warning about (unused) pointer before start of array in deflate.c
+- avoid various warnings in gzio.c, example.c, infblock.c, adler32.c, zutil.c
+- avoid reserved word 'new' in trees.c
+
+Changes in 0.93 (25 June 95)
+- temporarily disable inline functions
+- make deflate deterministic
+- give enough lookahead for PARTIAL_FLUSH
+- Set binary mode for stdin/stdout in minigzip.c for OS/2
+- don't even use signed char in inflate (not portable enough)
+- fix inflate memory leak for segmented architectures
+
+Changes in 0.92 (3 May 95)
+- don't assume that char is signed (problem on SGI)
+- Clear bit buffer when starting a stored block
+- no memcpy on Pyramid
+- suppressed inftest.c
+- optimized fill_window, put longest_match inline for gcc
+- optimized inflate on stored blocks.
+- untabify all sources to simplify patches
+
+Changes in 0.91 (2 May 95)
+- Default MEM_LEVEL is 8 (not 9 for Unix) as documented in zlib.h
+- Document the memory requirements in zconf.h
+- added "make install"
+- fix sync search logic in inflateSync
+- deflate(Z_FULL_FLUSH) now works even if output buffer too short
+- after inflateSync, don't scare people with just "lo world"
+- added support for DJGPP
+
+Changes in 0.9 (1 May 95)
+- don't assume that zalloc clears the allocated memory (the TurboC bug
+ was Mark's bug after all :)
+- let again gzread copy uncompressed data unchanged (was working in 0.71)
+- deflate(Z_FULL_FLUSH), inflateReset and inflateSync are now fully implemented
+- added a test of inflateSync in example.c
+- moved MAX_WBITS to zconf.h because users might want to change that.
+- document explicitly that zalloc(64K) on MSDOS must return a normalized
+ pointer (zero offset)
+- added Makefiles for Microsoft C, Turbo C, Borland C++
+- faster crc32()
+
+Changes in 0.8 (29 April 95)
+- added fast inflate (inffast.c)
+- deflate(Z_FINISH) now returns Z_STREAM_END when done. Warning: this
+ is incompatible with previous versions of zlib which returned Z_OK.
+- work around a TurboC compiler bug (bad code for b << 0, see infutil.h)
+ (actually that was not a compiler bug, see 0.81 above)
+- gzread no longer reads one extra byte in certain cases
+- In gzio destroy(), don't reference a freed structure
+- avoid many warnings for MSDOS
+- avoid the ERROR symbol which is used by MS Windows
+
+Changes in 0.71 (14 April 95)
+- Fixed more MSDOS compilation problems :( There is still a bug with
+ TurboC large model.
+
+Changes in 0.7 (14 April 95)
+- Added full inflate support.
+- Simplified the crc32() interface. The pre- and post-conditioning
+ (one's complement) is now done inside crc32(). WARNING: this is
+ incompatible with previous versions; see zlib.h for the new usage.
+
+Changes in 0.61 (12 April 95)
+- workaround for a bug in TurboC. example and minigzip now work on MSDOS.
+
+Changes in 0.6 (11 April 95)
+- added minigzip.c
+- added gzdopen to reopen a file descriptor as gzFile
+- added transparent reading of non-gziped files in gzread.
+- fixed bug in gzread (don't read crc as data)
+- fixed bug in destroy (gzio.c) (don't return Z_STREAM_END for gzclose).
+- don't allocate big arrays in the stack (for MSDOS)
+- fix some MSDOS compilation problems
+
+Changes in 0.5:
+- do real compression in deflate.c. Z_PARTIAL_FLUSH is supported but
+ not yet Z_FULL_FLUSH.
+- support decompression but only in a single step (forced Z_FINISH)
+- added opaque object for zalloc and zfree.
+- added deflateReset and inflateReset
+- added a variable zlib_version for consistency checking.
+- renamed the 'filter' parameter of deflateInit2 as 'strategy'.
+ Added Z_FILTERED and Z_HUFFMAN_ONLY constants.
+
+Changes in 0.4:
+- avoid "zip" everywhere, use zlib instead of ziplib.
+- suppress Z_BLOCK_FLUSH, interpret Z_PARTIAL_FLUSH as block flush
+ if compression method == 8.
+- added adler32 and crc32
+- renamed deflateOptions as deflateInit2, call one or the other but not both
+- added the method parameter for deflateInit2.
+- added inflateInit2
+- simplied considerably deflateInit and inflateInit by not supporting
+ user-provided history buffer. This is supported only in deflateInit2
+ and inflateInit2.
+
+Changes in 0.3:
+- prefix all macro names with Z_
+- use Z_FINISH instead of deflateEnd to finish compression.
+- added Z_HUFFMAN_ONLY
+- added gzerror()
diff --git a/lib/libz/Makefile b/lib/libz/Makefile
new file mode 100644
index 0000000..cba7339
--- /dev/null
+++ b/lib/libz/Makefile
@@ -0,0 +1,30 @@
+# $OpenBSD: Makefile,v 1.20 2016/09/14 06:26:03 natano Exp $
+
+LIB= z
+HDRS= zconf.h zlib.h
+SRCS= adler32.c compress.c crc32.c deflate.c gzio.c infback.c \
+ inffast.c inflate.c inftrees.c trees.c uncompr.c zutil.c
+MAN= compress.3
+CFLAGS+=-DHAVE_STRERROR -DHAVE_MEMCPY -DHAS_vsnprintf -DHAS_snprintf
+
+PC_FILES=zlib.pc
+CLEANFILES+=${PC_FILES}
+
+includes:
+ @cd ${.CURDIR}; for i in $(HDRS); do \
+ j="cmp -s $$i ${DESTDIR}/usr/include/$$i || \
+ ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m 444 \
+ $$i ${DESTDIR}/usr/include"; \
+ echo $$j; \
+ eval "$$j"; \
+ done
+
+all: ${PC_FILES}
+${PC_FILES}: zlib.h
+ /bin/sh ${.CURDIR}/generate_pkgconfig.sh -c ${.CURDIR} -o ${.OBJDIR}
+
+beforeinstall:
+ ${INSTALL} ${INSTALL_COPY} -o root -g ${SHAREGRP} \
+ -m ${SHAREMODE} ${.OBJDIR}/${PC_FILES} ${DESTDIR}/usr/lib/pkgconfig/
+
+.include <bsd.lib.mk>
diff --git a/lib/libz/README b/lib/libz/README
new file mode 100644
index 0000000..758cc50
--- /dev/null
+++ b/lib/libz/README
@@ -0,0 +1,125 @@
+ZLIB DATA COMPRESSION LIBRARY
+
+zlib 1.2.3 is a general purpose data compression library. All the code is
+thread safe. The data format used by the zlib library is described by RFCs
+(Request for Comments) 1950 to 1952 in the files
+http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format)
+and rfc1952.txt (gzip format). These documents are also available in other
+formats from ftp://ftp.uu.net/graphics/png/documents/zlib/zdoc-index.html
+
+All functions of the compression library are documented in the file zlib.h
+(volunteer to write man pages welcome, contact zlib@gzip.org). A usage example
+of the library is given in the file example.c which also tests that the library
+is working correctly. Another example is given in the file minigzip.c. The
+compression library itself is composed of all source files except example.c and
+minigzip.c.
+
+To compile all files and run the test program, follow the instructions given at
+the top of Makefile. In short "make test; make install" should work for most
+machines. For Unix: "./configure; make test; make install". For MSDOS, use one
+of the special makefiles such as Makefile.msc. For VMS, use make_vms.com.
+
+Questions about zlib should be sent to <zlib@gzip.org>, or to Gilles Vollant
+<info@winimage.com> for the Windows DLL version. The zlib home page is
+http://www.zlib.org or http://www.gzip.org/zlib/ Before reporting a problem,
+please check this site to verify that you have the latest version of zlib;
+otherwise get the latest version and check whether the problem still exists or
+not.
+
+PLEASE read the zlib FAQ http://www.gzip.org/zlib/zlib_faq.html before asking
+for help.
+
+Mark Nelson <markn@ieee.org> wrote an article about zlib for the Jan. 1997
+issue of Dr. Dobb's Journal; a copy of the article is available in
+http://dogma.net/markn/articles/zlibtool/zlibtool.htm
+
+The changes made in version 1.2.3 are documented in the file ChangeLog.
+
+Unsupported third party contributions are provided in directory "contrib".
+
+A Java implementation of zlib is available in the Java Development Kit
+http://java.sun.com/j2se/1.4.2/docs/api/java/util/zip/package-summary.html
+See the zlib home page http://www.zlib.org for details.
+
+A Perl interface to zlib written by Paul Marquess <pmqs@cpan.org> is in the
+CPAN (Comprehensive Perl Archive Network) sites
+http://www.cpan.org/modules/by-module/Compress/
+
+A Python interface to zlib written by A.M. Kuchling <amk@amk.ca> is
+available in Python 1.5 and later versions, see
+http://www.python.org/doc/lib/module-zlib.html
+
+A zlib binding for TCL written by Andreas Kupries <a.kupries@westend.com> is
+availlable at http://www.oche.de/~akupries/soft/trf/trf_zip.html
+
+An experimental package to read and write files in .zip format, written on top
+of zlib by Gilles Vollant <info@winimage.com>, is available in the
+contrib/minizip directory of zlib.
+
+
+Notes for some targets:
+
+- For Windows DLL versions, please see win32/DLL_FAQ.txt
+
+- For 64-bit Irix, deflate.c must be compiled without any optimization. With
+ -O, one libpng test fails. The test works in 32 bit mode (with the -n32
+ compiler flag). The compiler bug has been reported to SGI.
+
+- zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works
+ when compiled with cc.
+
+- On Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 is
+ necessary to get gzprintf working correctly. This is done by configure.
+
+- zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with
+ other compilers. Use "make test" to check your compiler.
+
+- gzdopen is not supported on RISCOS, BEOS and by some Mac compilers.
+
+- For PalmOs, see http://palmzlib.sourceforge.net/
+
+- When building a shared, i.e. dynamic library on Mac OS X, the library must be
+ installed before testing (do "make install" before "make test"), since the
+ library location is specified in the library.
+
+
+Acknowledgments:
+
+ The deflate format used by zlib was defined by Phil Katz. The deflate
+ and zlib specifications were written by L. Peter Deutsch. Thanks to all the
+ people who reported problems and suggested various improvements in zlib;
+ they are too numerous to cite here.
+
+Copyright notice:
+
+ (C) 1995-2004 Jean-loup Gailly and Mark Adler
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+
+ Jean-loup Gailly Mark Adler
+ jloup@gzip.org madler@alumni.caltech.edu
+
+If you use the zlib library in a product, we would appreciate *not*
+receiving lengthy legal documents to sign. The sources are provided
+for free but without warranty of any kind. The library has been
+entirely written by Jean-loup Gailly and Mark Adler; it does not
+include third-party code.
+
+If you redistribute modified sources, we would appreciate that you include
+in the file ChangeLog history information documenting your changes. Please
+read the FAQ for more information on the distribution of modified source
+versions.
diff --git a/lib/libz/adler32.c b/lib/libz/adler32.c
new file mode 100644
index 0000000..932094f
--- /dev/null
+++ b/lib/libz/adler32.c
@@ -0,0 +1,148 @@
+/* $OpenBSD: adler32.c,v 1.6 2005/07/20 15:56:40 millert Exp $ */
+/* adler32.c -- compute the Adler-32 checksum of a data stream
+ * Copyright (C) 1995-2004 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#define ZLIB_INTERNAL
+#include "zlib.h"
+
+#define BASE 65521UL /* largest prime smaller than 65536 */
+#define NMAX 5552
+/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
+
+#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
+#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
+#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
+#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
+#define DO16(buf) DO8(buf,0); DO8(buf,8);
+
+/* use NO_DIVIDE if your processor does not do division in hardware */
+#ifdef NO_DIVIDE
+# define MOD(a) \
+ do { \
+ if (a >= (BASE << 16)) a -= (BASE << 16); \
+ if (a >= (BASE << 15)) a -= (BASE << 15); \
+ if (a >= (BASE << 14)) a -= (BASE << 14); \
+ if (a >= (BASE << 13)) a -= (BASE << 13); \
+ if (a >= (BASE << 12)) a -= (BASE << 12); \
+ if (a >= (BASE << 11)) a -= (BASE << 11); \
+ if (a >= (BASE << 10)) a -= (BASE << 10); \
+ if (a >= (BASE << 9)) a -= (BASE << 9); \
+ if (a >= (BASE << 8)) a -= (BASE << 8); \
+ if (a >= (BASE << 7)) a -= (BASE << 7); \
+ if (a >= (BASE << 6)) a -= (BASE << 6); \
+ if (a >= (BASE << 5)) a -= (BASE << 5); \
+ if (a >= (BASE << 4)) a -= (BASE << 4); \
+ if (a >= (BASE << 3)) a -= (BASE << 3); \
+ if (a >= (BASE << 2)) a -= (BASE << 2); \
+ if (a >= (BASE << 1)) a -= (BASE << 1); \
+ if (a >= BASE) a -= BASE; \
+ } while (0)
+# define MOD4(a) \
+ do { \
+ if (a >= (BASE << 4)) a -= (BASE << 4); \
+ if (a >= (BASE << 3)) a -= (BASE << 3); \
+ if (a >= (BASE << 2)) a -= (BASE << 2); \
+ if (a >= (BASE << 1)) a -= (BASE << 1); \
+ if (a >= BASE) a -= BASE; \
+ } while (0)
+#else
+# define MOD(a) a %= BASE
+# define MOD4(a) a %= BASE
+#endif
+
+/* ========================================================================= */
+uLong ZEXPORT adler32(adler, buf, len)
+ uLong adler;
+ const Bytef *buf;
+ uInt len;
+{
+ unsigned long sum2;
+ unsigned n;
+
+ /* split Adler-32 into component sums */
+ sum2 = (adler >> 16) & 0xffff;
+ adler &= 0xffff;
+
+ /* in case user likes doing a byte at a time, keep it fast */
+ if (len == 1) {
+ adler += buf[0];
+ if (adler >= BASE)
+ adler -= BASE;
+ sum2 += adler;
+ if (sum2 >= BASE)
+ sum2 -= BASE;
+ return adler | (sum2 << 16);
+ }
+
+ /* initial Adler-32 value (deferred check for len == 1 speed) */
+ if (buf == Z_NULL)
+ return 1L;
+
+ /* in case short lengths are provided, keep it somewhat fast */
+ if (len < 16) {
+ while (len--) {
+ adler += *buf++;
+ sum2 += adler;
+ }
+ if (adler >= BASE)
+ adler -= BASE;
+ MOD4(sum2); /* only added so many BASE's */
+ return adler | (sum2 << 16);
+ }
+
+ /* do length NMAX blocks -- requires just one modulo operation */
+ while (len >= NMAX) {
+ len -= NMAX;
+ n = NMAX / 16; /* NMAX is divisible by 16 */
+ do {
+ DO16(buf); /* 16 sums unrolled */
+ buf += 16;
+ } while (--n);
+ MOD(adler);
+ MOD(sum2);
+ }
+
+ /* do remaining bytes (less than NMAX, still just one modulo) */
+ if (len) { /* avoid modulos if none remaining */
+ while (len >= 16) {
+ len -= 16;
+ DO16(buf);
+ buf += 16;
+ }
+ while (len--) {
+ adler += *buf++;
+ sum2 += adler;
+ }
+ MOD(adler);
+ MOD(sum2);
+ }
+
+ /* return recombined sums */
+ return adler | (sum2 << 16);
+}
+
+/* ========================================================================= */
+uLong ZEXPORT adler32_combine(adler1, adler2, len2)
+ uLong adler1;
+ uLong adler2;
+ z_off_t len2;
+{
+ unsigned long sum1;
+ unsigned long sum2;
+ unsigned rem;
+
+ /* the derivation of this formula is left as an exercise for the reader */
+ rem = (unsigned)(len2 % BASE);
+ sum1 = adler1 & 0xffff;
+ sum2 = rem * sum1;
+ MOD(sum2);
+ sum1 += (adler2 & 0xffff) + BASE - 1;
+ sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
+ if (sum1 > BASE) sum1 -= BASE;
+ if (sum1 > BASE) sum1 -= BASE;
+ if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
+ if (sum2 > BASE) sum2 -= BASE;
+ return sum1 | (sum2 << 16);
+}
diff --git a/lib/libz/algorithm.doc b/lib/libz/algorithm.doc
new file mode 100644
index 0000000..b022dde
--- /dev/null
+++ b/lib/libz/algorithm.doc
@@ -0,0 +1,209 @@
+1. Compression algorithm (deflate)
+
+The deflation algorithm used by gzip (also zip and zlib) is a variation of
+LZ77 (Lempel-Ziv 1977, see reference below). It finds duplicated strings in
+the input data. The second occurrence of a string is replaced by a
+pointer to the previous string, in the form of a pair (distance,
+length). Distances are limited to 32K bytes, and lengths are limited
+to 258 bytes. When a string does not occur anywhere in the previous
+32K bytes, it is emitted as a sequence of literal bytes. (In this
+description, `string' must be taken as an arbitrary sequence of bytes,
+and is not restricted to printable characters.)
+
+Literals or match lengths are compressed with one Huffman tree, and
+match distances are compressed with another tree. The trees are stored
+in a compact form at the start of each block. The blocks can have any
+size (except that the compressed data for one block must fit in
+available memory). A block is terminated when deflate() determines that
+it would be useful to start another block with fresh trees. (This is
+somewhat similar to the behavior of LZW-based _compress_.)
+
+Duplicated strings are found using a hash table. All input strings of
+length 3 are inserted in the hash table. A hash index is computed for
+the next 3 bytes. If the hash chain for this index is not empty, all
+strings in the chain are compared with the current input string, and
+the longest match is selected.
+
+The hash chains are searched starting with the most recent strings, to
+favor small distances and thus take advantage of the Huffman encoding.
+The hash chains are singly linked. There are no deletions from the
+hash chains, the algorithm simply discards matches that are too old.
+
+To avoid a worst-case situation, very long hash chains are arbitrarily
+truncated at a certain length, determined by a runtime option (level
+parameter of deflateInit). So deflate() does not always find the longest
+possible match but generally finds a match which is long enough.
+
+deflate() also defers the selection of matches with a lazy evaluation
+mechanism. After a match of length N has been found, deflate() searches for
+a longer match at the next input byte. If a longer match is found, the
+previous match is truncated to a length of one (thus producing a single
+literal byte) and the process of lazy evaluation begins again. Otherwise,
+the original match is kept, and the next match search is attempted only N
+steps later.
+
+The lazy match evaluation is also subject to a runtime parameter. If
+the current match is long enough, deflate() reduces the search for a longer
+match, thus speeding up the whole process. If compression ratio is more
+important than speed, deflate() attempts a complete second search even if
+the first match is already long enough.
+
+The lazy match evaluation is not performed for the fastest compression
+modes (level parameter 1 to 3). For these fast modes, new strings
+are inserted in the hash table only when no match was found, or
+when the match is not too long. This degrades the compression ratio
+but saves time since there are both fewer insertions and fewer searches.
+
+
+2. Decompression algorithm (inflate)
+
+2.1 Introduction
+
+The key question is how to represent a Huffman code (or any prefix code) so
+that you can decode fast. The most important characteristic is that shorter
+codes are much more common than longer codes, so pay attention to decoding the
+short codes fast, and let the long codes take longer to decode.
+
+inflate() sets up a first level table that covers some number of bits of
+input less than the length of longest code. It gets that many bits from the
+stream, and looks it up in the table. The table will tell if the next
+code is that many bits or less and how many, and if it is, it will tell
+the value, else it will point to the next level table for which inflate()
+grabs more bits and tries to decode a longer code.
+
+How many bits to make the first lookup is a tradeoff between the time it
+takes to decode and the time it takes to build the table. If building the
+table took no time (and if you had infinite memory), then there would only
+be a first level table to cover all the way to the longest code. However,
+building the table ends up taking a lot longer for more bits since short
+codes are replicated many times in such a table. What inflate() does is
+simply to make the number of bits in the first table a variable, and then
+to set that variable for the maximum speed.
+
+For inflate, which has 286 possible codes for the literal/length tree, the size
+of the first table is nine bits. Also the distance trees have 30 possible
+values, and the size of the first table is six bits. Note that for each of
+those cases, the table ended up one bit longer than the ``average'' code
+length, i.e. the code length of an approximately flat code which would be a
+little more than eight bits for 286 symbols and a little less than five bits
+for 30 symbols.
+
+
+2.2 More details on the inflate table lookup
+
+Ok, you want to know what this cleverly obfuscated inflate tree actually
+looks like. You are correct that it's not a Huffman tree. It is simply a
+lookup table for the first, let's say, nine bits of a Huffman symbol. The
+symbol could be as short as one bit or as long as 15 bits. If a particular
+symbol is shorter than nine bits, then that symbol's translation is duplicated
+in all those entries that start with that symbol's bits. For example, if the
+symbol is four bits, then it's duplicated 32 times in a nine-bit table. If a
+symbol is nine bits long, it appears in the table once.
+
+If the symbol is longer than nine bits, then that entry in the table points
+to another similar table for the remaining bits. Again, there are duplicated
+entries as needed. The idea is that most of the time the symbol will be short
+and there will only be one table look up. (That's whole idea behind data
+compression in the first place.) For the less frequent long symbols, there
+will be two lookups. If you had a compression method with really long
+symbols, you could have as many levels of lookups as is efficient. For
+inflate, two is enough.
+
+So a table entry either points to another table (in which case nine bits in
+the above example are gobbled), or it contains the translation for the symbol
+and the number of bits to gobble. Then you start again with the next
+ungobbled bit.
+
+You may wonder: why not just have one lookup table for how ever many bits the
+longest symbol is? The reason is that if you do that, you end up spending
+more time filling in duplicate symbol entries than you do actually decoding.
+At least for deflate's output that generates new trees every several 10's of
+kbytes. You can imagine that filling in a 2^15 entry table for a 15-bit code
+would take too long if you're only decoding several thousand symbols. At the
+other extreme, you could make a new table for every bit in the code. In fact,
+that's essentially a Huffman tree. But then you spend two much time
+traversing the tree while decoding, even for short symbols.
+
+So the number of bits for the first lookup table is a trade of the time to
+fill out the table vs. the time spent looking at the second level and above of
+the table.
+
+Here is an example, scaled down:
+
+The code being decoded, with 10 symbols, from 1 to 6 bits long:
+
+A: 0
+B: 10
+C: 1100
+D: 11010
+E: 11011
+F: 11100
+G: 11101
+H: 11110
+I: 111110
+J: 111111
+
+Let's make the first table three bits long (eight entries):
+
+000: A,1
+001: A,1
+010: A,1
+011: A,1
+100: B,2
+101: B,2
+110: -> table X (gobble 3 bits)
+111: -> table Y (gobble 3 bits)
+
+Each entry is what the bits decode as and how many bits that is, i.e. how
+many bits to gobble. Or the entry points to another table, with the number of
+bits to gobble implicit in the size of the table.
+
+Table X is two bits long since the longest code starting with 110 is five bits
+long:
+
+00: C,1
+01: C,1
+10: D,2
+11: E,2
+
+Table Y is three bits long since the longest code starting with 111 is six
+bits long:
+
+000: F,2
+001: F,2
+010: G,2
+011: G,2
+100: H,2
+101: H,2
+110: I,3
+111: J,3
+
+So what we have here are three tables with a total of 20 entries that had to
+be constructed. That's compared to 64 entries for a single table. Or
+compared to 16 entries for a Huffman tree (six two entry tables and one four
+entry table). Assuming that the code ideally represents the probability of
+the symbols, it takes on the average 1.25 lookups per symbol. That's compared
+to one lookup for the single table, or 1.66 lookups per symbol for the
+Huffman tree.
+
+There, I think that gives you a picture of what's going on. For inflate, the
+meaning of a particular symbol is often more than just a letter. It can be a
+byte (a "literal"), or it can be either a length or a distance which
+indicates a base value and a number of bits to fetch after the code that is
+added to the base value. Or it might be the special end-of-block code. The
+data structures created in inftrees.c try to encode all that information
+compactly in the tables.
+
+
+Jean-loup Gailly Mark Adler
+jloup@gzip.org madler@alumni.caltech.edu
+
+
+References:
+
+[LZ77] Ziv J., Lempel A., ``A Universal Algorithm for Sequential Data
+Compression,'' IEEE Transactions on Information Theory, Vol. 23, No. 3,
+pp. 337-343.
+
+``DEFLATE Compressed Data Format Specification'' available in
+http://www.ietf.org/rfc/rfc1951.txt
diff --git a/lib/libz/compress.3 b/lib/libz/compress.3
new file mode 100644
index 0000000..cfac921
--- /dev/null
+++ b/lib/libz/compress.3
@@ -0,0 +1,2810 @@
+.\" $OpenBSD: compress.3,v 1.19 2018/03/16 16:58:26 schwarze Exp $
+.\"
+.\" Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
+.\"
+.\" This software is provided 'as-is', without any express or implied
+.\" warranty. In no event will the authors be held liable for any damages
+.\" arising from the use of this software.
+.\"
+.\" Permission is granted to anyone to use this software for any purpose,
+.\" including commercial applications, and to alter it and redistribute it
+.\" freely, subject to the following restrictions:
+.\"
+.\" The origin of this software must not be misrepresented; you must not
+.\" claim that you wrote the original software. If you use this software
+.\" in a product, an acknowledgment in the product documentation would be
+.\" appreciated but is not required.
+.\" Altered source versions must be plainly marked as such, and must not be
+.\" misrepresented as being the original software.
+.\" This notice may not be removed or altered from any source distribution.
+.\"
+.\" Converted to mdoc format for the OpenBSD project
+.\" by Jason McIntyre <jmc@openbsd.org>
+.\"
+.\" This page corresponds to zlib version 1.2.3
+.\"
+.Dd $Mdocdate: March 16 2018 $
+.Dt COMPRESS 3
+.Os
+.Sh NAME
+.Nm compress ,
+.Nm zlibVersion ,
+.Nm deflateInit ,
+.Nm deflate ,
+.Nm deflateEnd ,
+.Nm inflateInit ,
+.Nm inflate ,
+.Nm inflateEnd ,
+.Nm deflateInit2 ,
+.Nm deflateSetDictionary ,
+.Nm deflateCopy ,
+.Nm deflateReset ,
+.Nm deflateParams ,
+.Nm deflateTune ,
+.Nm deflateBound ,
+.Nm deflatePrime ,
+.Nm deflateSetHeader ,
+.Nm inflateInit2 ,
+.Nm inflateSetDictionary ,
+.Nm inflateSync ,
+.Nm inflateCopy ,
+.Nm inflateReset ,
+.Nm inflatePrime ,
+.Nm inflateGetHeader ,
+.Nm inflateBackInit ,
+.Nm inflateBack ,
+.Nm inflateBackEnd ,
+.Nm zlibCompileFlags ,
+.Nm compress2 ,
+.Nm compressBound ,
+.Nm uncompress ,
+.Nm gzopen ,
+.Nm gzdopen ,
+.Nm gzsetparams ,
+.Nm gzread ,
+.Nm gzwrite ,
+.Nm gzprintf ,
+.Nm gzputs ,
+.Nm gzgets ,
+.Nm gzputc ,
+.Nm gzgetc ,
+.Nm gzungetc ,
+.Nm gzflush ,
+.Nm gzseek ,
+.Nm gzrewind ,
+.Nm gztell ,
+.Nm gzeof ,
+.Nm gzdirect ,
+.Nm gzclose ,
+.Nm gzerror ,
+.Nm gzclearerr ,
+.Nm adler32 ,
+.Nm adler32_combine ,
+.Nm crc32 ,
+.Nm crc32_combine
+.Nd zlib general purpose compression library
+.Sh SYNOPSIS
+.In zlib.h
+.Pp
+Basic functions
+.Pp
+.Ft const char *
+.Fn zlibVersion "void"
+.Ft int
+.Fn deflateInit "z_streamp strm" "int level"
+.Ft int
+.Fn deflate "z_streamp strm" "int flush"
+.Ft int
+.Fn deflateEnd "z_streamp strm"
+.Ft int
+.Fn inflateInit "z_streamp strm"
+.Ft int
+.Fn inflate "z_streamp strm" "int flush"
+.Ft int
+.Fn inflateEnd "z_streamp strm"
+.Pp
+Advanced functions
+.Pp
+.Ft int
+.Fn deflateInit2 "z_streamp strm" "int level" "int method" "int windowBits" "int memLevel" "int strategy"
+.Ft int
+.Fn deflateSetDictionary "z_streamp strm" "const Bytef *dictionary" "uInt dictLength"
+.Ft int
+.Fn deflateCopy "z_streamp dest" "z_streamp source"
+.Ft int
+.Fn deflateReset "z_streamp strm"
+.Ft int
+.Fn deflateParams "z_streamp strm" "int level" "int strategy"
+.Ft int
+.Fn deflateTune "z_streamp strm" "int good_length" "int max_lazy" "int nice_length" "int max_chain"
+.Ft uLong
+.Fn deflateBound "z_streamp strm" "uLong sourceLen"
+.Ft int
+.Fn deflatePrime "z_streamp strm" "int bits" "int value"
+.Ft int
+.Fn deflateSetHeader "z_streamp strm" "gz_headerp head"
+.Ft int
+.Fn inflateInit2 "z_streamp strm" "int windowBits"
+.Ft int
+.Fn inflateSetDictionary "z_streamp strm" "const Bytef *dictionary" "uInt dictLength"
+.Ft int
+.Fn inflateSync "z_streamp strm"
+.Ft int
+.Fn inflateCopy "z_streamp dst" "z_streamp source"
+.Ft int
+.Fn inflateReset "z_streamp strm"
+.Ft int
+.Fn inflatePrime "z_streamp strm" "int bits" "int value"
+.Ft int
+.Fn inflateGetHeader "z_streamp strm" "gz_headerp head"
+.Ft int
+.Fn inflateBackInit "z_stream *strm" "int windowBits" "unsigned char FAR *window"
+.Ft int
+.Fn inflateBack "z_stream *strm" "in_func in" "void FAR *in_desc" "out_func out" "void FAR *out_desc"
+.Ft int
+.Fn inflateBackEnd "z_stream *strm"
+.Ft uLong
+.Fn zlibCompileFlags "void"
+.Pp
+Utility functions
+.Pp
+.Fd typedef voidp gzFile;
+.Pp
+.Ft int
+.Fn compress "Bytef *dest" "uLongf *destLen" "const Bytef *source" "uLong sourceLen"
+.Ft int
+.Fn compress2 "Bytef *dest" "uLongf *destLen" "const Bytef *source" "uLong sourceLen" "int level"
+.Ft uLong
+.Fn compressBound "uLong sourceLen"
+.Ft int
+.Fn uncompress "Bytef *dest" "uLongf *destLen" "const Bytef *source" "uLong sourceLen"
+.Ft gzFile
+.Fn gzopen "const char *path" "const char *mode"
+.Ft gzFile
+.Fn gzdopen "int fd" "const char *mode"
+.Ft int
+.Fn gzsetparams "gzFile file" "int level" "int strategy"
+.Ft int
+.Fn gzread "gzFile file" "voidp buf" "unsigned len"
+.Ft int
+.Fn gzwrite "gzFile file" "voidpc buf" "unsigned len"
+.Ft int
+.Fn gzprintf "gzFile file" "const char *format" "..."
+.Ft int
+.Fn gzputs "gzFile file" "const char *s"
+.Ft char *
+.Fn gzgets "gzFile file" "char *buf" "int len"
+.Ft int
+.Fn gzputc "gzFile file" "int c"
+.Ft int
+.Fn gzgetc "gzFile file"
+.Ft int
+.Fn gzungetc "int c" "gzFile file"
+.Ft int
+.Fn gzflush "gzFile file" "int flush"
+.Ft z_off_t
+.Fn gzseek "gzFile file" "z_off_t offset" "int whence"
+.Ft int
+.Fn gzrewind "gzFile file"
+.Ft z_off_t
+.Fn gztell "gzFile file"
+.Ft int
+.Fn gzeof "gzFile file"
+.Ft int
+.Fn gzdirect "gzFile file"
+.Ft int
+.Fn gzclose "gzFile file"
+.Ft const char *
+.Fn gzerror "gzFile file" "int *errnum"
+.Ft void
+.Fn gzclearerr "gzFile file"
+.Pp
+Checksum functions
+.Pp
+.Ft uLong
+.Fn adler32 "uLong adler" "const Bytef *buf" "uInt len"
+.Ft uLong
+.Fn adler32_combine "uLong adler1" "uLong adler2" "z_off_t len2"
+.Ft uLong
+.Fn crc32 "uLong crc" "const Bytef *buf" "uInt len"
+.Ft uLong
+.Fn crc32_combine "uLong crc1" "uLong crc2" "z_off_t len2"
+.Sh DESCRIPTION
+This manual page describes the
+.Nm zlib
+general purpose compression library, version 1.2.3.
+.Pp
+The
+.Nm zlib
+compression library provides in-memory compression and decompression functions,
+including integrity checks of the uncompressed data.
+This version of the library supports only one compression method
+.Pq deflation
+but other algorithms will be added later and will have the same
+stream interface.
+.Pp
+Compression can be done in a single step if the buffers are large enough
+.Pq for example if an input file is mmap'ed ,
+or can be done by repeated calls of the compression function.
+In the latter case, the application must provide more input
+and/or consume the output
+.Pq providing more output space
+before each call.
+.Pp
+The compressed data format used by default by the in-memory functions is the
+.Nm zlib
+format, which is a zlib wrapper documented in RFC 1950,
+wrapped around a deflate stream, which is itself documented in RFC 1951.
+.Pp
+The library also supports reading and writing files in
+.Xr gzip 1
+.Pq .gz
+format with an interface similar to that of
+.Xr stdio 3
+using the functions that start with
+.Qq gz .
+The gzip format is different from the zlib format.
+gzip is a gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
+This library can optionally read and write gzip streams in memory as well.
+.Pp
+The zlib format was designed to be compact and fast for use in memory
+and on communications channels.
+The gzip format was designed for single-file compression on file systems,
+has a larger header than zlib to maintain directory information,
+and uses a different, slower, check method than zlib.
+.Pp
+The library does not install any signal handler.
+The decoder checks the consistency of the compressed data,
+so the library should never crash even in case of corrupted input.
+.Pp
+The functions within the library are divided into the following sections:
+.Pp
+.Bl -dash -offset indent -compact
+.It
+Basic functions
+.It
+Advanced functions
+.It
+Utility functions
+.It
+Checksum functions
+.El
+.Sh BASIC FUNCTIONS
+.Bl -tag -width Ds
+.It Xo
+.Fa const char *
+.Fn zlibVersion "void" ;
+.Xc
+.Pp
+The application can compare
+.Fn zlibVersion
+and
+.Dv ZLIB_VERSION
+for consistency.
+If the first character differs, the library code actually used is
+not compatible with the
+.In zlib.h
+header file used by the application.
+This check is automatically made by
+.Fn deflateInit
+and
+.Fn inflateInit .
+.It Xo
+.Fa int
+.Fn deflateInit "z_streamp strm" "int level" ;
+.Xc
+.Pp
+The
+.Fn deflateInit
+function initializes the internal stream state for compression.
+The fields
+.Fa zalloc ,
+.Fa zfree ,
+and
+.Fa opaque
+must be initialized before by the caller.
+If
+.Fa zalloc
+and
+.Fa zfree
+are set to
+.Dv Z_NULL ,
+.Fn deflateInit
+updates them to use default allocation functions.
+.Pp
+The compression level must be
+.Dv Z_DEFAULT_COMPRESSION ,
+or between 0 and 9:
+1 gives best speed, 9 gives best compression, 0 gives no compression at all
+(the input data is simply copied a block at a time).
+.Pp
+.Dv Z_DEFAULT_COMPRESSION
+requests a default compromise between speed and compression
+.Pq currently equivalent to level 6 .
+.Pp
+.Fn deflateInit
+returns
+.Dv Z_OK
+if successful,
+.Dv Z_MEM_ERROR
+if there was not enough memory,
+.Dv Z_STREAM_ERROR
+if level is not a valid compression level,
+.Dv Z_VERSION_ERROR
+if the
+.Nm zlib
+library version
+.Pq zlib_version
+is incompatible with the version assumed by the caller
+.Pq ZLIB_VERSION .
+.Fa msg
+is set to null if there is no error message.
+.Fn deflateInit
+does not perform any compression: this will be done by
+.Fn deflate .
+.It Xo
+.Fa int
+.Fn deflate "z_streamp strm" "int flush" ;
+.Xc
+.Pp
+.Fn deflate
+compresses as much data as possible, and stops when the input
+buffer becomes empty or the output buffer becomes full.
+It may introduce some output latency
+.Pq reading input without producing any output
+except when forced to flush.
+.Pp
+The detailed semantics are as follows.
+.Fn deflate
+performs one or both of the following actions:
+.Pp
+Compress more input starting at
+.Fa next_in
+and update
+.Fa next_in
+and
+.Fa avail_in
+accordingly.
+If not all input can be processed
+(because there is not enough room in the output buffer),
+.Fa next_in
+and
+.Fa avail_in
+are updated and processing will resume at this point for the next call to
+.Fn deflate .
+.Pp
+Provide more output starting at
+.Fa next_out
+and update
+.Fa next_out
+and
+.Fa avail_out
+accordingly.
+This action is forced if the parameter
+.Fa flush
+is non-zero.
+Forcing
+.Fa flush
+frequently degrades the compression ratio,
+so this parameter should be set only when necessary
+.Pq in interactive applications .
+Some output may be provided even if
+.Fa flush
+is not set.
+.Pp
+Before the call to
+.Fn deflate ,
+the application should ensure that at least
+one of the actions is possible, by providing more input and/or consuming
+more output, and updating
+.Fa avail_in
+or
+.Fa avail_out
+accordingly;
+.Fa avail_out
+should never be zero before the call.
+The application can consume the compressed output when it wants,
+for example when the output buffer is full
+.Pq avail_out == 0 ,
+or after each call to
+.Fn deflate .
+If
+.Fn deflate
+returns
+.Dv Z_OK
+and with zero
+.Fa avail_out ,
+it must be called again after making room in the
+output buffer because there might be more output pending.
+.Pp
+Normally the parameter
+.Fa flush
+is set to
+.Dv Z_NO_FLUSH ,
+which allows
+.Fn deflate
+to decide how much data to accumulate before producing output,
+in order to maximise compression.
+.Pp
+If the parameter
+.Fa flush
+is set to
+.Dv Z_SYNC_FLUSH ,
+all pending output is flushed to the output buffer and the output
+is aligned on a byte boundary, so that the decompressor can get all
+input data available so far.
+(In particular,
+.Fa avail_in
+is zero after the call if enough output space
+has been provided before the call.)
+Flushing may degrade compression for some compression algorithms
+and so it should be used only when necessary.
+.Pp
+If
+.Fa flush
+is set to
+.Dv Z_FULL_FLUSH ,
+all output is flushed as with
+.Dv Z_SYNC_FLUSH ,
+and the compression state is reset so that decompression can restart from this
+point if previous compressed data has been damaged or if random access
+is desired.
+Using
+.Dv Z_FULL_FLUSH
+too often can seriously degrade compression.
+.Pp
+If
+.Fn deflate
+returns with avail_out == 0, this function must be called again
+with the same value of the flush parameter and more output space
+(updated
+.Fa avail_out ) ,
+until the flush is complete
+.Pf ( Fn deflate
+returns with non-zero
+.Fa avail_out ) .
+In the case of a
+.Dv Z_FULL_FLUSH
+or a
+.Dv Z_SYNC_FLUSH ,
+make sure that
+.Fa avail_out
+is greater than six to avoid repeated flush markers due to avail_out == 0
+on return.
+.Pp
+If the parameter
+.Fa flush
+is set to
+.Dv Z_FINISH ,
+pending input is processed, pending output is flushed and
+.Fn deflate
+returns with
+.Dv Z_STREAM_END
+if there was enough output space; if
+.Fn deflate
+returns with
+.Dv Z_OK ,
+this function must be called again with
+.Dv Z_FINISH
+and more output space
+(updated
+.Fa avail_out
+but no more input data, until it returns with
+.Dv Z_STREAM_END
+or an error.
+After
+.Fn deflate
+has returned
+.Dv Z_STREAM_END ,
+the only possible operations on the stream are
+.Fn deflateReset
+or
+.Fn deflateEnd .
+.Pp
+.Dv Z_FINISH
+can be used immediately after
+.Fn deflateInit
+if all the compression is to be done in a single step.
+In this case,
+.Fa avail_out
+must be at least the value returned by
+.Fn deflateBound
+.Pq see below .
+If
+.Fn deflate
+does not return
+.Dv Z_STREAM_END ,
+then it must be called again as described above.
+.Pp
+.Fn deflate
+sets strm->adler to the Adler-32 checksum of all input read so far
+(that is,
+.Fa total_in
+bytes).
+.Pp
+.Fn deflate
+may update strm->data_type
+if it can make a good guess about the input data type
+.Pq Z_BINARY or Z_TEXT .
+If in doubt, the data is considered binary.
+This field is only for information purposes and does not affect
+the compression algorithm in any manner.
+.Pp
+.Fn deflate
+returns
+.Dv Z_OK
+if some progress has been made
+.Pq more input processed or more output produced ,
+.Dv Z_STREAM_END
+if all input has been consumed and all output has been produced
+(only when
+.Fa flush
+is set to
+.Dv Z_FINISH ) ,
+.Dv Z_STREAM_ERROR
+if the stream state was inconsistent
+(for example, if
+.Fa next_in
+or
+.Fa next_out
+was
+.Dv NULL ) ,
+.Dv Z_BUF_ERROR
+if no progress is possible
+(for example,
+.Fa avail_in
+or
+.Fa avail_out
+was zero).
+Note that
+.Dv Z_BUF_ERROR
+is not fatal, and
+.Fn deflate
+can be called again with more input and more output space
+to continue processing.
+.It Xo
+.Fa int
+.Fn deflateEnd "z_streamp strm" ;
+.Xc
+.Pp
+All dynamically allocated data structures for this stream are freed.
+This function discards any unprocessed input and does not flush any
+pending output.
+.Pp
+.Fn deflateEnd
+returns
+.Dv Z_OK
+if successful,
+.Dv Z_STREAM_ERROR
+if the stream state was inconsistent,
+.Dv Z_DATA_ERROR
+if the stream was freed prematurely
+.Pq some input or output was discarded .
+In the error case,
+.Fa msg
+may be set but then points to a static string
+.Pq which must not be deallocated .
+.It Xo
+.Fa int
+.Fn inflateInit "z_streamp strm" ;
+.Xc
+The
+.Fn inflateInit
+function initializes the internal stream state for decompression.
+The fields
+.Fa next_in ,
+.Fa avail_in ,
+.Fa zalloc ,
+.Fa zfree ,
+and
+.Fa opaque
+must be initialized before by the caller.
+If
+.Fa next_in
+is not
+.Dv Z_NULL
+and
+.Fa avail_in
+is large enough
+.Pq the exact value depends on the compression method ,
+.Fn inflateInit
+determines the compression method from the
+.Nm zlib
+header and allocates all data structures accordingly;
+otherwise the allocation will be deferred to the first call to
+.Fn inflate .
+If
+.Fa zalloc
+and
+.Fa zfree
+are set to
+.Dv Z_NULL ,
+.Fn inflateInit
+updates them to use default allocation functions.
+.Pp
+.Fn inflateInit
+returns
+.Dv Z_OK
+if successful,
+.Dv Z_MEM_ERROR
+if there was not enough memory,
+.Dv Z_VERSION_ERROR
+if the
+.Nm zlib
+library version is incompatible with the version assumed by the caller.
+.Fa msg
+is set to null if there is no error message.
+.Fn inflateInit
+does not perform any decompression apart from reading the
+.Nm zlib
+header if present: this will be done by
+.Fn inflate .
+(So
+.Fa next_in
+and
+.Fa avail_in
+may be modified,
+but
+.Fa next_out
+and
+.Fa avail_out
+are unchanged.)
+.It Xo
+.Fa int
+.Fn inflate "z_streamp strm" "int flush" ;
+.Xc
+.Fn inflate
+decompresses as much data as possible, and stops when the input
+buffer becomes empty or the output buffer becomes full.
+It may introduce some output latency
+.Pq reading input without producing any output
+except when forced to flush.
+.Pp
+The detailed semantics are as follows.
+.Fn inflate
+performs one or both of the following actions:
+.Pp
+Decompress more input starting at
+.Fa next_in
+and update
+.Fa next_in
+and
+.Fa avail_in
+accordingly.
+If not all input can be processed
+(because there is not enough room in the output buffer),
+.Fa next_in
+is updated and processing will resume at this point for the next call to
+.Fn inflate .
+.Pp
+Provide more output starting at
+.Fa next_out
+and update
+.Fa next_out
+and
+.Fa avail_out
+accordingly.
+.Fn inflate
+provides as much output as possible,
+until there is no more input data or no more space in the output buffer
+.Pq see below about the flush parameter .
+.Pp
+Before the call to
+.Fn inflate ,
+the application should ensure that at least one of the actions is possible,
+by providing more input and/or consuming more output,
+and updating the next_* and avail_* values accordingly.
+The application can consume the uncompressed output when it wants,
+for example when the output buffer is full (avail_out == 0),
+or after each call to
+.Fn inflate .
+If
+.Fn inflate
+returns
+.Dv Z_OK
+and with zero
+.Fa avail_out ,
+it must be called again after making room
+in the output buffer because there might be more output pending.
+.Pp
+The
+.Fa flush
+parameter of
+.Fn inflate
+can be
+.Dv Z_NO_FLUSH , Z_SYNC_FLUSH , Z_FINISH ,
+or
+.Dv Z_BLOCK .
+.Dv Z_SYNC_FLUSH
+requests that
+.Fn inflate
+flush as much output as possible to the output buffer.
+.Dv Z_BLOCK
+requests that
+.Fn inflate
+stop if and when it gets to the next deflate block boundary.
+When decoding the zlib or gzip format, this will cause
+.Fn inflate
+to return immediately after the header and before the first block.
+When doing a raw inflate,
+.Fn inflate
+will go ahead and process the first block,
+and will return when it gets to the end of that block,
+or when it runs out of data.
+.Pp
+The
+.Dv Z_BLOCK
+option assists in appending to or combining deflate streams.
+Also to assist in this, on return
+.Fn inflate
+will set strm->data_type to the number of unused bits in the last byte
+taken from strm->next_in, plus 64 if
+.Fn inflate
+is currently decoding the last block in the deflate stream, plus 128 if
+.Fn inflate
+returned immediately after decoding an end-of-block code or decoding
+the complete header up to just before the first byte of the deflate stream.
+The end-of-block will not be indicated until all of the uncompressed data
+from that block has been written to strm->next_out.
+The number of unused bits may in general be greater than seven,
+except when bit 7 of data_type is set,
+in which case the number of unused bits will be less than eight.
+.Pp
+.Fn inflate
+should normally be called until it returns
+.Dv Z_STREAM_END
+or an error.
+However if all decompression is to be performed in a single step
+.Pq a single call to inflate ,
+the parameter
+.Fa flush
+should be set to
+.Dv Z_FINISH .
+In this case all pending input is processed and all pending output is flushed;
+.Fa avail_out
+must be large enough to hold all the uncompressed data.
+(The size of the uncompressed data may have been saved
+by the compressor for this purpose.)
+The next operation on this stream must be
+.Fn inflateEnd
+to deallocate the decompression state.
+The use of
+.Dv Z_FINISH
+is never required, but can be used to inform
+.Fn inflate
+that a faster approach may be used for the single
+.Fn inflate
+call.
+.Pp
+In this implementation,
+.Fn inflate
+always flushes as much output as possible to the output buffer,
+and always uses the faster approach on the first call.
+So the only effect of the
+.Fa flush
+parameter in this implementation is on the return value of
+.Fn inflate ,
+as noted below, or when it returns early because
+.Dv Z_BLOCK
+is used.
+.Pp
+If a preset dictionary is needed after this call (see
+.Fn inflateSetDictionary
+below),
+.Fn inflate
+sets strm->adler to the Adler-32 checksum of the dictionary
+chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
+strm->adler to the Adler-32 checksum of all output produced so far
+(that is,
+.Fa total_out
+bytes) and returns
+.Dv Z_OK , Z_STREAM_END
+or an error code as described below.
+At the end of the stream,
+.Fn inflate
+checks that its computed Adler-32 checksum is equal to that saved by
+the compressor and returns
+.Dv Z_STREAM_END
+only if the checksum is correct.
+.Pp
+.Fn inflate
+will decompress and check either zlib-wrapped or gzip-wrapped deflate data.
+The header type is detected automatically.
+Any information contained in the gzip header is not retained,
+so applications that need that information should instead use raw inflate; see
+.Fn inflateInit2
+below, or
+.Fn inflateBack
+and perform their own processing of the gzip header and trailer.
+.Pp
+.Fn inflate
+returns
+.Dv Z_OK
+if some progress has been made
+.Pq more input processed or more output produced ,
+.Dv Z_STREAM_END
+if the end of the compressed data has been reached and all uncompressed output
+has been produced,
+.Dv Z_NEED_DICT
+if a preset dictionary is needed at this point,
+.Dv Z_DATA_ERROR
+if the input data was corrupted (input stream not conforming to the
+.Nm zlib
+format or incorrect check value),
+.Dv Z_STREAM_ERROR
+if the stream structure was inconsistent
+(for example, if
+.Fa next_in
+or
+.Fa next_out
+was
+.Dv NULL ) ,
+.Dv Z_MEM_ERROR
+if there was not enough memory,
+.Dv Z_BUF_ERROR
+if no progress is possible or if there was not enough room in the output buffer
+when
+.Dv Z_FINISH
+is used.
+Note that
+.Dv Z_BUF_ERROR
+is not fatal, and
+.Fn inflate
+can be called again with more input and more output space
+to continue compressing.
+If
+.Dv Z_DATA_ERROR
+is returned, the application may then call
+.Fn inflateSync
+to look for a good compression block if a partial recovery
+of the data is desired.
+.It Xo
+.Fa int
+.Fn inflateEnd "z_streamp strm" ;
+.Xc
+All dynamically allocated data structures for this stream are freed.
+This function discards any unprocessed input and does not flush any
+pending output.
+.Pp
+.Fn inflateEnd
+returns
+.Dv Z_OK
+if successful, or
+.Dv Z_STREAM_ERROR
+if the stream state was inconsistent.
+In the error case,
+.Fa msg
+may be set but then points to a static string
+.Pq which must not be deallocated .
+.El
+.Sh ADVANCED FUNCTIONS
+The following functions are needed only in some special applications.
+.Bl -tag -width Ds
+.It Xo
+.Fa int
+.Fn deflateInit2 "z_streamp strm" "int level" "int method" "int windowBits" "int memLevel" "int strategy" ;
+.Xc
+.Pp
+This is another version of
+.Fn deflateInit
+with more compression options.
+The fields
+.Fa next_in ,
+.Fa zalloc ,
+.Fa zfree ,
+and
+.Fa opaque
+must be initialized before by the caller.
+.Pp
+The
+.Fa method
+parameter is the compression method.
+It must be
+.Dv Z_DEFLATED
+in this version of the library.
+.Pp
+The
+.Fa windowBits
+parameter is the base two logarithm of the window size
+.Pq the size of the history buffer .
+It should be in the range 8..15 for this version of the library.
+Larger values of this parameter result in better compression
+at the expense of memory usage.
+The default value is 15 if
+.Fn deflateInit
+is used instead.
+.Pp
+.Fa windowBits
+can also be -8..-15 for raw deflate.
+In this case, -windowBits determines the window size.
+.Fn deflate
+will then generate raw deflate data with no zlib header or trailer,
+and will not compute an Adler-32 check value.
+.Pp
+.Fa windowBits
+can also be greater than 15 for optional gzip encoding.
+Add 16 to
+.Fa windowBits
+to write a simple gzip header and trailer around the
+compressed data instead of a zlib wrapper.
+The gzip header will have no file name, no extra data, no comment,
+no modification time
+.Pq set to zero ,
+no header crc, and the operating system will be set to 255
+.Pq unknown .
+If a gzip stream is being written,
+strm->adler is a crc32 instead of an adler32.
+.Pp
+The
+.Fa memLevel
+parameter specifies how much memory should be allocated
+for the internal compression state.
+memLevel=1 uses minimum memory but is slow and reduces compression ratio;
+memLevel=9 uses maximum memory for optimal speed.
+The default value is 8.
+See
+.In zconf.h
+for total memory usage as a function of
+.Fa windowBits
+and
+.Fa memLevel .
+.Pp
+The
+.Fa strategy
+parameter is used to tune the compression algorithm.
+Use the value
+.Dv Z_DEFAULT_STRATEGY
+for normal data;
+.Dv Z_FILTERED
+for data produced by a filter
+.Pq or predictor ;
+.Dv Z_HUFFMAN_ONLY
+to force Huffman encoding only
+.Pq no string match ,
+or
+.Dv Z_RLE
+to limit match distances to one
+.Pq run-length encoding .
+Filtered data consists mostly of small values with a
+somewhat random distribution.
+In this case, the compression algorithm is tuned to compress them better.
+The effect of
+.Dv Z_FILTERED
+is to force more Huffman coding and less string matching;
+it is somewhat intermediate between
+.Dv Z_DEFAULT
+and
+.Dv Z_HUFFMAN_ONLY .
+.Dv Z_RLE
+is designed to be almost as fast as
+.Dv Z_HUFFMAN_ONLY ,
+but gives better compression for PNG image data.
+The
+.Fa strategy
+parameter only affects the compression ratio but not the correctness of the
+compressed output, even if it is not set appropriately.
+.Dv Z_FIXED
+prevents the use of dynamic Huffman codes,
+allowing for a simpler decoder for special applications.
+.Pp
+.Fn deflateInit2
+returns
+.Dv Z_OK
+if successful,
+.Dv Z_MEM_ERROR
+if there was not enough memory,
+.Dv Z_STREAM_ERROR
+if a parameter is invalid
+.Pq such as an invalid method .
+.Fa msg
+is set to null if there is no error message.
+.Fn deflateInit2
+does not perform any compression: this will be done by
+.Fn deflate .
+.It Xo
+.Fa int
+.Fn deflateSetDictionary "z_streamp strm" "const Bytef *dictionary" "uInt dictLength" ;
+.Xc
+.Pp
+Initializes the compression dictionary from the given byte sequence
+without producing any compressed output.
+This function must be called immediately after
+.Fn deflateInit ,
+.Fn deflateInit2 ,
+or
+.Fn deflateReset ,
+before any call to
+.Fn deflate .
+The compressor and decompressor must use exactly the same dictionary
+(see
+.Fn inflateSetDictionary ) .
+.Pp
+The dictionary should consist of strings
+.Pq byte sequences
+that are likely to be encountered later in the data to be compressed,
+with the most commonly used strings preferably put towards
+the end of the dictionary.
+Using a dictionary is most useful when the data to be compressed is short
+and can be predicted with good accuracy;
+the data can then be compressed better than with the default empty dictionary.
+.Pp
+Depending on the size of the compression data structures selected by
+.Fn deflateInit
+or
+.Fn deflateInit2 ,
+a part of the dictionary may in effect be discarded,
+for example if the dictionary is larger than the window size in
+.Fn deflate
+or
+.Fn deflate2 .
+Thus the strings most likely to be useful should be
+put at the end of the dictionary, not at the front.
+In addition, the current implementation of
+.Fn deflate
+will use at most the window size minus 262 bytes of the provided dictionary.
+.Pp
+Upon return of this function, strm->adler is set to the Adler-32 value
+of the dictionary; the decompressor may later use this value to determine
+which dictionary has been used by the compressor.
+(The Adler-32 value applies to the whole dictionary even if only a subset
+of the dictionary is actually used by the compressor.)
+If a raw deflate was requested, then the Adler-32 value is not computed
+and strm->adler is not set.
+.Pp
+.Fn deflateSetDictionary
+returns
+.Dv Z_OK
+if successful,
+or
+.Dv Z_STREAM_ERROR
+if a parameter is invalid
+.Pq such as NULL dictionary
+or the stream state is inconsistent
+(for example if
+.Fn deflate
+has already been called for this stream or if the compression method is bsort).
+.Fn deflateSetDictionary
+does not perform any compression: this will be done by
+.Fn deflate .
+.It Xo
+.Fa int
+.Fn deflateCopy "z_streamp dest" "z_streamp source" ;
+.Xc
+.Pp
+The
+.Fn deflateCopy
+function sets the destination stream as a complete copy of the source stream.
+.Pp
+This function can be useful when several compression strategies will be
+tried, for example when there are several ways of pre-processing the input
+data with a filter.
+The streams that will be discarded should then be freed by calling
+.Fn deflateEnd .
+Note that
+.Fn deflateCopy
+duplicates the internal compression state which can be quite large,
+so this strategy is slow and can consume lots of memory.
+.Pp
+.Fn deflateCopy
+returns
+.Dv Z_OK
+if successful,
+.Dv Z_MEM_ERROR
+if there was not enough memory,
+.Dv Z_STREAM_ERROR
+if the source stream state was inconsistent
+(such as
+.Fa zalloc
+being NULL).
+.Fa msg
+is left unchanged in both source and destination.
+.It Xo
+.Fa int
+.Fn deflateReset "z_streamp strm" ;
+.Xc
+.Pp
+This function is equivalent to
+.Fn deflateEnd
+followed by
+.Fn deflateInit ,
+but does not free and reallocate all the internal compression state.
+The stream will keep the same compression level and any other attributes
+that may have been set by
+.Fn deflateInit2 .
+.Pp
+.Fn deflateReset
+returns
+.Dv Z_OK
+if successful, or
+.Dv Z_STREAM_ERROR
+if the source stream state was inconsistent
+(such as
+.Fa zalloc
+or
+.Fa state
+being NULL).
+.It Xo
+.Fa int
+.Fn deflateParams "z_streamp strm" "int level" "int strategy" ;
+.Xc
+.Pp
+The
+.Fn deflateParams
+function dynamically updates the compression level and compression strategy.
+The interpretation of level and strategy is as in
+.Fn deflateInit2 .
+This can be used to switch between compression and straight copy
+of the input data, or to switch to a different kind of input data
+requiring a different strategy.
+If the compression level is changed, the input available so far
+is compressed with the old level
+.Pq and may be flushed ;
+the new level will take effect only at the next call to
+.Fn deflate .
+.Pp
+Before the call to
+.Fn deflateParams ,
+the stream state must be set as for a call to
+.Fn deflate ,
+since the currently available input may have to be compressed and flushed.
+In particular, strm->avail_out must be non-zero.
+.Pp
+.Fn deflateParams
+returns
+.Dv Z_OK
+if successful,
+.Dv Z_STREAM_ERROR
+if the source stream state was inconsistent or if a parameter was invalid, or
+.Dv Z_BUF_ERROR
+if strm->avail_out was zero.
+.It Xo
+.Fa int
+.Fn deflateTune "z_streamp strm" "int good_length" "int max_lazy" "int nice_length" "int max_chain"
+.Xc
+.Pp
+Fine tune
+.Fn deflate Ns 's
+internal compression parameters.
+This should only be used by someone who understands the algorithm
+used by zlib's deflate for searching for the best matching string,
+and even then only by the most fanatic optimizer
+trying to squeeze out the last compressed bit for their specific input data.
+Read the
+.Pa deflate.c
+source code for the meaning of the
+.Fa max_lazy , good_length , nice_length ,
+and
+.Fa max_chain
+parameters.
+.Pp
+.Fn deflateTune
+can be called after
+.Fn deflateInit
+or
+.Fn deflateInit2 ,
+and returns
+.Dv Z_OK
+on success, or
+.Dv Z_STREAM_ERROR
+for an invalid deflate stream.
+.It Xo
+.Fa uLong
+.Fn deflateBound "z_streamp strm" "uLong sourceLen"
+.Xc
+.Pp
+.Fn deflateBound
+returns an upper bound on the compressed size after deflation of
+.Fa sourceLen
+bytes.
+It must be called after
+.Fn deflateInit
+or
+.Fn deflateInit2 .
+This would be used to allocate an output buffer for deflation in a single pass,
+and so would be called before
+.Fn deflate .
+.It Xo
+.Fa int
+.Fn deflatePrime "z_streamp strm" "int bits" "int value"
+.Xc
+.Pp
+.Fn deflatePrime
+inserts
+.Fa bits
+in the deflate output stream.
+The intent is that this function is used to start off the deflate output
+with the bits leftover from a previous deflate stream when appending to it.
+As such, this function can only be used for raw deflate,
+and must be used before the first
+.Fn deflate
+call after a
+.Fn deflateInit2
+or
+.Fn deflateReset .
+.Fa bits
+must be less than or equal to 16,
+and that many of the least significant bits of
+.Fa value
+will be inserted in the output.
+.Pp
+.Fn deflatePrime
+returns
+.Dv Z_OK
+if successful, or
+.Dv Z_STREAM_ERROR
+if the source stream state was inconsistent.
+.It Xo
+.Fa int
+.Fn deflateSetHeader "z_streamp strm" "gz_headerp head"
+.Xc
+.Pp
+.Fn deflateSetHeader
+provides gzip header information for when a gzip
+stream is requested by
+.Fn deflateInit2 .
+.Fn deflateSetHeader
+may be called after
+.Fn deflateInit2
+or
+.Fn deflateReset
+and before the first call of
+.Fn deflate .
+The text, time, os, extra field, name, and comment information
+in the provided gz_header structure are written to the gzip header
+(xflag is ignored \- the extra flags are set
+according to the compression level).
+The caller must assure that, if not
+.Dv Z_NULL ,
+.Fa name
+and
+.Fa comment
+are terminated with a zero byte,
+and that if
+.Fa extra
+is not
+.Dv Z_NULL ,
+that
+.Fa extra_len
+bytes are available there.
+If hcrc is true, a gzip header CRC is included.
+Note that the current versions of the command-line version of
+.Xr gzip 1
+do not support header CRCs, and will report that it is a
+.Dq multi-part gzip file
+and give up.
+.Pp
+If
+.Fn deflateSetHeader
+is not used, the default gzip header has text false,
+the time set to zero, and os set to 255, with no extra, name, or comment
+fields.
+The gzip header is returned to the default state by
+.Fn deflateReset .
+.Pp
+.Fn deflateSetHeader
+returns
+.Dv Z_OK
+if successful, or
+.Dv Z_STREAM_ERROR
+if the source stream state was inconsistent.
+.It Xo
+.Fa int
+.Fn inflateInit2 "z_streamp strm" "int windowBits" ;
+.Xc
+.Pp
+This is another version of
+.Fn inflateInit
+with an extra parameter.
+The fields
+.Fa next_in ,
+.Fa avail_in ,
+.Fa zalloc ,
+.Fa zfree ,
+and
+.Fa opaque
+must be initialized before by the caller.
+.Pp
+The
+.Fa windowBits
+parameter is the base two logarithm of the maximum window size
+.Pq the size of the history buffer .
+It should be in the range 8..15 for this version of the library.
+The default value is 15 if
+.Fn inflateInit
+is used instead.
+.Fa windowBits
+must be greater than or equal to the
+.Fa windowBits
+value provided to
+.Fn deflateInit2
+while compressing, or it must be equal to 15 if
+.Fn deflateInit2
+was not used.
+If a compressed stream with a larger window size is given as input,
+.Fn inflate
+will return with the error code
+.Dv Z_DATA_ERROR
+instead of trying to allocate a larger window.
+.Pp
+.Fa windowBits
+can also be -8..-15 for raw inflate.
+In this case, -windowBits determines the window size.
+.Fn inflate
+will then process raw deflate data, not looking for a zlib or gzip header,
+not generating a check value, and not looking for any check values
+for comparison at the end of the stream.
+This is for use with other formats that use the deflate compressed data format
+such as zip.
+Those formats provide their own check values.
+If a custom format is developed using the raw deflate format
+for compressed data, it is recommended that a check value such as an Adler-32
+or a crc32 be applied to the uncompressed data as is done in the zlib, gzip,
+and zip formats.
+For most applications, the zlib format should be used as is.
+Note that comments above on the use in
+.Fn deflateInit2
+applies to the magnitude of
+.Fa windowBits .
+.Pp
+.Fa windowBits
+can also be greater than 15 for optional gzip decoding.
+Add 32 to windowBits to enable zlib and gzip decoding with automatic header
+detection, or add 16 to decode only the gzip format
+(the zlib format will return a
+.Dv Z_DATA_ERROR ) .
+If a gzip stream is being decoded,
+strm->adler is a crc32 instead of an adler32.
+.Pp
+.Fn inflateInit2
+returns
+.Dv Z_OK
+if successful,
+.Dv Z_MEM_ERROR
+if there was not enough memory,
+.Dv Z_STREAM_ERROR
+if a parameter is invalid
+(such as a null strm).
+.Fa msg
+is set to null if there is no error message.
+.Fn inflateInit2
+does not perform any decompression apart from reading the
+.Nm zlib
+header if present: this will be done by
+.Fn inflate .
+(So
+.Fa next_in
+and
+.Fa avail_in
+may be modified, but
+.Fa next_out
+and
+.Fa avail_out
+are unchanged.)
+.It Xo
+.Fa int
+.Fn inflateSetDictionary "z_streamp strm" "const Bytef *dictionary" "uInt dictLength" ;
+.Xc
+.Pp
+Initializes the decompression dictionary from the given uncompressed byte
+sequence.
+This function must be called immediately after a call to
+.Fn inflate
+if that call returned
+.Dv Z_NEED_DICT .
+The dictionary chosen by the compressor can be determined from the
+Adler-32 value returned by that call to
+.Fn inflate .
+The compressor and decompressor must use exactly the same dictionary
+(see
+.Fn deflateSetDictionary ) .
+For raw inflate, this function can be called immediately after
+.Fn inflateInit2
+or
+.Fn inflateReset
+and before any call to
+.Fn inflate
+to set the dictionary.
+The application must ensure that the dictionary
+that was used for compression is provided.
+.Pp
+.Fn inflateSetDictionary
+returns
+.Dv Z_OK
+if successful,
+.Dv Z_STREAM_ERROR
+if a parameter is invalid
+.Pq such as NULL dictionary
+or the stream state is inconsistent,
+.Dv Z_DATA_ERROR
+if the given dictionary doesn't match the expected one
+.Pq incorrect Adler-32 value .
+.Fn inflateSetDictionary
+does not perform any decompression: this will be done by subsequent calls of
+.Fn inflate .
+.It Xo
+.Fa int
+.Fn inflateSync "z_streamp strm" ;
+.Xc
+.Pp
+Skips invalid compressed data until a full flush point
+(see above the description of
+.Fn deflate
+with
+.Dv Z_FULL_FLUSH )
+can be found, or until all available input is skipped.
+No output is provided.
+.Pp
+.Fn inflateSync
+returns
+.Dv Z_OK
+if a full flush point has been found,
+.Dv Z_BUF_ERROR
+if no more input was provided,
+.Dv Z_DATA_ERROR
+if no flush point has been found, or
+.Dv Z_STREAM_ERROR
+if the stream structure was inconsistent.
+In the success case, the application may save the current value of
+.Fa total_in
+which indicates where valid compressed data was found.
+In the error case, the application may repeatedly call
+.Fn inflateSync ,
+providing more input each time, until success or end of the input data.
+.It Xo
+.Fa int
+.Fn inflateCopy "z_streamp dest" "z_streamp source"
+.Xc
+.Pp
+Sets the destination stream as a complete copy of the source stream.
+.Pp
+This function can be useful when randomly accessing a large stream.
+The first pass through the stream can periodically record the inflate state,
+allowing restarting inflate at those points when randomly accessing the stream.
+.Pp
+.Fn inflateCopy
+returns
+.Dv Z_OK
+if success,
+.Dv Z_MEM_ERROR
+if there was not enough memory,
+.Dv Z_STREAM_ERROR
+if the source stream state was inconsistent
+(such as
+.Fa zalloc
+being NULL).
+.Fa msg
+is left unchanged in both
+.Fa source
+and
+.Fa dest .
+.It Xo
+.Fa int
+.Fn inflateReset "z_streamp strm" ;
+.Xc
+.Pp
+This function is equivalent to
+.Fn inflateEnd
+followed by
+.Fn inflateInit ,
+but does not free and reallocate all the internal decompression state.
+The stream will keep attributes that may have been set by
+.Fn inflateInit2 .
+.Pp
+.Fn inflateReset
+returns
+.Dv Z_OK
+if successful, or
+.Dv Z_STREAM_ERROR
+if the source stream state was inconsistent
+(such as
+.Fa zalloc
+or
+.Fa state
+being NULL).
+.It Xo
+.Fa int
+.Fn inflatePrime "z_stream strm" "int bits" "int value"
+.Xc
+.Pp
+This function inserts bits in the inflate input stream.
+The intent is that this function is used
+to start inflating at a bit position in the middle of a byte.
+The provided bits will be used before any bytes are used from
+.Fa next_in .
+This function should only be used with raw inflate,
+and should be used before the first
+.Fn inflate
+call after
+.Fn inflateInit2
+or
+.Fn inflateReset .
+.Fa bits
+must be less than or equal to 16,
+and that many of the least significant bits of value
+will be inserted in the input.
+.Pp
+.Fn inflatePrime
+returns
+.Dv Z_OK
+if successful, or
+.Dv Z_STREAM_ERROR
+if the source stream state was inconsistent.
+.It Xo
+.Fa int
+.Fn inflateGetHeader "z_streamp strm" "gz_headerp head"
+.Xc
+.Pp
+.Fn inflateGetHeader
+requests that gzip header information be stored in the
+provided gz_header structure.
+.Fn inflateGetHeader
+may be called after
+.Fn inflateInit2
+or
+.Fn inflateReset ,
+and before the first call of
+.Fn inflate .
+As
+.Fn inflate
+processes the gzip stream, head->done is zero until the header
+is completed, at which time head->done is set to one.
+If a zlib stream is being decoded,
+then head->done is set to \-1 to indicate that there will be
+no gzip header information forthcoming.
+Note that
+.Dv Z_BLOCK
+can be used to force
+.Fn inflate
+to return immediately after header processing is complete
+and before any actual data is decompressed.
+.Pp
+The text, time, xflags, and os fields are filled in with the gzip header
+contents.
+hcrc is set to true if there is a header CRC.
+(The header CRC was valid if done is set to one.)
+If extra is not
+.Dv Z_NULL ,
+then
+.Fa extra_max
+contains the maximum number of bytes to write to
+.Fa extra .
+Once done is true,
+.Fa extra_len
+contains the actual extra field length, and
+.Fa extra
+contains the extra field, or that field truncated if
+.Fa extra_max
+is less than
+.Fa extra_len .
+If name is not
+.Dv Z_NULL ,
+then up to
+.Fa name_max
+characters are written there,
+terminated with a zero unless the length is greater than
+.Fa name_max .
+If comment is not
+.Dv Z_NULL ,
+then up to
+.Fa comm_max
+characters are written there,
+terminated with a zero unless the length is greater than
+.Fa comm_max .
+When any of extra, name, or comment are not
+.Dv Z_NULL
+and the respective field is not present in the header,
+then that field is set to
+.Dv Z_NULL
+to signal its absence.
+This allows the use of
+.Fn deflateSetHeader
+with the returned structure to duplicate the header.
+However if those fields are set to allocated memory,
+then the application will need to save those pointers
+elsewhere so that they can be eventually freed.
+.Pp
+If
+.Fn inflateGetHeader
+is not used, then the header information is simply discarded.
+The header is always checked for validity,
+including the header CRC if present.
+.Fn inflateReset
+will reset the process to discard the header information.
+The application would need to call
+.Fn inflateGetHeader
+again to retrieve the header from the next gzip stream.
+.Pp
+.Fn inflateGetHeader
+returns
+.Dv Z_OK
+if successful,
+or
+.Dv Z_STREAM_ERROR
+if the source stream state was inconsistent.
+.It Xo
+.Fa int
+.Fn inflateBackInit "z_stream *strm" "int windowBits" "unsigned char FAR *window"
+.Xc
+.Pp
+Initialize the internal stream state for decompression using
+.Fn inflateBack
+calls.
+The fields
+.Fa zalloc , zfree
+and
+.Fa opaque
+in
+.Fa strm
+must be initialized before the call.
+If
+.Fa zalloc
+and
+.Fa zfree
+are
+.Dv Z_NULL ,
+then the default library-derived memory allocation routines are used.
+.Fa windowBits
+is the base two logarithm of the window size, in the range 8..15.
+.Fa window
+is a caller supplied buffer of that size.
+Except for special applications where it is assured that
+.Fn deflate
+was used with small window sizes,
+.Fa windowBits
+must be 15 and a 32K byte window must be supplied to be able to decompress
+general deflate streams.
+.Pp
+See
+.Fn inflateBack
+for the usage of these routines.
+.Pp
+.Fn inflateBackInit
+will return
+.Dv Z_OK
+on success,
+.Dv Z_STREAM_ERROR
+if any of the parameters are invalid,
+.Dv Z_MEM_ERROR
+if the internal state could not be allocated, or
+.Dv Z_VERSION_ERROR
+if the version of the library does not match the version of the header file.
+.It Xo
+.Fa int
+.Fn inflateBack "z_stream *strm" "in_func in" "void FAR *in_desc" "out_func out" "void FAR *out_desc"
+.Xc
+.Pp
+.Fn inflateBack
+does a raw inflate with a single call using a call-back
+interface for input and output.
+This is more efficient than
+.Fn inflate
+for file I/O applications in that it avoids copying between the output and the
+sliding window by simply making the window itself the output buffer.
+This function trusts the application to not change the output buffer passed by
+the output function, at least until
+.Fn inflateBack
+returns.
+.Pp
+.Fn inflateBackInit
+must be called first to allocate the internal state
+and to initialize the state with the user-provided window buffer.
+.Fn inflateBack
+may then be used multiple times to inflate a complete, raw
+deflate stream with each call.
+.Fn inflateBackEnd
+is then called to free the allocated state.
+.Pp
+A raw deflate stream is one with no zlib or gzip header or trailer.
+This routine would normally be used in a utility that reads zip or gzip
+files and writes out uncompressed files.
+The utility would decode the header and process the trailer on its own,
+hence this routine expects only the raw deflate stream to decompress.
+This is different from the normal behavior of
+.Fn inflate ,
+which expects either a zlib or gzip header and
+trailer around the deflate stream.
+.Pp
+.Fn inflateBack
+uses two subroutines supplied by the caller that are then called by
+.Fn inflateBack
+for input and output.
+.Fn inflateBack
+calls those routines until it reads a complete deflate stream and writes out
+all of the uncompressed data, or until it encounters an error.
+The function's parameters and return types are defined above in the
+in_func and out_func typedefs.
+.Fn inflateBack
+will call in(in_desc, &buf) which should return the
+number of bytes of provided input, and a pointer to that input in
+.Fa buf .
+If there is no input available,
+.Fn in
+must return zero
+\(em buf is ignored in that case \(em
+and
+.Fn inflateBack
+will return a buffer error.
+.Fn inflateBack
+will call out(out_desc, buf, len) to write the uncompressed data buf[0..len-1].
+.Fn out
+should return zero on success, or non-zero on failure.
+If
+.Fn out
+returns non-zero,
+.Fn inflateBack
+will return with an error.
+Neither
+.Fn in
+nor
+.Fn out
+are permitted to change the contents of the window provided to
+.Fn inflateBackInit ,
+which is also the buffer that
+.Fn out
+uses to write from.
+The length written by
+.Fn out
+will be at most the window size.
+Any non-zero amount of input may be provided by
+.Fn in .
+.Pp
+For convenience,
+.Fn inflateBack
+can be provided input on the first call by setting strm->next_in
+and strm->avail_in.
+If that input is exhausted, then
+.Fn in
+will be called.
+Therefore strm->next_in must be initialized before calling
+.Fn inflateBack .
+If strm->next_in is
+.Dv Z_NULL ,
+then
+.Fn in
+will be called immediately for input.
+If strm->next_in is not
+.Dv Z_NULL ,
+then strm->avail_in must also be initialized,
+and then if strm->avail_in is not zero,
+input will initially be taken from
+strm->next_in[0 .. strm->avail_in \- 1].
+.Pp
+The
+.Fa in_desc
+and
+.Fa out_desc
+parameters of
+.Fn inflateBack
+are passed as the first parameter of
+.Fn in
+and
+.Fn out
+respectively when they are called.
+These descriptors can be optionally used to pass any information that the
+caller-supplied
+.Fn in
+and
+.Fn out
+functions need to do their job.
+.Pp
+On return,
+.Fn inflateBack
+will set strm->next_in and strm->avail_in to pass back any unused input
+that was provided by the last
+.Fn in
+call.
+The return values of
+.Fn inflateBack
+can be
+.Dv Z_STREAM_END
+on success,
+.Dv Z_BUF_ERROR
+if
+.Fn in
+or
+.Fn out
+returned an error,
+.Dv Z_DATA_ERROR
+if there was a format error in the deflate stream
+(in which case strm->msg is set to indicate the nature of the error),
+or
+.Dv Z_STREAM_ERROR
+if the stream was not properly initialized.
+In the case of
+.Dv Z_BUF_ERROR ,
+an input or output error can be distinguished using strm->next_in which
+will be
+.Dv Z_NULL
+only if
+.Fn in
+returned an error.
+If strm->next is not
+.Dv Z_NULL ,
+then the
+.Dv Z_BUF_ERROR
+was due to
+.Fn out
+returning non-zero.
+.Po
+.Fn in
+will always be called before
+.Fn out ,
+so strm->next_in is assured to be defined if
+.Fn out
+returns non-zero.
+.Pc
+Note that
+.Fn inflateBack
+cannot return
+.Dv Z_OK .
+.It Xo
+.Fa int
+.Fn inflateBackEnd "z_stream *strm"
+.Xc
+.Pp
+All memory allocated by
+.Fn inflateBackInit
+is freed.
+.Pp
+.Fn inflateBackEnd
+returns
+.Dv Z_OK
+on success, or
+.Dv Z_STREAM_ERROR
+if the stream state was inconsistent.
+.It Xo
+.Fa uLong
+.Fn zlibCompileFlags "void"
+.Xc
+.Pp
+This function returns flags indicating compile-time options.
+.Pp
+Type sizes, two bits each:
+.Pp
+.Bl -tag -width Ds -offset indent -compact
+.It 00
+16 bits
+.It 01
+32 bits
+.It 10
+64 bits
+.It 11
+other:
+.Pp
+.Bl -tag -width Ds -offset indent -compact
+.It 1.0
+size of uInt
+.It 3.2
+size of uLong
+.It 5.4
+size of voidpf
+.Pq pointer
+.It 7.6
+size of z_off_t
+.El
+.El
+.Pp
+Compiler, assembler, and debug options:
+.Pp
+.Bl -tag -width Ds -offset indent -compact
+.It 8
+DEBUG
+.It 9
+ASMV or ASMINF \(em use ASM code
+.It 10
+ZLIB_WINAPI \(em exported functions use the WINAPI calling convention
+.It 11
+0
+.Pq reserved
+.El
+.Pp
+One-time table building
+.Pq smaller code, but not thread-safe if true :
+.Pp
+.Bl -tag -width Ds -offset indent -compact
+.It 12
+BUILDFIXED \(em build static block decoding tables when needed
+.It 13
+DYNAMIC_CRC_TABLE \(em build CRC calculation tables when needed
+.It 14,15
+0
+.Pq reserved
+.El
+.Pp
+Library content (indicates missing functionality):
+.Pp
+.Bl -tag -width Ds -offset indent -compact
+.It 16
+NO_GZCOMPRESS \(em gz* functions cannot compress
+.Pq to avoid linking deflate code when not needed
+.It 17
+NO_GZIP \(em deflate can't write gzip streams, and inflate can't detect
+and decode gzip streams
+.Pq to avoid linking CRC code
+.It 18-19
+0
+.Pq reserved
+.El
+.Pp
+Operation variations (changes in library functionality):
+.Pp
+.Bl -tag -width Ds -offset indent -compact
+.It 20
+PKZIP_BUG_WORKAROUND \(em slightly more permissive inflate
+.It 21
+FASTEST \(em deflate algorithm with only one, lowest compression level
+.It 22,23
+0
+.Pq reserved
+.El
+.Pp
+The sprintf variant used by gzprintf
+.Pq zero is best :
+.Pp
+.Bl -tag -width Ds -offset indent -compact
+.It 24
+0 = vs*, 1 = s* \(em 1 means limited to 20 arguments after the format
+.It 25
+0 = *nprintf, 1 = *printf \(em 1 means
+.Fn gzprintf
+not secure!
+.It 26
+0 = returns value, 1 = void \(em 1 means inferred string length returned
+.El
+.Pp
+Remainder:
+.Pp
+.Bl -tag -width Ds -offset indent -compact
+.It 27-31
+0
+.Pq reserved
+.El
+.El
+.Sh UTILITY FUNCTIONS
+The following utility functions are implemented on top of the
+basic stream-oriented functions.
+To simplify the interface,
+some default options are assumed (compression level and memory usage,
+standard memory allocation functions).
+The source code of these utility functions can easily be modified
+if you need special options.
+.Bl -tag -width Ds
+.It Xo
+.Fa int
+.Fn compress "Bytef *dest" "uLongf *destLen" "const Bytef *source" "uLong sourceLen" ;
+.Xc
+.Pp
+The
+.Fn compress
+function compresses the source buffer into the destination buffer.
+.Fa sourceLen
+is the byte length of the source buffer.
+Upon entry,
+.Fa destLen
+is the total size of the destination buffer,
+which must be at least the value returned by
+.Fn compressBound sourcelen .
+Upon exit,
+.Fa destLen
+is the actual size of the compressed buffer.
+This function can be used to compress a whole file at once if the
+input file is mmap'ed.
+.Pp
+.Fn compress
+returns
+.Dv Z_OK
+if successful,
+.Dv Z_MEM_ERROR
+if there was not enough memory, or
+.Dv Z_BUF_ERROR
+if there was not enough room in the output buffer.
+.It Xo
+.Fa int
+.Fn compress2 "Bytef *dest" "uLongf *destLen" "const Bytef *source" "uLong sourceLen" "int level" ;
+.Xc
+.Pp
+The
+.Fn compress2
+function compresses the source buffer into the destination buffer.
+The
+.Fa level
+parameter has the same meaning as in
+.Fn deflateInit .
+.Fa sourceLen
+is the byte length of the source buffer.
+Upon entry,
+.Fa destLen
+is the total size of the destination buffer,
+which must be at least the value returned by
+.Fn compressBound sourceLen .
+Upon exit,
+.Fa destLen
+is the actual size of the compressed buffer.
+.Pp
+.Fn compress2
+returns
+.Dv Z_OK
+if successful,
+.Dv Z_MEM_ERROR
+if there was not enough memory,
+.Dv Z_BUF_ERROR
+if there was not enough room in the output buffer, or
+.Dv Z_STREAM_ERROR
+if the level parameter is invalid.
+.It Xo
+.Fa int
+.Fn compressBound "uLong sourceLen"
+.Xc
+.Pp
+.Fn compressBound
+returns an upper bound on the compressed size after
+.Fn compress
+or
+.Fn compress2
+on
+.Fa sourceLen
+bytes.
+It would be used before a
+.Fn compress
+or
+.Fn compress2
+call to allocate the destination buffer.
+.It Xo
+.Fa int
+.Fn uncompress "Bytef *dest" "uLongf *destLen" "const Bytef *source" "uLong sourceLen" ;
+.Xc
+.Pp
+The
+.Fn uncompress
+function decompresses the source buffer into the destination buffer.
+.Fa sourceLen
+is the byte length of the source buffer.
+Upon entry,
+.Fa destLen
+is the total size of the destination buffer,
+which must be large enough to hold the entire uncompressed data.
+(The size of the uncompressed data must have been saved previously
+by the compressor and transmitted to the decompressor
+by some mechanism outside the scope of this compression library.)
+Upon exit,
+.Fa destLen
+is the actual size of the compressed buffer.
+This function can be used to decompress a whole file at once if the
+input file is mmap'ed.
+.Pp
+.Fn uncompress
+returns
+.Dv Z_OK
+if successful,
+.Dv Z_MEM_ERROR
+if there was not enough memory,
+.Dv Z_BUF_ERROR
+if there was not enough room in the output buffer, or
+.Dv Z_DATA_ERROR
+if the input data was corrupted or incomplete.
+.It Xo
+.Fa gzFile
+.Fn gzopen "const char *path" "const char *mode" ;
+.Xc
+.Pp
+The
+.Fn gzopen
+function opens a gzip
+.Pq .gz
+file for reading or writing.
+The mode parameter is as in
+.Xr fopen 3
+.Po
+.Qq rb
+or
+.Qq wb
+.Pc
+but can also include a compression level
+.Pq "wb9"
+or a strategy:
+.Sq f
+for filtered data, as in
+.Qq wb6f ;
+.Sq h
+for Huffman only compression, as in
+.Qq wb1h ,
+or
+.Sq R
+for run-length encoding as in
+.Qq wb1R .
+(See the description of
+.Fn deflateInit2
+for more information about the strategy parameter.)
+.Pp
+.Fn gzopen
+can be used to read a file which is not in gzip format;
+in this case
+.Fn gzread
+will directly read from the file without decompression.
+.Pp
+.Fn gzopen
+returns
+.Dv NULL
+if the file could not be opened or if there was
+insufficient memory to allocate the (de)compression state;
+errno can be checked to distinguish the two cases (if errno is zero, the
+.Nm zlib
+error is
+.Dv Z_MEM_ERROR ) .
+.It Xo
+.Fa gzFile
+.Fn gzdopen "int fd" "const char *mode" ;
+.Xc
+.Pp
+The
+.Fn gzdopen
+function associates a gzFile with the file descriptor
+.Fa fd .
+File descriptors are obtained from calls like
+.Xr open 2 ,
+.Xr dup 2 ,
+.Xr creat 3 ,
+.Xr pipe 2 ,
+or
+.Xr fileno 3
+(if the file has been previously opened with
+.Xr fopen 3 ) .
+The
+.Fa mode
+parameter is as in
+.Fn gzopen .
+.Pp
+The next call to
+.Fn gzclose
+on the returned gzFile will also close the file descriptor fd,
+just like fclose(fdopen(fd), mode) closes the file descriptor fd.
+If you want to keep fd open, use gzdopen(dup(fd), mode).
+.Pp
+.Fn gzdopen
+returns
+.Dv NULL
+if there was insufficient memory to allocate the (de)compression state.
+.It Xo
+.Fa int
+.Fn gzsetparams "gzFile file" "int level" "int strategy" ;
+.Xc
+.Pp
+The
+.Fn gzsetparams
+function dynamically updates the compression level or strategy.
+See the description of
+.Fn deflateInit2
+for the meaning of these parameters.
+.Pp
+.Fn gzsetparams
+returns
+.Dv Z_OK
+if successful, or
+.Dv Z_STREAM_ERROR
+if the file was not opened for writing.
+.It Xo
+.Fa int
+.Fn gzread "gzFile file" "voidp buf" "unsigned len" ;
+.Xc
+.Pp
+The
+.Fn gzread
+function reads the given number of uncompressed bytes from the compressed file.
+If the input file was not in gzip format,
+.Fn gzread
+copies the given number of bytes into the buffer.
+.Pp
+.Fn gzread
+returns the number of uncompressed bytes actually read
+(0 for end of file, \-1 for error).
+.It Xo
+.Fa int
+.Fn gzwrite "gzFile file" "voidpc buf" "unsigned len" ;
+.Xc
+.Pp
+The
+.Fn gzwrite
+function writes the given number of uncompressed bytes into the compressed file.
+.Fn gzwrite
+returns the number of uncompressed bytes actually written
+.Pq 0 in case of error .
+.It Xo
+.Fa int
+.Fn gzprintf "gzFile file" "const char *format" "..." ;
+.Xc
+.Pp
+The
+.Fn gzprintf
+function converts, formats, and writes the args to the compressed file
+under control of the format string, as in
+.Xr fprintf 3 .
+.Fn gzprintf
+returns the number of uncompressed bytes actually written
+.Pq 0 in case of error .
+The number of uncompressed bytes written is limited to 4095.
+The caller should make sure that this limit is not exceeded.
+If it is exceeded, then
+.Fn gzprintf
+will return an error
+.Pq 0
+with nothing written.
+In this case, there may also be a buffer overflow
+with unpredictable consequences, which is possible only if
+.Nm zlib
+was compiled with the insecure functions
+.Fn sprintf
+or
+.Fn vsprintf
+because the secure
+.Fn snprintf
+or
+.Fn vsnprintf
+functions were not available.
+.It Xo
+.Fa int
+.Fn gzputs "gzFile file" "const char *s" ;
+.Xc
+.Pp
+The
+.Fn gzputs
+function writes the given null-terminated string to the compressed file,
+excluding the terminating null character.
+.Pp
+.Fn gzputs
+returns the number of characters written, or \-1 in case of error.
+.It Xo
+.Fa char *
+.Fn gzgets "gzFile file" "char *buf" "int len" ;
+.Xc
+.Pp
+The
+.Fn gzgets
+function reads bytes from the compressed file until len\-1 characters are read,
+or a newline character is read and transferred to
+.Fa buf ,
+or an end-of-file condition is encountered.
+The string is then terminated with a null character.
+.Pp
+.Fn gzgets
+returns
+.Fa buf ,
+or
+.Dv Z_NULL
+in case of error.
+.It Xo
+.Fa int
+.Fn gzputc "gzFile file" "int c" ;
+.Xc
+.Pp
+The
+.Fn gzputc
+function writes
+.Fa c ,
+converted to an unsigned char, into the compressed file.
+.Fn gzputc
+returns the value that was written, or \-1 in case of error.
+.It Xo
+.Fa int
+.Fn gzgetc "gzFile file" ;
+.Xc
+.Pp
+The
+.Fn gzgetc
+function reads one byte from the compressed file.
+.Fn gzgetc
+returns this byte or \-1 in case of end of file or error.
+.It Xo
+.Fa int
+.Fn gzungetc "int c" "gzFile file"
+.Xc
+.Pp
+Push one character back onto the stream to be read again later.
+Only one character of push-back is allowed.
+.Fn gzungetc
+returns the character pushed, or \-1 on failure.
+.Fn gzungetc
+will fail if a character has been pushed but not read yet, or if
+.Fa c
+is \-1.
+The pushed character will be discarded if the stream is repositioned with
+.Fn gzseek
+or
+.Fn gzrewind .
+.It Xo
+.Fa int
+.Fn gzflush "gzFile file" "int flush" ;
+.Xc
+.Pp
+The
+.Fn gzflush
+function flushes all pending output into the compressed file.
+The parameter
+.Fa flush
+is as in the
+.Fn deflate
+function.
+The return value is the
+.Nm zlib
+error number (see function
+.Fn gzerror
+below).
+.Fn gzflush
+returns
+.Dv Z_OK
+if the flush parameter is
+.Dv Z_FINISH
+and all output could be flushed.
+.Pp
+.Fn gzflush
+should be called only when strictly necessary because it can
+degrade compression.
+.It Xo
+.Fa z_off_t
+.Fn gzseek "gzFile file" "z_off_t offset" "int whence" ;
+.Xc
+.Pp
+Sets the starting position for the next
+.Fn gzread
+or
+.Fn gzwrite
+on the given compressed file.
+The offset represents a number of bytes in the uncompressed data stream.
+The whence parameter is defined as in
+.Xr lseek 2 ;
+the value
+.Dv SEEK_END
+is not supported.
+.Pp
+If the file is opened for reading, this function is emulated but can be
+extremely slow.
+If the file is opened for writing, only forward seeks are supported;
+.Fn gzseek
+then compresses a sequence of zeroes up to the new starting position.
+.Pp
+.Fn gzseek
+returns the resulting offset location as measured in bytes from
+the beginning of the uncompressed stream, or \-1 in case of error,
+in particular if the file is opened for writing and the new starting position
+would be before the current position.
+.It Xo
+.Fa int
+.Fn gzrewind "gzFile file" ;
+.Xc
+.Pp
+The
+.Fn gzrewind
+function rewinds the given
+.Fa file .
+This function is supported only for reading.
+.Pp
+gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET).
+.It Xo
+.Fa z_off_t
+.Fn gztell "gzFile file" ;
+.Xc
+.Pp
+The
+.Fn gztell
+function returns the starting position for the next
+.Fn gzread
+or
+.Fn gzwrite
+on the given compressed file.
+This position represents a number of bytes in the uncompressed data stream.
+.Pp
+gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR).
+.It Xo
+.Fa int
+.Fn gzeof "gzFile file" ;
+.Xc
+.Pp
+The
+.Fn gzeof
+function returns 1 when
+.Dv EOF
+has previously been detected reading the given input stream, otherwise zero.
+.It Xo
+.Fa int
+.Fn gzdirect "gzFile file" ;
+.Xc
+.Pp
+The
+.Fn gzdirect
+function returns 1 if the file is being read directly
+without compression;
+otherwise it returns 0.
+.It Xo
+.Fa int
+.Fn gzclose "gzFile file" ;
+.Xc
+.Pp
+The
+.Fn gzclose
+function flushes all pending output if necessary, closes the compressed file
+and deallocates all the (de)compression state.
+The return value is the
+.Nm zlib
+error number (see function
+.Fn gzerror
+below).
+.It Xo
+.Fa const char *
+.Fn gzerror "gzFile file" "int *errnum" ;
+.Xc
+.Pp
+The
+.Fn gzerror
+function returns the error message for the last error which occurred on the
+given compressed
+.Fa file .
+.Fa errnum
+is set to the
+.Nm zlib
+error number.
+If an error occurred in the file system and not in the compression library,
+.Fa errnum
+is set to
+.Dv Z_ERRNO
+and the application may consult errno to get the exact error code.
+.It Xo
+.Fa void
+.Fn gzclearerr "gzFile file"
+.Xc
+Clears the error and end-of-file flags for
+.Fa file .
+This is analogous to the
+.Fn clearerr
+function in stdio.
+This is useful for continuing to read a gzip file
+that is being written concurrently.
+.El
+.Sh CHECKSUM FUNCTIONS
+These functions are not related to compression but are exported
+anyway because they might be useful in applications using the
+compression library.
+.Bl -tag -width Ds
+.It Xo
+.Fa uLong
+.Fn adler32 "uLong adler" "const Bytef *buf" "uInt len" ;
+.Xc
+The
+.Fn adler32
+function updates a running Adler-32 checksum with the bytes buf[0..len-1]
+and returns the updated checksum.
+If
+.Fa buf
+is
+.Dv NULL ,
+this function returns the required initial value for the checksum.
+.Pp
+An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
+much faster.
+Usage example:
+.Bd -unfilled -offset indent
+uLong adler = adler32(0L, Z_NULL, 0);
+
+while (read_buffer(buffer, length) != EOF) {
+adler = adler32(adler, buffer, length);
+}
+if (adler != original_adler) error();
+.Ed
+.It Xo
+.Fa uLong
+.Fn adler32_combine "uLong adler1" "uLong adler2" "z_off_t len2"
+.Xc
+.Pp
+The
+.Fn adler32_combine
+function combines two Adler-32 checksums into one.
+For two sequences of bytes, seq1 and seq2 with lengths len1 and len2,
+Adler-32 checksums are calculated for each, adler1 and adler2.
+.Fn adler32_combine
+returns the Adler-32 checksum of seq1 and seq2 concatenated,
+requiring only adler1, adler2, and len2.
+.It Xo
+.Fa uLong
+.Fn crc32 "uLong crc" "const Bytef *buf" "uInt len" ;
+.Xc
+.Pp
+The
+.Fn crc32
+function updates a running CRC-32 with the bytes buf[0..len-1]
+and returns the updated CRC-32.
+If
+.Fa buf
+is
+.Dv NULL ,
+this function returns the required initial value for the CRC.
+Pre- and post-conditioning
+.Pq one's complement
+is performed within this function so it shouldn't be done by the application.
+Usage example:
+.Bd -unfilled -offset indent
+uLong crc = crc32(0L, Z_NULL, 0);
+
+while (read_buffer(buffer, length) != EOF) {
+crc = crc32(crc, buffer, length);
+}
+if (crc != original_crc) error();
+.Ed
+.It Xo
+.Fa uLong
+.Fn crc32_combine "uLong crc1" "uLong crc2" "z_off_t len2"
+.Xc
+.Pp
+The
+.Fn crc32_combine
+function combines two CRC-32 check values into one.
+For two sequences of bytes,
+seq1 and seq2 with lengths len1 and len2,
+CRC-32 check values are calculated for each, crc1 and crc2.
+.Fn crc32_combine
+returns the CRC-32 check value of seq1 and seq2 concatenated,
+requiring only crc1, crc2, and len2.
+.El
+.Sh STRUCTURES
+.Bd -unfilled
+struct internal_state;
+
+typedef struct z_stream_s {
+ Bytef *next_in; /* next input byte */
+ uInt avail_in; /* number of bytes available at next_in */
+ off_t total_in; /* total nb of input bytes read so far */
+
+ Bytef *next_out; /* next output byte should be put there */
+ uInt avail_out; /* remaining free space at next_out */
+ off_t total_out; /* total nb of bytes output so far */
+
+ char *msg; /* last error message, NULL if no error */
+ struct internal_state FAR *state; /* not visible by applications */
+
+ alloc_func zalloc; /* used to allocate the internal state */
+ free_func zfree; /* used to free the internal state */
+ voidpf opaque; /* private data object passed to zalloc and zfree*/
+
+ int data_type; /* best guess about the data type: binary or text*/
+ uLong adler; /* adler32 value of the uncompressed data */
+ uLong reserved; /* reserved for future use */
+} z_stream;
+
+typedef z_stream FAR * z_streamp;
+.Ed
+.Bd -unfilled
+/*
+ gzip header information passed to and from zlib routines.
+ See RFC 1952 for more details on the meanings of these fields.
+*/
+typedef struct gz_header_s {
+ int text; /* true if compressed data believed to be text */
+ uLong time; /* modification time */
+ int xflags; /*extra flags (not used when writing a gzip file)*/
+ int os; /* operating system */
+ Bytef *extra; /* pointer to extra field or Z_NULL if none */
+ uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
+ uInt extra_max; /* space at extra (only when reading header) */
+ Bytef *name; /* pointer to zero-terminated file name or Z_NULL*/
+ uInt name_max; /* space at name (only when reading header) */
+ Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
+ uInt comm_max; /* space at comment (only when reading header) */
+ int hcrc; /* true if there was or will be a header crc */
+ int done; /* true when done reading gzip header (not used
+ when writing a gzip file) */
+} gz_header;
+
+typedef gz_header FAR *gz_headerp;
+.Ed
+.Pp
+The application must update
+.Fa next_in
+and
+.Fa avail_in
+when
+.Fa avail_in
+has dropped to zero.
+It must update
+.Fa next_out
+and
+.Fa avail_out
+when
+.Fa avail_out
+has dropped to zero.
+The application must initialize
+.Fa zalloc ,
+.Fa zfree ,
+and
+.Fa opaque
+before calling the init function.
+All other fields are set by the compression library
+and must not be updated by the application.
+.Pp
+The
+.Fa opaque
+value provided by the application will be passed as the first
+parameter for calls to
+.Fn zalloc
+and
+.Fn zfree .
+This can be useful for custom memory management.
+The compression library attaches no meaning to the
+.Fa opaque
+value.
+.Pp
+.Fa zalloc
+must return
+.Dv Z_NULL
+if there is not enough memory for the object.
+If
+.Nm zlib
+is used in a multi-threaded application,
+.Fa zalloc
+and
+.Fa zfree
+must be thread safe.
+.Pp
+On 16-bit systems, the functions
+.Fa zalloc
+and
+.Fa zfree
+must be able to allocate exactly 65536 bytes,
+but will not be required to allocate more than this if the symbol MAXSEG_64K
+is defined (see
+.In zconf.h ) .
+.Pp
+WARNING: On MSDOS, pointers returned by
+.Fa zalloc
+for objects of exactly 65536 bytes *must* have their offset normalized to zero.
+The default allocation function provided by this library ensures this (see
+.Pa zutil.c ) .
+To reduce memory requirements and avoid any allocation of 64K objects,
+at the expense of compression ratio,
+compile the library with -DMAX_WBITS=14 (see
+.In zconf.h ) .
+.Pp
+The fields
+.Fa total_in
+and
+.Fa total_out
+can be used for statistics or progress reports.
+After compression,
+.Fa total_in
+holds the total size of the uncompressed data and may be saved for use
+in the decompressor
+(particularly if the decompressor wants to decompress everything
+in a single step).
+.Sh CONSTANTS
+.Bd -unfilled
+#define Z_NO_FLUSH 0
+#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
+#define Z_SYNC_FLUSH 2
+#define Z_FULL_FLUSH 3
+#define Z_FINISH 4
+#define Z_BLOCK 5
+/* Allowed flush values; see deflate() and inflate() below for details */
+
+#define Z_OK 0
+#define Z_STREAM_END 1
+#define Z_NEED_DICT 2
+#define Z_ERRNO (-1)
+#define Z_STREAM_ERROR (-2)
+#define Z_DATA_ERROR (-3)
+#define Z_MEM_ERROR (-4)
+#define Z_BUF_ERROR (-5)
+#define Z_VERSION_ERROR (-6)
+/* Return codes for the compression/decompression functions.
+ * Negative values are errors,
+ * positive values are used for special but normal events.
+ */
+
+#define Z_NO_COMPRESSION 0
+#define Z_BEST_SPEED 1
+#define Z_BEST_COMPRESSION 9
+#define Z_DEFAULT_COMPRESSION (-1)
+/* compression levels */
+
+#define Z_FILTERED 1
+#define Z_HUFFMAN_ONLY 2
+#define Z_RLE 3
+#define Z_FIXED 4
+#define Z_DEFAULT_STRATEGY 0
+/* compression strategy; see deflateInit2() below for details */
+
+#define Z_BINARY 0
+#define Z_TEXT 1
+#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
+#define Z_UNKNOWN 2
+/* Possible values of the data_type field (though see inflate()) */
+
+#define Z_DEFLATED 8
+/* The deflate compression method
+ * (the only one supported in this version)
+*/
+
+#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
+
+#define zlib_version zlibVersion()
+/* for compatibility with versions < 1.0.2 */
+.Ed
+.Sh VARIOUS HACKS
+deflateInit and inflateInit are macros to allow checking the
+.Nm zlib
+version and the compiler's view of
+.Fa z_stream .
+.Bl -tag -width Ds
+.It Xo
+.Fa int
+.Fn deflateInit_ "z_stream strm" "int level" "const char *version" "int stream_size" ;
+.Xc
+.It Xo
+.Fa int
+.Fn inflateInit_ "z_stream strm" "const char *version" "int stream_size" ;
+.Xc
+.It Xo
+.Fa int
+.Fo deflateInit2_
+.Fa "z_stream strm"
+.Fa "int level"
+.Fa "int method"
+.Fa "int windowBits"
+.Fa "int memLevel"
+.Fa "int strategy"
+.Fa "const char *version"
+.Fa "int stream_size"
+.Fc
+.Xc
+.It Xo
+.Fa int
+.Fn inflateInit2_ "z_stream strm" "int windowBits" "const char *version" "int stream_size" ;
+.Xc
+.It Xo
+.Fa int
+.Fn inflateBackInit_ "z_stream *strm" "int windowBits" "unsigned char FAR *window" "const char *version" "int stream_size"
+.Xc
+.It Xo
+.Fa const char *
+.Fn zError "int err" ;
+.Xc
+.It Xo
+.Fa int
+.Fn inflateSyncPoint "z_streamp z" ;
+.Xc
+.It Xo
+.Fa const uLongf *
+.Fn "get_crc_table" "void" ;
+.Xc
+.El
+.Sh SEE ALSO
+.Xr compress 1 ,
+.Xr gzip 1
+.Sh STANDARDS
+.Rs
+.%A P. Deutsch
+.%A J-L. Gailly
+.%D May 1996
+.%R RFC 1950
+.%T ZLIB Compressed Data Format Specification version 3.3
+.Re
+.Pp
+.Rs
+.%A P. Deutsch
+.%D May 1996
+.%R RFC 1951
+.%T DEFLATE Compressed Data Format Specification version 1.3
+.Re
+.Pp
+.Rs
+.%A P. Deutsch
+.%D May 1996
+.%R RFC 1952
+.%T GZIP file format specification version 4.3
+.Re
+.Sh HISTORY
+This manual page is based on an HTML version of
+.In zlib.h
+converted by
+.An piaip Aq Mt piaip@csie.ntu.edu.tw
+and was converted to mdoc format by the
+.Ox
+project.
+.Sh AUTHORS
+.An Jean-loup Gailly Aq Mt jloup@gzip.org
+.An Mark Adler Aq Mt madler@alumni.caltech.edu
diff --git a/lib/libz/compress.c b/lib/libz/compress.c
new file mode 100644
index 0000000..f501874
--- /dev/null
+++ b/lib/libz/compress.c
@@ -0,0 +1,79 @@
+/* $OpenBSD: compress.c,v 1.6 2005/07/20 15:56:41 millert Exp $ */
+/* compress.c -- compress a memory buffer
+ * Copyright (C) 1995-2003 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+
+#define ZLIB_INTERNAL
+#include "zlib.h"
+
+/* ===========================================================================
+ Compresses the source buffer into the destination buffer. The level
+ parameter has the same meaning as in deflateInit. sourceLen is the byte
+ length of the source buffer. Upon entry, destLen is the total size of the
+ destination buffer, which must be at least 0.1% larger than sourceLen plus
+ 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
+
+ compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_BUF_ERROR if there was not enough room in the output buffer,
+ Z_STREAM_ERROR if the level parameter is invalid.
+*/
+int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
+ Bytef *dest;
+ uLongf *destLen;
+ const Bytef *source;
+ uLong sourceLen;
+ int level;
+{
+ z_stream stream;
+ int err;
+
+ stream.next_in = (Bytef*)source;
+ stream.avail_in = (uInt)sourceLen;
+#ifdef MAXSEG_64K
+ /* Check for source > 64K on 16-bit machine: */
+ if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
+#endif
+ stream.next_out = dest;
+ stream.avail_out = (uInt)*destLen;
+ if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
+
+ stream.zalloc = (alloc_func)0;
+ stream.zfree = (free_func)0;
+ stream.opaque = (voidpf)0;
+
+ err = deflateInit(&stream, level);
+ if (err != Z_OK) return err;
+
+ err = deflate(&stream, Z_FINISH);
+ if (err != Z_STREAM_END) {
+ deflateEnd(&stream);
+ return err == Z_OK ? Z_BUF_ERROR : err;
+ }
+ *destLen = stream.total_out;
+
+ err = deflateEnd(&stream);
+ return err;
+}
+
+/* ===========================================================================
+ */
+int ZEXPORT compress (dest, destLen, source, sourceLen)
+ Bytef *dest;
+ uLongf *destLen;
+ const Bytef *source;
+ uLong sourceLen;
+{
+ return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
+}
+
+/* ===========================================================================
+ If the default memLevel or windowBits for deflateInit() is changed, then
+ this function needs to be updated.
+ */
+uLong ZEXPORT compressBound (sourceLen)
+ uLong sourceLen;
+{
+ return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
+}
diff --git a/lib/libz/compress.cat3 b/lib/libz/compress.cat3
new file mode 100644
index 0000000..bcd9add
--- /dev/null
+++ b/lib/libz/compress.cat3
@@ -0,0 +1,1556 @@
+COMPRESS(3) BSD Library Functions Manual COMPRESS(3)
+
+NAME
+ compress, zlibVersion, deflateInit, deflate, deflateEnd, inflateInit,
+ inflate, inflateEnd, deflateInit2, deflateSetDictionary, deflateCopy,
+ deflateReset, deflateParams, deflateTune, deflateBound, deflatePrime,
+ deflateSetHeader, inflateInit2, inflateSetDictionary, inflateSync,
+ inflateCopy, inflateReset, inflatePrime, inflateGetHeader,
+ inflateBackInit, inflateBack, inflateBackEnd, zlibCompileFlags,
+ compress2, compressBound, uncompress, gzopen, gzdopen, gzsetparams,
+ gzread, gzwrite, gzprintf, gzputs, gzgets, gzputc, gzgetc, gzungetc,
+ gzflush, gzseek, gzrewind, gztell, gzeof, gzdirect, gzclose, gzerror,
+ gzclearerr, adler32, adler32_combine, crc32, crc32_combine -- zlib gen-
+ eral purpose compression library
+
+SYNOPSIS
+ #include <zlib.h>
+
+ Basic functions
+
+ const char *
+ zlibVersion(void);
+
+ int
+ deflateInit(z_streamp strm, int level);
+
+ int
+ deflate(z_streamp strm, int flush);
+
+ int
+ deflateEnd(z_streamp strm);
+
+ int
+ inflateInit(z_streamp strm);
+
+ int
+ inflate(z_streamp strm, int flush);
+
+ int
+ inflateEnd(z_streamp strm);
+
+ Advanced functions
+
+ int
+ deflateInit2(z_streamp strm, int level, int method, int windowBits,
+ int memLevel, int strategy);
+
+ int
+ deflateSetDictionary(z_streamp strm, const Bytef *dictionary,
+ uInt dictLength);
+
+ int
+ deflateCopy(z_streamp dest, z_streamp source);
+
+ int
+ deflateReset(z_streamp strm);
+
+ int
+ deflateParams(z_streamp strm, int level, int strategy);
+
+ int
+ deflateTune(z_streamp strm, int good_length, int max_lazy,
+ int nice_length, int max_chain);
+
+ uLong
+ deflateBound(z_streamp strm, uLong sourceLen);
+
+ int
+ deflatePrime(z_streamp strm, int bits, int value);
+
+ int
+ deflateSetHeader(z_streamp strm, gz_headerp head);
+
+ int
+ inflateInit2(z_streamp strm, int windowBits);
+
+ int
+ inflateSetDictionary(z_streamp strm, const Bytef *dictionary,
+ uInt dictLength);
+
+ int
+ inflateSync(z_streamp strm);
+
+ int
+ inflateCopy(z_streamp dst, z_streamp source);
+
+ int
+ inflateReset(z_streamp strm);
+
+ int
+ inflatePrime(z_streamp strm, int bits, int value);
+
+ int
+ inflateGetHeader(z_streamp strm, gz_headerp head);
+
+ int
+ inflateBackInit(z_stream *strm, int windowBits,
+ unsigned char FAR *window);
+
+ int
+ inflateBack(z_stream *strm, in_func in, void FAR *in_desc, out_func out,
+ void FAR *out_desc);
+
+ int
+ inflateBackEnd(z_stream *strm);
+
+ uLong
+ zlibCompileFlags(void);
+
+ Utility functions
+
+ typedef voidp gzFile;
+
+ int
+ compress(Bytef *dest, uLongf *destLen, const Bytef *source,
+ uLong sourceLen);
+
+ int
+ compress2(Bytef *dest, uLongf *destLen, const Bytef *source,
+ uLong sourceLen, int level);
+
+ uLong
+ compressBound(uLong sourceLen);
+
+ int
+ uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
+ uLong sourceLen);
+
+ gzFile
+ gzopen(const char *path, const char *mode);
+
+ gzFile
+ gzdopen(int fd, const char *mode);
+
+ int
+ gzsetparams(gzFile file, int level, int strategy);
+
+ int
+ gzread(gzFile file, voidp buf, unsigned len);
+
+ int
+ gzwrite(gzFile file, voidpc buf, unsigned len);
+
+ int
+ gzprintf(gzFile file, const char *format, ...);
+
+ int
+ gzputs(gzFile file, const char *s);
+
+ char *
+ gzgets(gzFile file, char *buf, int len);
+
+ int
+ gzputc(gzFile file, int c);
+
+ int
+ gzgetc(gzFile file);
+
+ int
+ gzungetc(int c, gzFile file);
+
+ int
+ gzflush(gzFile file, int flush);
+
+ z_off_t
+ gzseek(gzFile file, z_off_t offset, int whence);
+
+ int
+ gzrewind(gzFile file);
+
+ z_off_t
+ gztell(gzFile file);
+
+ int
+ gzeof(gzFile file);
+
+ int
+ gzdirect(gzFile file);
+
+ int
+ gzclose(gzFile file);
+
+ const char *
+ gzerror(gzFile file, int *errnum);
+
+ void
+ gzclearerr(gzFile file);
+
+ Checksum functions
+
+ uLong
+ adler32(uLong adler, const Bytef *buf, uInt len);
+
+ uLong
+ adler32_combine(uLong adler1, uLong adler2, z_off_t len2);
+
+ uLong
+ crc32(uLong crc, const Bytef *buf, uInt len);
+
+ uLong
+ crc32_combine(uLong crc1, uLong crc2, z_off_t len2);
+
+DESCRIPTION
+ This manual page describes the zlib general purpose compression library,
+ version 1.2.3.
+
+ The zlib compression library provides in-memory compression and decom-
+ pression functions, including integrity checks of the uncompressed data.
+ This version of the library supports only one compression method
+ (deflation) but other algorithms will be added later and will have the
+ same stream interface.
+
+ Compression can be done in a single step if the buffers are large enough
+ (for example if an input file is mmap'ed), or can be done by repeated
+ calls of the compression function. In the latter case, the application
+ must provide more input and/or consume the output (providing more output
+ space) before each call.
+
+ The compressed data format used by default by the in-memory functions is
+ the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
+ around a deflate stream, which is itself documented in RFC 1951.
+
+ The library also supports reading and writing files in gzip(1) (.gz) for-
+ mat with an interface similar to that of stdio(3) using the functions
+ that start with "gz". The gzip format is different from the zlib format.
+ gzip is a gzip wrapper, documented in RFC 1952, wrapped around a deflate
+ stream. This library can optionally read and write gzip streams in mem-
+ ory as well.
+
+ The zlib format was designed to be compact and fast for use in memory and
+ on communications channels. The gzip format was designed for single-file
+ compression on file systems, has a larger header than zlib to maintain
+ directory information, and uses a different, slower, check method than
+ zlib.
+
+ The library does not install any signal handler. The decoder checks the
+ consistency of the compressed data, so the library should never crash
+ even in case of corrupted input.
+
+ The functions within the library are divided into the following sections:
+
+ - Basic functions
+ - Advanced functions
+ - Utility functions
+ - Checksum functions
+
+BASIC FUNCTIONS
+ const char * zlibVersion(void);
+
+ The application can compare zlibVersion() and ZLIB_VERSION for
+ consistency. If the first character differs, the library code
+ actually used is not compatible with the <zlib.h> header file
+ used by the application. This check is automatically made by
+ deflateInit() and inflateInit().
+
+ int deflateInit(z_streamp strm, int level);
+
+ The deflateInit() function initializes the internal stream state
+ for compression. The fields zalloc, zfree, and opaque must be
+ initialized before by the caller. If zalloc and zfree are set to
+ Z_NULL, deflateInit() updates them to use default allocation
+ functions.
+
+ The compression level must be Z_DEFAULT_COMPRESSION, or between 0
+ and 9: 1 gives best speed, 9 gives best compression, 0 gives no
+ compression at all (the input data is simply copied a block at a
+ time).
+
+ Z_DEFAULT_COMPRESSION requests a default compromise between speed
+ and compression (currently equivalent to level 6).
+
+ deflateInit() returns Z_OK if successful, Z_MEM_ERROR if there
+ was not enough memory, Z_STREAM_ERROR if level is not a valid
+ compression level, Z_VERSION_ERROR if the zlib library version
+ (zlib_version) is incompatible with the version assumed by the
+ caller (ZLIB_VERSION). msg is set to null if there is no error
+ message. deflateInit() does not perform any compression: this
+ will be done by deflate().
+
+ int deflate(z_streamp strm, int flush);
+
+ deflate() compresses as much data as possible, and stops when the
+ input buffer becomes empty or the output buffer becomes full. It
+ may introduce some output latency (reading input without
+ producing any output) except when forced to flush.
+
+ The detailed semantics are as follows. deflate() performs one or
+ both of the following actions:
+
+ Compress more input starting at next_in and update next_in and
+ avail_in accordingly. If not all input can be processed (because
+ there is not enough room in the output buffer), next_in and
+ avail_in are updated and processing will resume at this point for
+ the next call to deflate().
+
+ Provide more output starting at next_out and update next_out and
+ avail_out accordingly. This action is forced if the parameter
+ flush is non-zero. Forcing flush frequently degrades the com-
+ pression ratio, so this parameter should be set only when neces-
+ sary (in interactive applications). Some output may be provided
+ even if flush is not set.
+
+ Before the call to deflate(), the application should ensure that
+ at least one of the actions is possible, by providing more input
+ and/or consuming more output, and updating avail_in or avail_out
+ accordingly; avail_out should never be zero before the call. The
+ application can consume the compressed output when it wants, for
+ example when the output buffer is full (avail_out == 0), or after
+ each call to deflate(). If deflate() returns Z_OK and with zero
+ avail_out, it must be called again after making room in the out-
+ put buffer because there might be more output pending.
+
+ Normally the parameter flush is set to Z_NO_FLUSH, which allows
+ deflate() to decide how much data to accumulate before producing
+ output, in order to maximise compression.
+
+ If the parameter flush is set to Z_SYNC_FLUSH, all pending output
+ is flushed to the output buffer and the output is aligned on a
+ byte boundary, so that the decompressor can get all input data
+ available so far. (In particular, avail_in is zero after the
+ call if enough output space has been provided before the call.)
+ Flushing may degrade compression for some compression algorithms
+ and so it should be used only when necessary.
+
+ If flush is set to Z_FULL_FLUSH, all output is flushed as with
+ Z_SYNC_FLUSH, and the compression state is reset so that decom-
+ pression can restart from this point if previous compressed data
+ has been damaged or if random access is desired. Using
+ Z_FULL_FLUSH too often can seriously degrade compression.
+
+ If deflate() returns with avail_out == 0, this function must be
+ called again with the same value of the flush parameter and more
+ output space (updated avail_out), until the flush is complete
+ (deflate() returns with non-zero avail_out). In the case of a
+ Z_FULL_FLUSH or a Z_SYNC_FLUSH, make sure that avail_out is
+ greater than six to avoid repeated flush markers due to avail_out
+ == 0 on return.
+
+ If the parameter flush is set to Z_FINISH, pending input is pro-
+ cessed, pending output is flushed and deflate() returns with
+ Z_STREAM_END if there was enough output space; if deflate() re-
+ turns with Z_OK, this function must be called again with Z_FINISH
+ and more output space (updated avail_out but no more input data,
+ until it returns with Z_STREAM_END or an error. After deflate()
+ has returned Z_STREAM_END, the only possible operations on the
+ stream are deflateReset() or deflateEnd().
+
+ Z_FINISH can be used immediately after deflateInit() if all the
+ compression is to be done in a single step. In this case,
+ avail_out must be at least the value returned by deflateBound()
+ (see below). If deflate() does not return Z_STREAM_END, then it
+ must be called again as described above.
+
+ deflate() sets strm->adler to the Adler-32 checksum of all input
+ read so far (that is, total_in bytes).
+
+ deflate() may update strm->data_type if it can make a good guess
+ about the input data type (Z_BINARY or Z_TEXT). If in doubt, the
+ data is considered binary. This field is only for information
+ purposes and does not affect the compression algorithm in any
+ manner.
+
+ deflate() returns Z_OK if some progress has been made (more input
+ processed or more output produced), Z_STREAM_END if all input has
+ been consumed and all output has been produced (only when flush
+ is set to Z_FINISH), Z_STREAM_ERROR if the stream state was in-
+ consistent (for example, if next_in or next_out was NULL),
+ Z_BUF_ERROR if no progress is possible (for example, avail_in or
+ avail_out was zero). Note that Z_BUF_ERROR is not fatal, and
+ deflate() can be called again with more input and more output
+ space to continue processing.
+
+ int deflateEnd(z_streamp strm);
+
+ All dynamically allocated data structures for this stream are
+ freed. This function discards any unprocessed input and does not
+ flush any pending output.
+
+ deflateEnd() returns Z_OK if successful, Z_STREAM_ERROR if the
+ stream state was inconsistent, Z_DATA_ERROR if the stream was
+ freed prematurely (some input or output was discarded). In the
+ error case, msg may be set but then points to a static string
+ (which must not be deallocated).
+
+ int inflateInit(z_streamp strm);
+ The inflateInit() function initializes the internal stream state
+ for decompression. The fields next_in, avail_in, zalloc, zfree,
+ and opaque must be initialized before by the caller. If next_in
+ is not Z_NULL and avail_in is large enough (the exact value
+ depends on the compression method), inflateInit() determines the
+ compression method from the zlib header and allocates all data
+ structures accordingly; otherwise the allocation will be deferred
+ to the first call to inflate(). If zalloc and zfree are set to
+ Z_NULL, inflateInit() updates them to use default allocation
+ functions.
+
+ inflateInit() returns Z_OK if successful, Z_MEM_ERROR if there
+ was not enough memory, Z_VERSION_ERROR if the zlib library ver-
+ sion is incompatible with the version assumed by the caller. msg
+ is set to null if there is no error message. inflateInit() does
+ not perform any decompression apart from reading the zlib header
+ if present: this will be done by inflate(). (So next_in and
+ avail_in may be modified, but next_out and avail_out are un-
+ changed.)
+
+ int inflate(z_streamp strm, int flush);
+ inflate() decompresses as much data as possible, and stops when
+ the input buffer becomes empty or the output buffer becomes full.
+ It may introduce some output latency (reading input without
+ producing any output) except when forced to flush.
+
+ The detailed semantics are as follows. inflate() performs one or
+ both of the following actions:
+
+ Decompress more input starting at next_in and update next_in and
+ avail_in accordingly. If not all input can be processed (because
+ there is not enough room in the output buffer), next_in is up-
+ dated and processing will resume at this point for the next call
+ to inflate().
+
+ Provide more output starting at next_out and update next_out and
+ avail_out accordingly. inflate() provides as much output as pos-
+ sible, until there is no more input data or no more space in the
+ output buffer (see below about the flush parameter).
+
+ Before the call to inflate(), the application should ensure that
+ at least one of the actions is possible, by providing more input
+ and/or consuming more output, and updating the next_* and avail_*
+ values accordingly. The application can consume the uncompressed
+ output when it wants, for example when the output buffer is full
+ (avail_out == 0), or after each call to inflate(). If inflate()
+ returns Z_OK and with zero avail_out, it must be called again af-
+ ter making room in the output buffer because there might be more
+ output pending.
+
+ The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
+ Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush
+ as much output as possible to the output buffer. Z_BLOCK re-
+ quests that inflate() stop if and when it gets to the next de-
+ flate block boundary. When decoding the zlib or gzip format,
+ this will cause inflate() to return immediately after the header
+ and before the first block. When doing a raw inflate, inflate()
+ will go ahead and process the first block, and will return when
+ it gets to the end of that block, or when it runs out of data.
+
+ The Z_BLOCK option assists in appending to or combining deflate
+ streams. Also to assist in this, on return inflate() will set
+ strm->data_type to the number of unused bits in the last byte
+ taken from strm->next_in, plus 64 if inflate() is currently de-
+ coding the last block in the deflate stream, plus 128 if
+ inflate() returned immediately after decoding an end-of-block
+ code or decoding the complete header up to just before the first
+ byte of the deflate stream. The end-of-block will not be indi-
+ cated until all of the uncompressed data from that block has been
+ written to strm->next_out. The number of unused bits may in gen-
+ eral be greater than seven, except when bit 7 of data_type is
+ set, in which case the number of unused bits will be less than
+ eight.
+
+ inflate() should normally be called until it returns Z_STREAM_END
+ or an error. However if all decompression is to be performed in
+ a single step (a single call to inflate), the parameter flush
+ should be set to Z_FINISH. In this case all pending input is
+ processed and all pending output is flushed; avail_out must be
+ large enough to hold all the uncompressed data. (The size of the
+ uncompressed data may have been saved by the compressor for this
+ purpose.) The next operation on this stream must be inflateEnd()
+ to deallocate the decompression state. The use of Z_FINISH is
+ never required, but can be used to inform inflate() that a faster
+ approach may be used for the single inflate() call.
+
+ In this implementation, inflate() always flushes as much output
+ as possible to the output buffer, and always uses the faster ap-
+ proach on the first call. So the only effect of the flush param-
+ eter in this implementation is on the return value of inflate(),
+ as noted below, or when it returns early because Z_BLOCK is used.
+
+ If a preset dictionary is needed after this call (see
+ inflateSetDictionary() below), inflate() sets strm->adler to the
+ Adler-32 checksum of the dictionary chosen by the compressor and
+ returns Z_NEED_DICT; otherwise it sets strm->adler to the
+ Adler-32 checksum of all output produced so far (that is,
+ total_out bytes) and returns Z_OK, Z_STREAM_END or an error code
+ as described below. At the end of the stream, inflate() checks
+ that its computed Adler-32 checksum is equal to that saved by the
+ compressor and returns Z_STREAM_END only if the checksum is cor-
+ rect.
+
+ inflate() will decompress and check either zlib-wrapped or gzip-
+ wrapped deflate data. The header type is detected automatically.
+ Any information contained in the gzip header is not retained, so
+ applications that need that information should instead use raw
+ inflate; see inflateInit2() below, or inflateBack() and perform
+ their own processing of the gzip header and trailer.
+
+ inflate() returns Z_OK if some progress has been made (more input
+ processed or more output produced), Z_STREAM_END if the end of
+ the compressed data has been reached and all uncompressed output
+ has been produced, Z_NEED_DICT if a preset dictionary is needed
+ at this point, Z_DATA_ERROR if the input data was corrupted (in-
+ put stream not conforming to the zlib format or incorrect check
+ value), Z_STREAM_ERROR if the stream structure was inconsistent
+ (for example, if next_in or next_out was NULL), Z_MEM_ERROR if
+ there was not enough memory, Z_BUF_ERROR if no progress is possi-
+ ble or if there was not enough room in the output buffer when
+ Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
+ inflate() can be called again with more input and more output
+ space to continue compressing. If Z_DATA_ERROR is returned, the
+ application may then call inflateSync() to look for a good com-
+ pression block if a partial recovery of the data is desired.
+
+ int inflateEnd(z_streamp strm);
+ All dynamically allocated data structures for this stream are
+ freed. This function discards any unprocessed input and does not
+ flush any pending output.
+
+ inflateEnd() returns Z_OK if successful, or Z_STREAM_ERROR if the
+ stream state was inconsistent. In the error case, msg may be set
+ but then points to a static string (which must not be
+ deallocated).
+
+ADVANCED FUNCTIONS
+ The following functions are needed only in some special applications.
+
+ int deflateInit2(z_streamp strm, int level, int method, int windowBits,
+ int memLevel, int strategy);
+
+ This is another version of deflateInit() with more compression
+ options. The fields next_in, zalloc, zfree, and opaque must be
+ initialized before by the caller.
+
+ The method parameter is the compression method. It must be
+ Z_DEFLATED in this version of the library.
+
+ The windowBits parameter is the base two logarithm of the window
+ size (the size of the history buffer). It should be in the range
+ 8..15 for this version of the library. Larger values of this pa-
+ rameter result in better compression at the expense of memory us-
+ age. The default value is 15 if deflateInit() is used instead.
+
+ windowBits can also be -8..-15 for raw deflate. In this case,
+ -windowBits determines the window size. deflate() will then gen-
+ erate raw deflate data with no zlib header or trailer, and will
+ not compute an Adler-32 check value.
+
+ windowBits can also be greater than 15 for optional gzip encod-
+ ing. Add 16 to windowBits to write a simple gzip header and
+ trailer around the compressed data instead of a zlib wrapper.
+ The gzip header will have no file name, no extra data, no com-
+ ment, no modification time (set to zero), no header crc, and the
+ operating system will be set to 255 (unknown). If a gzip stream
+ is being written, strm->adler is a crc32 instead of an adler32.
+
+ The memLevel parameter specifies how much memory should be allo-
+ cated for the internal compression state. memLevel=1 uses mini-
+ mum memory but is slow and reduces compression ratio; memLevel=9
+ uses maximum memory for optimal speed. The default value is 8.
+ See <zconf.h> for total memory usage as a function of windowBits
+ and memLevel.
+
+ The strategy parameter is used to tune the compression algorithm.
+ Use the value Z_DEFAULT_STRATEGY for normal data; Z_FILTERED for
+ data produced by a filter (or predictor); Z_HUFFMAN_ONLY to force
+ Huffman encoding only (no string match), or Z_RLE to limit match
+ distances to one (run-length encoding). Filtered data consists
+ mostly of small values with a somewhat random distribution. In
+ this case, the compression algorithm is tuned to compress them
+ better. The effect of Z_FILTERED is to force more Huffman coding
+ and less string matching; it is somewhat intermediate between
+ Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as
+ fast as Z_HUFFMAN_ONLY, but gives better compression for PNG im-
+ age data. The strategy parameter only affects the compression
+ ratio but not the correctness of the compressed output, even if
+ it is not set appropriately. Z_FIXED prevents the use of dynamic
+ Huffman codes, allowing for a simpler decoder for special appli-
+ cations.
+
+ deflateInit2() returns Z_OK if successful, Z_MEM_ERROR if there
+ was not enough memory, Z_STREAM_ERROR if a parameter is invalid
+ (such as an invalid method). msg is set to null if there is no
+ error message. deflateInit2() does not perform any compression:
+ this will be done by deflate().
+
+ int deflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt
+ dictLength);
+
+ Initializes the compression dictionary from the given byte se-
+ quence without producing any compressed output. This function
+ must be called immediately after deflateInit(), deflateInit2(),
+ or deflateReset(), before any call to deflate(). The compressor
+ and decompressor must use exactly the same dictionary (see
+ inflateSetDictionary()).
+
+ The dictionary should consist of strings (byte sequences) that
+ are likely to be encountered later in the data to be compressed,
+ with the most commonly used strings preferably put towards the
+ end of the dictionary. Using a dictionary is most useful when
+ the data to be compressed is short and can be predicted with good
+ accuracy; the data can then be compressed better than with the
+ default empty dictionary.
+
+ Depending on the size of the compression data structures selected
+ by deflateInit() or deflateInit2(), a part of the dictionary may
+ in effect be discarded, for example if the dictionary is larger
+ than the window size in deflate() or deflate2(). Thus the
+ strings most likely to be useful should be put at the end of the
+ dictionary, not at the front. In addition, the current implemen-
+ tation of deflate() will use at most the window size minus 262
+ bytes of the provided dictionary.
+
+ Upon return of this function, strm->adler is set to the Adler-32
+ value of the dictionary; the decompressor may later use this
+ value to determine which dictionary has been used by the compres-
+ sor. (The Adler-32 value applies to the whole dictionary even if
+ only a subset of the dictionary is actually used by the compres-
+ sor.) If a raw deflate was requested, then the Adler-32 value is
+ not computed and strm->adler is not set.
+
+ deflateSetDictionary() returns Z_OK if successful, or
+ Z_STREAM_ERROR if a parameter is invalid (such as NULL
+ dictionary) or the stream state is inconsistent (for example if
+ deflate() has already been called for this stream or if the com-
+ pression method is bsort). deflateSetDictionary() does not per-
+ form any compression: this will be done by deflate().
+
+ int deflateCopy(z_streamp dest, z_streamp source);
+
+ The deflateCopy() function sets the destination stream as a com-
+ plete copy of the source stream.
+
+ This function can be useful when several compression strategies
+ will be tried, for example when there are several ways of pre-
+ processing the input data with a filter. The streams that will
+ be discarded should then be freed by calling deflateEnd(). Note
+ that deflateCopy() duplicates the internal compression state
+ which can be quite large, so this strategy is slow and can con-
+ sume lots of memory.
+
+ deflateCopy() returns Z_OK if successful, Z_MEM_ERROR if there
+ was not enough memory, Z_STREAM_ERROR if the source stream state
+ was inconsistent (such as zalloc being NULL). msg is left un-
+ changed in both source and destination.
+
+ int deflateReset(z_streamp strm);
+
+ This function is equivalent to deflateEnd() followed by
+ deflateInit(), but does not free and reallocate all the internal
+ compression state. The stream will keep the same compression
+ level and any other attributes that may have been set by
+ deflateInit2().
+
+ deflateReset() returns Z_OK if successful, or Z_STREAM_ERROR if
+ the source stream state was inconsistent (such as zalloc or state
+ being NULL).
+
+ int deflateParams(z_streamp strm, int level, int strategy);
+
+ The deflateParams() function dynamically updates the compression
+ level and compression strategy. The interpretation of level and
+ strategy is as in deflateInit2(). This can be used to switch be-
+ tween compression and straight copy of the input data, or to
+ switch to a different kind of input data requiring a different
+ strategy. If the compression level is changed, the input avail-
+ able so far is compressed with the old level (and may be
+ flushed); the new level will take effect only at the next call to
+ deflate().
+
+ Before the call to deflateParams(), the stream state must be set
+ as for a call to deflate(), since the currently available input
+ may have to be compressed and flushed. In particular,
+ strm->avail_out must be non-zero.
+
+ deflateParams() returns Z_OK if successful, Z_STREAM_ERROR if the
+ source stream state was inconsistent or if a parameter was in-
+ valid, or Z_BUF_ERROR if strm->avail_out was zero.
+
+ int deflateTune(z_streamp strm, int good_length, int max_lazy, int
+ nice_length, int max_chain)
+
+ Fine tune deflate()'s internal compression parameters. This
+ should only be used by someone who understands the algorithm used
+ by zlib's deflate for searching for the best matching string, and
+ even then only by the most fanatic optimizer trying to squeeze
+ out the last compressed bit for their specific input data. Read
+ the deflate.c source code for the meaning of the max_lazy,
+ good_length, nice_length, and max_chain parameters.
+
+ deflateTune() can be called after deflateInit() or
+ deflateInit2(), and returns Z_OK on success, or Z_STREAM_ERROR
+ for an invalid deflate stream.
+
+ uLong deflateBound(z_streamp strm, uLong sourceLen)
+
+ deflateBound() returns an upper bound on the compressed size af-
+ ter deflation of sourceLen bytes. It must be called after
+ deflateInit() or deflateInit2(). This would be used to allocate
+ an output buffer for deflation in a single pass, and so would be
+ called before deflate().
+
+ int deflatePrime(z_streamp strm, int bits, int value)
+
+ deflatePrime() inserts bits in the deflate output stream. The
+ intent is that this function is used to start off the deflate
+ output with the bits leftover from a previous deflate stream when
+ appending to it. As such, this function can only be used for raw
+ deflate, and must be used before the first deflate() call after a
+ deflateInit2() or deflateReset(). bits must be less than or
+ equal to 16, and that many of the least significant bits of value
+ will be inserted in the output.
+
+ deflatePrime() returns Z_OK if successful, or Z_STREAM_ERROR if
+ the source stream state was inconsistent.
+
+ int deflateSetHeader(z_streamp strm, gz_headerp head)
+
+ deflateSetHeader() provides gzip header information for when a
+ gzip stream is requested by deflateInit2(). deflateSetHeader()
+ may be called after deflateInit2() or deflateReset() and before
+ the first call of deflate(). The text, time, os, extra field,
+ name, and comment information in the provided gz_header structure
+ are written to the gzip header (xflag is ignored - the extra
+ flags are set according to the compression level). The caller
+ must assure that, if not Z_NULL, name and comment are terminated
+ with a zero byte, and that if extra is not Z_NULL, that extra_len
+ bytes are available there. If hcrc is true, a gzip header CRC is
+ included. Note that the current versions of the command-line
+ version of gzip(1) do not support header CRCs, and will report
+ that it is a "multi-part gzip file" and give up.
+
+ If deflateSetHeader() is not used, the default gzip header has
+ text false, the time set to zero, and os set to 255, with no ex-
+ tra, name, or comment fields. The gzip header is returned to the
+ default state by deflateReset().
+
+ deflateSetHeader() returns Z_OK if successful, or Z_STREAM_ERROR
+ if the source stream state was inconsistent.
+
+ int inflateInit2(z_streamp strm, int windowBits);
+
+ This is another version of inflateInit() with an extra parameter.
+ The fields next_in, avail_in, zalloc, zfree, and opaque must be
+ initialized before by the caller.
+
+ The windowBits parameter is the base two logarithm of the maximum
+ window size (the size of the history buffer). It should be in
+ the range 8..15 for this version of the library. The default
+ value is 15 if inflateInit() is used instead. windowBits must be
+ greater than or equal to the windowBits value provided to
+ deflateInit2() while compressing, or it must be equal to 15 if
+ deflateInit2() was not used. If a compressed stream with a
+ larger window size is given as input, inflate() will return with
+ the error code Z_DATA_ERROR instead of trying to allocate a
+ larger window.
+
+ windowBits can also be -8..-15 for raw inflate. In this case,
+ -windowBits determines the window size. inflate() will then
+ process raw deflate data, not looking for a zlib or gzip header,
+ not generating a check value, and not looking for any check val-
+ ues for comparison at the end of the stream. This is for use
+ with other formats that use the deflate compressed data format
+ such as zip. Those formats provide their own check values. If a
+ custom format is developed using the raw deflate format for com-
+ pressed data, it is recommended that a check value such as an
+ Adler-32 or a crc32 be applied to the uncompressed data as is
+ done in the zlib, gzip, and zip formats. For most applications,
+ the zlib format should be used as is. Note that comments above
+ on the use in deflateInit2() applies to the magnitude of
+ windowBits.
+
+ windowBits can also be greater than 15 for optional gzip decod-
+ ing. Add 32 to windowBits to enable zlib and gzip decoding with
+ automatic header detection, or add 16 to decode only the gzip
+ format (the zlib format will return a Z_DATA_ERROR). If a gzip
+ stream is being decoded, strm->adler is a crc32 instead of an
+ adler32.
+
+ inflateInit2() returns Z_OK if successful, Z_MEM_ERROR if there
+ was not enough memory, Z_STREAM_ERROR if a parameter is invalid
+ (such as a null strm). msg is set to null if there is no error
+ message. inflateInit2() does not perform any decompression apart
+ from reading the zlib header if present: this will be done by
+ inflate(). (So next_in and avail_in may be modified, but
+ next_out and avail_out are unchanged.)
+
+ int inflateSetDictionary(z_streamp strm, const Bytef *dictionary, uInt
+ dictLength);
+
+ Initializes the decompression dictionary from the given uncom-
+ pressed byte sequence. This function must be called immediately
+ after a call to inflate() if that call returned Z_NEED_DICT. The
+ dictionary chosen by the compressor can be determined from the
+ Adler-32 value returned by that call to inflate(). The compres-
+ sor and decompressor must use exactly the same dictionary (see
+ deflateSetDictionary()). For raw inflate, this function can be
+ called immediately after inflateInit2() or inflateReset() and be-
+ fore any call to inflate() to set the dictionary. The applica-
+ tion must ensure that the dictionary that was used for compres-
+ sion is provided.
+
+ inflateSetDictionary() returns Z_OK if successful, Z_STREAM_ERROR
+ if a parameter is invalid (such as NULL dictionary) or the stream
+ state is inconsistent, Z_DATA_ERROR if the given dictionary
+ doesn't match the expected one (incorrect Adler-32 value).
+ inflateSetDictionary() does not perform any decompression: this
+ will be done by subsequent calls of inflate().
+
+ int inflateSync(z_streamp strm);
+
+ Skips invalid compressed data until a full flush point (see above
+ the description of deflate() with Z_FULL_FLUSH) can be found, or
+ until all available input is skipped. No output is provided.
+
+ inflateSync() returns Z_OK if a full flush point has been found,
+ Z_BUF_ERROR if no more input was provided, Z_DATA_ERROR if no
+ flush point has been found, or Z_STREAM_ERROR if the stream
+ structure was inconsistent. In the success case, the application
+ may save the current value of total_in which indicates where
+ valid compressed data was found. In the error case, the applica-
+ tion may repeatedly call inflateSync(), providing more input each
+ time, until success or end of the input data.
+
+ int inflateCopy(z_streamp dest, z_streamp source)
+
+ Sets the destination stream as a complete copy of the source
+ stream.
+
+ This function can be useful when randomly accessing a large
+ stream. The first pass through the stream can periodically
+ record the inflate state, allowing restarting inflate at those
+ points when randomly accessing the stream.
+
+ inflateCopy() returns Z_OK if success, Z_MEM_ERROR if there was
+ not enough memory, Z_STREAM_ERROR if the source stream state was
+ inconsistent (such as zalloc being NULL). msg is left unchanged
+ in both source and dest.
+
+ int inflateReset(z_streamp strm);
+
+ This function is equivalent to inflateEnd() followed by
+ inflateInit(), but does not free and reallocate all the internal
+ decompression state. The stream will keep attributes that may
+ have been set by inflateInit2().
+
+ inflateReset() returns Z_OK if successful, or Z_STREAM_ERROR if
+ the source stream state was inconsistent (such as zalloc or state
+ being NULL).
+
+ int inflatePrime(z_stream strm, int bits, int value)
+
+ This function inserts bits in the inflate input stream. The in-
+ tent is that this function is used to start inflating at a bit
+ position in the middle of a byte. The provided bits will be used
+ before any bytes are used from next_in. This function should
+ only be used with raw inflate, and should be used before the
+ first inflate() call after inflateInit2() or inflateReset().
+ bits must be less than or equal to 16, and that many of the least
+ significant bits of value will be inserted in the input.
+
+ inflatePrime() returns Z_OK if successful, or Z_STREAM_ERROR if
+ the source stream state was inconsistent.
+
+ int inflateGetHeader(z_streamp strm, gz_headerp head)
+
+ inflateGetHeader() requests that gzip header information be
+ stored in the provided gz_header structure. inflateGetHeader()
+ may be called after inflateInit2() or inflateReset(), and before
+ the first call of inflate(). As inflate() processes the gzip
+ stream, head->done is zero until the header is completed, at
+ which time head->done is set to one. If a zlib stream is being
+ decoded, then head->done is set to -1 to indicate that there will
+ be no gzip header information forthcoming. Note that Z_BLOCK can
+ be used to force inflate() to return immediately after header
+ processing is complete and before any actual data is decom-
+ pressed.
+
+ The text, time, xflags, and os fields are filled in with the gzip
+ header contents. hcrc is set to true if there is a header CRC.
+ (The header CRC was valid if done is set to one.) If extra is
+ not Z_NULL, then extra_max contains the maximum number of bytes
+ to write to extra. Once done is true, extra_len contains the ac-
+ tual extra field length, and extra contains the extra field, or
+ that field truncated if extra_max is less than extra_len. If
+ name is not Z_NULL, then up to name_max characters are written
+ there, terminated with a zero unless the length is greater than
+ name_max. If comment is not Z_NULL, then up to comm_max charac-
+ ters are written there, terminated with a zero unless the length
+ is greater than comm_max. When any of extra, name, or comment
+ are not Z_NULL and the respective field is not present in the
+ header, then that field is set to Z_NULL to signal its absence.
+ This allows the use of deflateSetHeader() with the returned
+ structure to duplicate the header. However if those fields are
+ set to allocated memory, then the application will need to save
+ those pointers elsewhere so that they can be eventually freed.
+
+ If inflateGetHeader() is not used, then the header information is
+ simply discarded. The header is always checked for validity, in-
+ cluding the header CRC if present. inflateReset() will reset the
+ process to discard the header information. The application would
+ need to call inflateGetHeader() again to retrieve the header from
+ the next gzip stream.
+
+ inflateGetHeader() returns Z_OK if successful, or Z_STREAM_ERROR
+ if the source stream state was inconsistent.
+
+ int inflateBackInit(z_stream *strm, int windowBits, unsigned char FAR
+ *window)
+
+ Initialize the internal stream state for decompression using
+ inflateBack() calls. The fields zalloc, zfree and opaque in strm
+ must be initialized before the call. If zalloc and zfree are
+ Z_NULL, then the default library-derived memory allocation rou-
+ tines are used. windowBits is the base two logarithm of the win-
+ dow size, in the range 8..15. window is a caller supplied buffer
+ of that size. Except for special applications where it is as-
+ sured that deflate() was used with small window sizes, windowBits
+ must be 15 and a 32K byte window must be supplied to be able to
+ decompress general deflate streams.
+
+ See inflateBack() for the usage of these routines.
+
+ inflateBackInit() will return Z_OK on success, Z_STREAM_ERROR if
+ any of the parameters are invalid, Z_MEM_ERROR if the internal
+ state could not be allocated, or Z_VERSION_ERROR if the version
+ of the library does not match the version of the header file.
+
+ int inflateBack(z_stream *strm, in_func in, void FAR *in_desc, out_func
+ out, void FAR *out_desc)
+
+ inflateBack() does a raw inflate with a single call using a call-
+ back interface for input and output. This is more efficient than
+ inflate() for file I/O applications in that it avoids copying be-
+ tween the output and the sliding window by simply making the win-
+ dow itself the output buffer. This function trusts the applica-
+ tion to not change the output buffer passed by the output func-
+ tion, at least until inflateBack() returns.
+
+ inflateBackInit() must be called first to allocate the internal
+ state and to initialize the state with the user-provided window
+ buffer. inflateBack() may then be used multiple times to inflate
+ a complete, raw deflate stream with each call. inflateBackEnd()
+ is then called to free the allocated state.
+
+ A raw deflate stream is one with no zlib or gzip header or
+ trailer. This routine would normally be used in a utility that
+ reads zip or gzip files and writes out uncompressed files. The
+ utility would decode the header and process the trailer on its
+ own, hence this routine expects only the raw deflate stream to
+ decompress. This is different from the normal behavior of
+ inflate(), which expects either a zlib or gzip header and trailer
+ around the deflate stream.
+
+ inflateBack() uses two subroutines supplied by the caller that
+ are then called by inflateBack() for input and output.
+ inflateBack() calls those routines until it reads a complete de-
+ flate stream and writes out all of the uncompressed data, or un-
+ til it encounters an error. The function's parameters and return
+ types are defined above in the in_func and out_func typedefs.
+ inflateBack() will call in(in_desc, &buf) which should return the
+ number of bytes of provided input, and a pointer to that input in
+ buf. If there is no input available, in() must return zero --
+ buf is ignored in that case -- and inflateBack() will return a
+ buffer error. inflateBack() will call out(out_desc, buf, len) to
+ write the uncompressed data buf[0..len-1]. out() should return
+ zero on success, or non-zero on failure. If out() returns non-
+ zero, inflateBack() will return with an error. Neither in() nor
+ out() are permitted to change the contents of the window provided
+ to inflateBackInit(), which is also the buffer that out() uses to
+ write from. The length written by out() will be at most the win-
+ dow size. Any non-zero amount of input may be provided by in().
+
+ For convenience, inflateBack() can be provided input on the first
+ call by setting strm->next_in and strm->avail_in. If that input
+ is exhausted, then in() will be called. Therefore strm->next_in
+ must be initialized before calling inflateBack(). If
+ strm->next_in is Z_NULL, then in() will be called immediately for
+ input. If strm->next_in is not Z_NULL, then strm->avail_in must
+ also be initialized, and then if strm->avail_in is not zero, in-
+ put will initially be taken from strm->next_in[0 ..
+ strm->avail_in - 1].
+
+ The in_desc and out_desc parameters of inflateBack() are passed
+ as the first parameter of in() and out() respectively when they
+ are called. These descriptors can be optionally used to pass any
+ information that the caller-supplied in() and out() functions
+ need to do their job.
+
+ On return, inflateBack() will set strm->next_in and
+ strm->avail_in to pass back any unused input that was provided by
+ the last in() call. The return values of inflateBack() can be
+ Z_STREAM_END on success, Z_BUF_ERROR if in() or out() returned an
+ error, Z_DATA_ERROR if there was a format error in the deflate
+ stream (in which case strm->msg is set to indicate the nature of
+ the error), or Z_STREAM_ERROR if the stream was not properly ini-
+ tialized. In the case of Z_BUF_ERROR, an input or output error
+ can be distinguished using strm->next_in which will be Z_NULL
+ only if in() returned an error. If strm->next is not Z_NULL,
+ then the Z_BUF_ERROR was due to out() returning non-zero. (in()
+ will always be called before out(), so strm->next_in is assured
+ to be defined if out() returns non-zero.) Note that
+ inflateBack() cannot return Z_OK.
+
+ int inflateBackEnd(z_stream *strm)
+
+ All memory allocated by inflateBackInit() is freed.
+
+ inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if
+ the stream state was inconsistent.
+
+ uLong zlibCompileFlags(void)
+
+ This function returns flags indicating compile-time options.
+
+ Type sizes, two bits each:
+
+ 00 16 bits
+ 01 32 bits
+ 10 64 bits
+ 11 other:
+
+ 1.0 size of uInt
+ 3.2 size of uLong
+ 5.4 size of voidpf (pointer)
+ 7.6 size of z_off_t
+
+ Compiler, assembler, and debug options:
+
+ 8 DEBUG
+ 9 ASMV or ASMINF -- use ASM code
+ 10 ZLIB_WINAPI -- exported functions use the WINAPI
+ calling convention
+ 11 0 (reserved)
+
+ One-time table building (smaller code, but not thread-safe if
+ true):
+
+ 12 BUILDFIXED -- build static block decoding tables
+ when needed
+ 13 DYNAMIC_CRC_TABLE -- build CRC calculation tables
+ when needed
+ 14,15 0 (reserved)
+
+ Library content (indicates missing functionality):
+
+ 16 NO_GZCOMPRESS -- gz* functions cannot compress (to
+ avoid linking deflate code when not needed)
+ 17 NO_GZIP -- deflate can't write gzip streams, and
+ inflate can't detect and decode gzip streams (to
+ avoid linking CRC code)
+ 18-19 0 (reserved)
+
+ Operation variations (changes in library functionality):
+
+ 20 PKZIP_BUG_WORKAROUND -- slightly more permissive
+ inflate
+ 21 FASTEST -- deflate algorithm with only one, lowest
+ compression level
+ 22,23 0 (reserved)
+
+ The sprintf variant used by gzprintf (zero is best):
+
+ 24 0 = vs*, 1 = s* -- 1 means limited to 20 arguments
+ after the format
+ 25 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not
+ secure!
+ 26 0 = returns value, 1 = void -- 1 means inferred
+ string length returned
+
+ Remainder:
+
+ 27-31 0 (reserved)
+
+UTILITY FUNCTIONS
+ The following utility functions are implemented on top of the basic
+ stream-oriented functions. To simplify the interface, some default op-
+ tions are assumed (compression level and memory usage, standard memory
+ allocation functions). The source code of these utility functions can
+ easily be modified if you need special options.
+
+ int compress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong
+ sourceLen);
+
+ The compress() function compresses the source buffer into the
+ destination buffer. sourceLen is the byte length of the source
+ buffer. Upon entry, destLen is the total size of the destination
+ buffer, which must be at least the value returned by
+ compressBound(sourcelen). Upon exit, destLen is the actual size
+ of the compressed buffer. This function can be used to compress
+ a whole file at once if the input file is mmap'ed.
+
+ compress() returns Z_OK if successful, Z_MEM_ERROR if there was
+ not enough memory, or Z_BUF_ERROR if there was not enough room in
+ the output buffer.
+
+ int compress2(Bytef *dest, uLongf *destLen, const Bytef *source, uLong
+ sourceLen, int level);
+
+ The compress2() function compresses the source buffer into the
+ destination buffer. The level parameter has the same meaning as
+ in deflateInit(). sourceLen is the byte length of the source
+ buffer. Upon entry, destLen is the total size of the destination
+ buffer, which must be at least the value returned by
+ compressBound(sourceLen). Upon exit, destLen is the actual size
+ of the compressed buffer.
+
+ compress2() returns Z_OK if successful, Z_MEM_ERROR if there was
+ not enough memory, Z_BUF_ERROR if there was not enough room in
+ the output buffer, or Z_STREAM_ERROR if the level parameter is
+ invalid.
+
+ int compressBound(uLong sourceLen)
+
+ compressBound() returns an upper bound on the compressed size af-
+ ter compress() or compress2() on sourceLen bytes. It would be
+ used before a compress() or compress2() call to allocate the des-
+ tination buffer.
+
+ int uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, uLong
+ sourceLen);
+
+ The uncompress() function decompresses the source buffer into the
+ destination buffer. sourceLen is the byte length of the source
+ buffer. Upon entry, destLen is the total size of the destination
+ buffer, which must be large enough to hold the entire uncom-
+ pressed data. (The size of the uncompressed data must have been
+ saved previously by the compressor and transmitted to the decom-
+ pressor by some mechanism outside the scope of this compression
+ library.) Upon exit, destLen is the actual size of the com-
+ pressed buffer. This function can be used to decompress a whole
+ file at once if the input file is mmap'ed.
+
+ uncompress() returns Z_OK if successful, Z_MEM_ERROR if there was
+ not enough memory, Z_BUF_ERROR if there was not enough room in
+ the output buffer, or Z_DATA_ERROR if the input data was cor-
+ rupted or incomplete.
+
+ gzFile gzopen(const char *path, const char *mode);
+
+ The gzopen() function opens a gzip (.gz) file for reading or
+ writing. The mode parameter is as in fopen(3) ("rb" or "wb") but
+ can also include a compression level (wb9) or a strategy: `f' for
+ filtered data, as in "wb6f"; `h' for Huffman only compression, as
+ in "wb1h", or `R' for run-length encoding as in "wb1R". (See the
+ description of deflateInit2() for more information about the
+ strategy parameter.)
+
+ gzopen() can be used to read a file which is not in gzip format;
+ in this case gzread() will directly read from the file without
+ decompression.
+
+ gzopen() returns NULL if the file could not be opened or if there
+ was insufficient memory to allocate the (de)compression state;
+ errno can be checked to distinguish the two cases (if errno is
+ zero, the zlib error is Z_MEM_ERROR).
+
+ gzFile gzdopen(int fd, const char *mode);
+
+ The gzdopen() function associates a gzFile with the file descrip-
+ tor fd. File descriptors are obtained from calls like open(2),
+ dup(2), creat(3), pipe(2), or fileno(3) (if the file has been
+ previously opened with fopen(3)). The mode parameter is as in
+ gzopen().
+
+ The next call to gzclose() on the returned gzFile will also close
+ the file descriptor fd, just like fclose(fdopen(fd), mode) closes
+ the file descriptor fd. If you want to keep fd open, use gz-
+ dopen(dup(fd), mode).
+
+ gzdopen() returns NULL if there was insufficient memory to allo-
+ cate the (de)compression state.
+
+ int gzsetparams(gzFile file, int level, int strategy);
+
+ The gzsetparams() function dynamically updates the compression
+ level or strategy. See the description of deflateInit2() for the
+ meaning of these parameters.
+
+ gzsetparams() returns Z_OK if successful, or Z_STREAM_ERROR if
+ the file was not opened for writing.
+
+ int gzread(gzFile file, voidp buf, unsigned len);
+
+ The gzread() function reads the given number of uncompressed
+ bytes from the compressed file. If the input file was not in
+ gzip format, gzread() copies the given number of bytes into the
+ buffer.
+
+ gzread() returns the number of uncompressed bytes actually read
+ (0 for end of file, -1 for error).
+
+ int gzwrite(gzFile file, voidpc buf, unsigned len);
+
+ The gzwrite() function writes the given number of uncompressed
+ bytes into the compressed file. gzwrite() returns the number of
+ uncompressed bytes actually written (0 in case of error).
+
+ int gzprintf(gzFile file, const char *format, ...);
+
+ The gzprintf() function converts, formats, and writes the args to
+ the compressed file under control of the format string, as in
+ fprintf(3). gzprintf() returns the number of uncompressed bytes
+ actually written (0 in case of error). The number of uncom-
+ pressed bytes written is limited to 4095. The caller should make
+ sure that this limit is not exceeded. If it is exceeded, then
+ gzprintf() will return an error (0) with nothing written. In
+ this case, there may also be a buffer overflow with unpredictable
+ consequences, which is possible only if zlib was compiled with
+ the insecure functions sprintf() or vsprintf() because the secure
+ snprintf() or vsnprintf() functions were not available.
+
+ int gzputs(gzFile file, const char *s);
+
+ The gzputs() function writes the given null-terminated string to
+ the compressed file, excluding the terminating null character.
+
+ gzputs() returns the number of characters written, or -1 in case
+ of error.
+
+ char * gzgets(gzFile file, char *buf, int len);
+
+ The gzgets() function reads bytes from the compressed file until
+ len-1 characters are read, or a newline character is read and
+ transferred to buf, or an end-of-file condition is encountered.
+ The string is then terminated with a null character.
+
+ gzgets() returns buf, or Z_NULL in case of error.
+
+ int gzputc(gzFile file, int c);
+
+ The gzputc() function writes c, converted to an unsigned char,
+ into the compressed file. gzputc() returns the value that was
+ written, or -1 in case of error.
+
+ int gzgetc(gzFile file);
+
+ The gzgetc() function reads one byte from the compressed file.
+ gzgetc() returns this byte or -1 in case of end of file or error.
+
+ int gzungetc(int c, gzFile file)
+
+ Push one character back onto the stream to be read again later.
+ Only one character of push-back is allowed. gzungetc() returns
+ the character pushed, or -1 on failure. gzungetc() will fail if
+ a character has been pushed but not read yet, or if c is -1. The
+ pushed character will be discarded if the stream is repositioned
+ with gzseek() or gzrewind().
+
+ int gzflush(gzFile file, int flush);
+
+ The gzflush() function flushes all pending output into the com-
+ pressed file. The parameter flush is as in the deflate() func-
+ tion. The return value is the zlib error number (see function
+ gzerror() below). gzflush() returns Z_OK if the flush parameter
+ is Z_FINISH and all output could be flushed.
+
+ gzflush() should be called only when strictly necessary because
+ it can degrade compression.
+
+ z_off_t gzseek(gzFile file, z_off_t offset, int whence);
+
+ Sets the starting position for the next gzread() or gzwrite() on
+ the given compressed file. The offset represents a number of
+ bytes in the uncompressed data stream. The whence parameter is
+ defined as in lseek(2); the value SEEK_END is not supported.
+
+ If the file is opened for reading, this function is emulated but
+ can be extremely slow. If the file is opened for writing, only
+ forward seeks are supported; gzseek() then compresses a sequence
+ of zeroes up to the new starting position.
+
+ gzseek() returns the resulting offset location as measured in
+ bytes from the beginning of the uncompressed stream, or -1 in
+ case of error, in particular if the file is opened for writing
+ and the new starting position would be before the current posi-
+ tion.
+
+ int gzrewind(gzFile file);
+
+ The gzrewind() function rewinds the given file. This function is
+ supported only for reading.
+
+ gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET).
+
+ z_off_t gztell(gzFile file);
+
+ The gztell() function returns the starting position for the next
+ gzread() or gzwrite() on the given compressed file. This posi-
+ tion represents a number of bytes in the uncompressed data
+ stream.
+
+ gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR).
+
+ int gzeof(gzFile file);
+
+ The gzeof() function returns 1 when EOF has previously been de-
+ tected reading the given input stream, otherwise zero.
+
+ int gzdirect(gzFile file);
+
+ The gzdirect() function returns 1 if the file is being read di-
+ rectly without compression; otherwise it returns 0.
+
+ int gzclose(gzFile file);
+
+ The gzclose() function flushes all pending output if necessary,
+ closes the compressed file and deallocates all the (de)compres-
+ sion state. The return value is the zlib error number (see func-
+ tion gzerror() below).
+
+ const char * gzerror(gzFile file, int *errnum);
+
+ The gzerror() function returns the error message for the last er-
+ ror which occurred on the given compressed file. errnum is set
+ to the zlib error number. If an error occurred in the file sys-
+ tem and not in the compression library, errnum is set to Z_ERRNO
+ and the application may consult errno to get the exact error
+ code.
+
+ void gzclearerr(gzFile file)
+ Clears the error and end-of-file flags for file. This is analo-
+ gous to the clearerr() function in stdio. This is useful for
+ continuing to read a gzip file that is being written concur-
+ rently.
+
+CHECKSUM FUNCTIONS
+ These functions are not related to compression but are exported anyway
+ because they might be useful in applications using the compression li-
+ brary.
+
+ uLong adler32(uLong adler, const Bytef *buf, uInt len);
+ The adler32() function updates a running Adler-32 checksum with
+ the bytes buf[0..len-1] and returns the updated checksum. If buf
+ is NULL, this function returns the required initial value for the
+ checksum.
+
+ An Adler-32 checksum is almost as reliable as a CRC32 but can be
+ computed much faster. Usage example:
+
+ uLong adler = adler32(0L, Z_NULL, 0);
+
+ while (read_buffer(buffer, length) != EOF) {
+ adler = adler32(adler, buffer, length);
+ }
+ if (adler != original_adler) error();
+
+ uLong adler32_combine(uLong adler1, uLong adler2, z_off_t len2)
+
+ The adler32_combine() function combines two Adler-32 checksums
+ into one. For two sequences of bytes, seq1 and seq2 with lengths
+ len1 and len2, Adler-32 checksums are calculated for each, adler1
+ and adler2. adler32_combine() returns the Adler-32 checksum of
+ seq1 and seq2 concatenated, requiring only adler1, adler2, and
+ len2.
+
+ uLong crc32(uLong crc, const Bytef *buf, uInt len);
+
+ The crc32() function updates a running CRC-32 with the bytes
+ buf[0..len-1] and returns the updated CRC-32. If buf is NULL,
+ this function returns the required initial value for the CRC.
+ Pre- and post-conditioning (one's complement) is performed within
+ this function so it shouldn't be done by the application. Usage
+ example:
+
+ uLong crc = crc32(0L, Z_NULL, 0);
+
+ while (read_buffer(buffer, length) != EOF) {
+ crc = crc32(crc, buffer, length);
+ }
+ if (crc != original_crc) error();
+
+ uLong crc32_combine(uLong crc1, uLong crc2, z_off_t len2)
+
+ The crc32_combine() function combines two CRC-32 check values
+ into one. For two sequences of bytes, seq1 and seq2 with lengths
+ len1 and len2, CRC-32 check values are calculated for each, crc1
+ and crc2. crc32_combine() returns the CRC-32 check value of seq1
+ and seq2 concatenated, requiring only crc1, crc2, and len2.
+
+STRUCTURES
+ struct internal_state;
+
+ typedef struct z_stream_s {
+ Bytef *next_in; /* next input byte */
+ uInt avail_in; /* number of bytes available at next_in */
+ off_t total_in; /* total nb of input bytes read so far */
+
+ Bytef *next_out; /* next output byte should be put there */
+ uInt avail_out; /* remaining free space at next_out */
+ off_t total_out; /* total nb of bytes output so far */
+
+ char *msg; /* last error message, NULL if no error */
+ struct internal_state FAR *state; /* not visible by applications */
+
+ alloc_func zalloc; /* used to allocate the internal state */
+ free_func zfree; /* used to free the internal state */
+ voidpf opaque; /* private data object passed to zalloc and zfree*/
+
+ int data_type; /* best guess about the data type: binary or text*/
+ uLong adler; /* adler32 value of the uncompressed data */
+ uLong reserved; /* reserved for future use */
+ } z_stream;
+
+ typedef z_stream FAR * z_streamp;
+
+ /*
+ gzip header information passed to and from zlib routines.
+ See RFC 1952 for more details on the meanings of these fields.
+ */
+ typedef struct gz_header_s {
+ int text; /* true if compressed data believed to be text */
+ uLong time; /* modification time */
+ int xflags; /*extra flags (not used when writing a gzip file)*/
+ int os; /* operating system */
+ Bytef *extra; /* pointer to extra field or Z_NULL if none */
+ uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
+ uInt extra_max; /* space at extra (only when reading header) */
+ Bytef *name; /* pointer to zero-terminated file name or Z_NULL*/
+ uInt name_max; /* space at name (only when reading header) */
+ Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
+ uInt comm_max; /* space at comment (only when reading header) */
+ int hcrc; /* true if there was or will be a header crc */
+ int done; /* true when done reading gzip header (not used
+ when writing a gzip file) */
+ } gz_header;
+
+ typedef gz_header FAR *gz_headerp;
+
+ The application must update next_in and avail_in when avail_in has
+ dropped to zero. It must update next_out and avail_out when avail_out
+ has dropped to zero. The application must initialize zalloc, zfree, and
+ opaque before calling the init function. All other fields are set by the
+ compression library and must not be updated by the application.
+
+ The opaque value provided by the application will be passed as the first
+ parameter for calls to zalloc() and zfree(). This can be useful for cus-
+ tom memory management. The compression library attaches no meaning to
+ the opaque value.
+
+ zalloc must return Z_NULL if there is not enough memory for the object.
+ If zlib is used in a multi-threaded application, zalloc and zfree must be
+ thread safe.
+
+ On 16-bit systems, the functions zalloc and zfree must be able to allo-
+ cate exactly 65536 bytes, but will not be required to allocate more than
+ this if the symbol MAXSEG_64K is defined (see <zconf.h>).
+
+ WARNING: On MSDOS, pointers returned by zalloc for objects of exactly
+ 65536 bytes *must* have their offset normalized to zero. The default al-
+ location function provided by this library ensures this (see zutil.c).
+ To reduce memory requirements and avoid any allocation of 64K objects, at
+ the expense of compression ratio, compile the library with -DMAX_WBITS=14
+ (see <zconf.h>).
+
+ The fields total_in and total_out can be used for statistics or progress
+ reports. After compression, total_in holds the total size of the uncom-
+ pressed data and may be saved for use in the decompressor (particularly
+ if the decompressor wants to decompress everything in a single step).
+
+CONSTANTS
+ #define Z_NO_FLUSH 0
+ #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
+ #define Z_SYNC_FLUSH 2
+ #define Z_FULL_FLUSH 3
+ #define Z_FINISH 4
+ #define Z_BLOCK 5
+ /* Allowed flush values; see deflate() and inflate() below for details */
+
+ #define Z_OK 0
+ #define Z_STREAM_END 1
+ #define Z_NEED_DICT 2
+ #define Z_ERRNO (-1)
+ #define Z_STREAM_ERROR (-2)
+ #define Z_DATA_ERROR (-3)
+ #define Z_MEM_ERROR (-4)
+ #define Z_BUF_ERROR (-5)
+ #define Z_VERSION_ERROR (-6)
+ /* Return codes for the compression/decompression functions.
+ * Negative values are errors,
+ * positive values are used for special but normal events.
+ */
+
+ #define Z_NO_COMPRESSION 0
+ #define Z_BEST_SPEED 1
+ #define Z_BEST_COMPRESSION 9
+ #define Z_DEFAULT_COMPRESSION (-1)
+ /* compression levels */
+
+ #define Z_FILTERED 1
+ #define Z_HUFFMAN_ONLY 2
+ #define Z_RLE 3
+ #define Z_FIXED 4
+ #define Z_DEFAULT_STRATEGY 0
+ /* compression strategy; see deflateInit2() below for details */
+
+ #define Z_BINARY 0
+ #define Z_TEXT 1
+ #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
+ #define Z_UNKNOWN 2
+ /* Possible values of the data_type field (though see inflate()) */
+
+ #define Z_DEFLATED 8
+ /* The deflate compression method
+ * (the only one supported in this version)
+ */
+
+ #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
+
+ #define zlib_version zlibVersion()
+ /* for compatibility with versions < 1.0.2 */
+
+VARIOUS HACKS
+ deflateInit and inflateInit are macros to allow checking the zlib version
+ and the compiler's view of z_stream.
+
+ int deflateInit_(z_stream strm, int level, const char *version, int
+ stream_size);
+
+ int inflateInit_(z_stream strm, const char *version, int stream_size);
+
+ int deflateInit2_(z_stream strm, int level, int method, int windowBits,
+ int memLevel, int strategy, const char *version, int stream_size)
+
+ int inflateInit2_(z_stream strm, int windowBits, const char *version, int
+ stream_size);
+
+ int inflateBackInit_(z_stream *strm, int windowBits, unsigned char FAR
+ *window, const char *version, int stream_size)
+
+ const char * zError(int err);
+
+ int inflateSyncPoint(z_streamp z);
+
+ const uLongf * get_crc_table(void);
+
+SEE ALSO
+ compress(1), gzip(1)
+
+STANDARDS
+ P. Deutsch and J-L. Gailly, ZLIB Compressed Data Format Specification
+ version 3.3, RFC 1950, May 1996.
+
+ P. Deutsch, DEFLATE Compressed Data Format Specification version 1.3, RFC
+ 1951, May 1996.
+
+ P. Deutsch, GZIP file format specification version 4.3, RFC 1952, May
+ 1996.
+
+HISTORY
+ This manual page is based on an HTML version of <zlib.h> converted by
+ piaip <piaip@csie.ntu.edu.tw> and was converted to mdoc format by the
+ OpenBSD project.
+
+AUTHORS
+ Jean-loup Gailly <jloup@gzip.org>
+ Mark Adler <madler@alumni.caltech.edu>
+
+BSD March 16, 2018 BSD
diff --git a/lib/libz/crc32.c b/lib/libz/crc32.c
new file mode 100644
index 0000000..fe88dba
--- /dev/null
+++ b/lib/libz/crc32.c
@@ -0,0 +1,422 @@
+/* $OpenBSD: crc32.c,v 1.8 2005/07/20 15:56:41 millert Exp $ */
+/* crc32.c -- compute the CRC-32 of a data stream
+ * Copyright (C) 1995-2005 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ *
+ * Thanks to Rodney Brown <rbrown64@csc.com.au> for his contribution of faster
+ * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing
+ * tables for updating the shift register in one step with three exclusive-ors
+ * instead of four steps with four exclusive-ors. This results in about a
+ * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3.
+ */
+
+/*
+ Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore
+ protection on the static variables used to control the first-use generation
+ of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should
+ first call get_crc_table() to initialize the tables before allowing more than
+ one thread to use crc32().
+ */
+
+#ifdef MAKECRCH
+# include <stdio.h>
+# ifndef DYNAMIC_CRC_TABLE
+# define DYNAMIC_CRC_TABLE
+# endif /* !DYNAMIC_CRC_TABLE */
+#endif /* MAKECRCH */
+
+#include "zutil.h" /* for STDC and FAR definitions */
+
+#define local static
+
+/* Find a four-byte integer type for crc32_little() and crc32_big(). */
+#ifndef NOBYFOUR
+# ifdef STDC /* need ANSI C limits.h to determine sizes */
+# include <limits.h>
+# define BYFOUR
+# if (UINT_MAX == 0xffffffffUL)
+ typedef unsigned int u4;
+# else
+# if (ULONG_MAX == 0xffffffffUL)
+ typedef unsigned long u4;
+# else
+# if (USHRT_MAX == 0xffffffffUL)
+ typedef unsigned short u4;
+# else
+# undef BYFOUR /* can't find a four-byte integer type! */
+# endif
+# endif
+# endif
+# endif /* STDC */
+#endif /* !NOBYFOUR */
+
+/* Definitions for doing the crc four data bytes at a time. */
+#ifdef BYFOUR
+# define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
+ (((w)&0xff00)<<8)+(((w)&0xff)<<24))
+ local unsigned long crc32_little OF((unsigned long,
+ const unsigned char FAR *, unsigned));
+ local unsigned long crc32_big OF((unsigned long,
+ const unsigned char FAR *, unsigned));
+# define TBLS 8
+#else
+# define TBLS 1
+#endif /* BYFOUR */
+
+/* Local functions for crc concatenation */
+local unsigned long gf2_matrix_times OF((unsigned long *mat,
+ unsigned long vec));
+local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
+
+#ifdef DYNAMIC_CRC_TABLE
+
+local volatile int crc_table_empty = 1;
+local unsigned long FAR crc_table[TBLS][256];
+local void make_crc_table OF((void));
+#ifdef MAKECRCH
+ local void write_table OF((FILE *, const unsigned long FAR *));
+#endif /* MAKECRCH */
+/*
+ Generate tables for a byte-wise 32-bit CRC calculation on the polynomial:
+ x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
+
+ Polynomials over GF(2) are represented in binary, one bit per coefficient,
+ with the lowest powers in the most significant bit. Then adding polynomials
+ is just exclusive-or, and multiplying a polynomial by x is a right shift by
+ one. If we call the above polynomial p, and represent a byte as the
+ polynomial q, also with the lowest power in the most significant bit (so the
+ byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p,
+ where a mod b means the remainder after dividing a by b.
+
+ This calculation is done using the shift-register method of multiplying and
+ taking the remainder. The register is initialized to zero, and for each
+ incoming bit, x^32 is added mod p to the register if the bit is a one (where
+ x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by
+ x (which is shifting right by one and adding x^32 mod p if the bit shifted
+ out is a one). We start with the highest power (least significant bit) of
+ q and repeat for all eight bits of q.
+
+ The first table is simply the CRC of all possible eight bit values. This is
+ all the information needed to generate CRCs on data a byte at a time for all
+ combinations of CRC register values and incoming bytes. The remaining tables
+ allow for word-at-a-time CRC calculation for both big-endian and little-
+ endian machines, where a word is four bytes.
+*/
+local void make_crc_table()
+{
+ unsigned long c;
+ int n, k;
+ unsigned long poly; /* polynomial exclusive-or pattern */
+ /* terms of polynomial defining this crc (except x^32): */
+ static volatile int first = 1; /* flag to limit concurrent making */
+ static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
+
+ /* See if another task is already doing this (not thread-safe, but better
+ than nothing -- significantly reduces duration of vulnerability in
+ case the advice about DYNAMIC_CRC_TABLE is ignored) */
+ if (first) {
+ first = 0;
+
+ /* make exclusive-or pattern from polynomial (0xedb88320UL) */
+ poly = 0UL;
+ for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
+ poly |= 1UL << (31 - p[n]);
+
+ /* generate a crc for every 8-bit value */
+ for (n = 0; n < 256; n++) {
+ c = (unsigned long)n;
+ for (k = 0; k < 8; k++)
+ c = c & 1 ? poly ^ (c >> 1) : c >> 1;
+ crc_table[0][n] = c;
+ }
+
+#ifdef BYFOUR
+ /* generate crc for each value followed by one, two, and three zeros,
+ and then the byte reversal of those as well as the first table */
+ for (n = 0; n < 256; n++) {
+ c = crc_table[0][n];
+ crc_table[4][n] = REV(c);
+ for (k = 1; k < 4; k++) {
+ c = crc_table[0][c & 0xff] ^ (c >> 8);
+ crc_table[k][n] = c;
+ crc_table[k + 4][n] = REV(c);
+ }
+ }
+#endif /* BYFOUR */
+
+ crc_table_empty = 0;
+ }
+ else { /* not first */
+ /* wait for the other guy to finish (not efficient, but rare) */
+ while (crc_table_empty)
+ ;
+ }
+
+#ifdef MAKECRCH
+ /* write out CRC tables to crc32.h */
+ {
+ FILE *out;
+
+ out = fopen("crc32.h", "w");
+ if (out == NULL) return;
+ fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
+ fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
+ fprintf(out, "local const unsigned long FAR ");
+ fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
+ write_table(out, crc_table[0]);
+# ifdef BYFOUR
+ fprintf(out, "#ifdef BYFOUR\n");
+ for (k = 1; k < 8; k++) {
+ fprintf(out, " },\n {\n");
+ write_table(out, crc_table[k]);
+ }
+ fprintf(out, "#endif\n");
+# endif /* BYFOUR */
+ fprintf(out, " }\n};\n");
+ fclose(out);
+ }
+#endif /* MAKECRCH */
+}
+
+#ifdef MAKECRCH
+local void write_table(out, table)
+ FILE *out;
+ const unsigned long FAR *table;
+{
+ int n;
+
+ for (n = 0; n < 256; n++)
+ fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
+ n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
+}
+#endif /* MAKECRCH */
+
+#else /* !DYNAMIC_CRC_TABLE */
+/* ========================================================================
+ * Tables of CRC-32s of all single-byte values, made by make_crc_table().
+ */
+#include "crc32.h"
+#endif /* DYNAMIC_CRC_TABLE */
+
+/* =========================================================================
+ * This function can be used by asm versions of crc32()
+ */
+const unsigned long FAR * ZEXPORT get_crc_table()
+{
+#ifdef DYNAMIC_CRC_TABLE
+ if (crc_table_empty)
+ make_crc_table();
+#endif /* DYNAMIC_CRC_TABLE */
+ return (const unsigned long FAR *)crc_table;
+}
+
+/* ========================================================================= */
+#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
+#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
+
+/* ========================================================================= */
+unsigned long ZEXPORT crc32(crc, buf, len)
+ unsigned long crc;
+ const unsigned char FAR *buf;
+ unsigned len;
+{
+ if (buf == Z_NULL) return 0UL;
+
+#ifdef DYNAMIC_CRC_TABLE
+ if (crc_table_empty)
+ make_crc_table();
+#endif /* DYNAMIC_CRC_TABLE */
+
+#ifdef BYFOUR
+ if (sizeof(void *) == sizeof(ptrdiff_t)) {
+ u4 endian;
+
+ endian = 1;
+ if (*((unsigned char *)(&endian)))
+ return crc32_little(crc, buf, len);
+ else
+ return crc32_big(crc, buf, len);
+ }
+#endif /* BYFOUR */
+ crc = crc ^ 0xffffffffUL;
+ while (len >= 8) {
+ DO8;
+ len -= 8;
+ }
+ if (len) do {
+ DO1;
+ } while (--len);
+ return crc ^ 0xffffffffUL;
+}
+
+#ifdef BYFOUR
+
+/* ========================================================================= */
+#define DOLIT4 c ^= *buf4++; \
+ c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
+ crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
+#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
+
+/* ========================================================================= */
+local unsigned long crc32_little(crc, buf, len)
+ unsigned long crc;
+ const unsigned char FAR *buf;
+ unsigned len;
+{
+ register u4 c;
+ register const u4 FAR *buf4;
+
+ c = (u4)crc;
+ c = ~c;
+ while (len && ((ptrdiff_t)buf & 3)) {
+ c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
+ len--;
+ }
+
+ buf4 = (const u4 FAR *)(const void FAR *)buf;
+ while (len >= 32) {
+ DOLIT32;
+ len -= 32;
+ }
+ while (len >= 4) {
+ DOLIT4;
+ len -= 4;
+ }
+ buf = (const unsigned char FAR *)buf4;
+
+ if (len) do {
+ c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
+ } while (--len);
+ c = ~c;
+ return (unsigned long)c;
+}
+
+/* ========================================================================= */
+#define DOBIG4 c ^= *++buf4; \
+ c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
+ crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
+#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
+
+/* ========================================================================= */
+local unsigned long crc32_big(crc, buf, len)
+ unsigned long crc;
+ const unsigned char FAR *buf;
+ unsigned len;
+{
+ register u4 c;
+ register const u4 FAR *buf4;
+
+ c = REV((u4)crc);
+ c = ~c;
+ while (len && ((ptrdiff_t)buf & 3)) {
+ c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
+ len--;
+ }
+
+ buf4 = (const u4 FAR *)(const void FAR *)buf;
+ buf4--;
+ while (len >= 32) {
+ DOBIG32;
+ len -= 32;
+ }
+ while (len >= 4) {
+ DOBIG4;
+ len -= 4;
+ }
+ buf4++;
+ buf = (const unsigned char FAR *)buf4;
+
+ if (len) do {
+ c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
+ } while (--len);
+ c = ~c;
+ return (unsigned long)(REV(c));
+}
+
+#endif /* BYFOUR */
+
+#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
+
+/* ========================================================================= */
+local unsigned long gf2_matrix_times(mat, vec)
+ unsigned long *mat;
+ unsigned long vec;
+{
+ unsigned long sum;
+
+ sum = 0;
+ while (vec) {
+ if (vec & 1)
+ sum ^= *mat;
+ vec >>= 1;
+ mat++;
+ }
+ return sum;
+}
+
+/* ========================================================================= */
+local void gf2_matrix_square(square, mat)
+ unsigned long *square;
+ unsigned long *mat;
+{
+ int n;
+
+ for (n = 0; n < GF2_DIM; n++)
+ square[n] = gf2_matrix_times(mat, mat[n]);
+}
+
+/* ========================================================================= */
+uLong ZEXPORT crc32_combine(crc1, crc2, len2)
+ uLong crc1;
+ uLong crc2;
+ z_off_t len2;
+{
+ int n;
+ unsigned long row;
+ unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
+ unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
+
+ /* degenerate case */
+ if (len2 == 0)
+ return crc1;
+
+ /* put operator for one zero bit in odd */
+ odd[0] = 0xedb88320L; /* CRC-32 polynomial */
+ row = 1;
+ for (n = 1; n < GF2_DIM; n++) {
+ odd[n] = row;
+ row <<= 1;
+ }
+
+ /* put operator for two zero bits in even */
+ gf2_matrix_square(even, odd);
+
+ /* put operator for four zero bits in odd */
+ gf2_matrix_square(odd, even);
+
+ /* apply len2 zeros to crc1 (first square will put the operator for one
+ zero byte, eight zero bits, in even) */
+ do {
+ /* apply zeros operator for this bit of len2 */
+ gf2_matrix_square(even, odd);
+ if (len2 & 1)
+ crc1 = gf2_matrix_times(even, crc1);
+ len2 >>= 1;
+
+ /* if no more bits set, then done */
+ if (len2 == 0)
+ break;
+
+ /* another iteration of the loop with odd and even swapped */
+ gf2_matrix_square(odd, even);
+ if (len2 & 1)
+ crc1 = gf2_matrix_times(odd, crc1);
+ len2 >>= 1;
+
+ /* if no more bits set, then done */
+ } while (len2 != 0);
+
+ /* return combined crc */
+ crc1 ^= crc2;
+ return crc1;
+}
diff --git a/lib/libz/crc32.h b/lib/libz/crc32.h
new file mode 100644
index 0000000..8053b61
--- /dev/null
+++ b/lib/libz/crc32.h
@@ -0,0 +1,441 @@
+/* crc32.h -- tables for rapid CRC calculation
+ * Generated automatically by crc32.c
+ */
+
+local const unsigned long FAR crc_table[TBLS][256] =
+{
+ {
+ 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
+ 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
+ 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
+ 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
+ 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
+ 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
+ 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
+ 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
+ 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
+ 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
+ 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
+ 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
+ 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
+ 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
+ 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
+ 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
+ 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
+ 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
+ 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
+ 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
+ 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
+ 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
+ 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
+ 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
+ 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
+ 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
+ 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
+ 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
+ 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
+ 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
+ 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
+ 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
+ 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
+ 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
+ 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
+ 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
+ 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
+ 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
+ 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
+ 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
+ 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
+ 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
+ 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
+ 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
+ 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
+ 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
+ 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
+ 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
+ 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
+ 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
+ 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
+ 0x2d02ef8dUL
+#ifdef BYFOUR
+ },
+ {
+ 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
+ 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
+ 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
+ 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
+ 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
+ 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
+ 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
+ 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
+ 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
+ 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
+ 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
+ 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
+ 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
+ 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
+ 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
+ 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
+ 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
+ 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
+ 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
+ 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
+ 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
+ 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
+ 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
+ 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
+ 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
+ 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
+ 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
+ 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
+ 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
+ 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
+ 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
+ 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
+ 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
+ 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
+ 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
+ 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
+ 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
+ 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
+ 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
+ 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
+ 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
+ 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
+ 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
+ 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
+ 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
+ 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
+ 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
+ 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
+ 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
+ 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
+ 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
+ 0x9324fd72UL
+ },
+ {
+ 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
+ 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
+ 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
+ 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
+ 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
+ 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
+ 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
+ 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
+ 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
+ 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
+ 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
+ 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
+ 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
+ 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
+ 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
+ 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
+ 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
+ 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
+ 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
+ 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
+ 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
+ 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
+ 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
+ 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
+ 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
+ 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
+ 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
+ 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
+ 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
+ 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
+ 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
+ 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
+ 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
+ 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
+ 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
+ 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
+ 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
+ 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
+ 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
+ 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
+ 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
+ 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
+ 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
+ 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
+ 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
+ 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
+ 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
+ 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
+ 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
+ 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
+ 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
+ 0xbe9834edUL
+ },
+ {
+ 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
+ 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
+ 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
+ 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
+ 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
+ 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
+ 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
+ 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
+ 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
+ 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
+ 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
+ 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
+ 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
+ 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
+ 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
+ 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
+ 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
+ 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
+ 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
+ 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
+ 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
+ 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
+ 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
+ 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
+ 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
+ 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
+ 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
+ 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
+ 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
+ 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
+ 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
+ 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
+ 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
+ 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
+ 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
+ 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
+ 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
+ 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
+ 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
+ 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
+ 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
+ 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
+ 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
+ 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
+ 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
+ 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
+ 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
+ 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
+ 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
+ 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
+ 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
+ 0xde0506f1UL
+ },
+ {
+ 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
+ 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
+ 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
+ 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
+ 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
+ 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
+ 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
+ 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
+ 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
+ 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
+ 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
+ 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
+ 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
+ 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
+ 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
+ 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
+ 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
+ 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
+ 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
+ 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
+ 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
+ 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
+ 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
+ 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
+ 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
+ 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
+ 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
+ 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
+ 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
+ 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
+ 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
+ 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
+ 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
+ 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
+ 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
+ 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
+ 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
+ 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
+ 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
+ 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
+ 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
+ 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
+ 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
+ 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
+ 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
+ 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
+ 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
+ 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
+ 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
+ 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
+ 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
+ 0x8def022dUL
+ },
+ {
+ 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
+ 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
+ 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
+ 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
+ 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
+ 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
+ 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
+ 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
+ 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
+ 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
+ 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
+ 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
+ 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
+ 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
+ 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
+ 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
+ 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
+ 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
+ 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
+ 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
+ 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
+ 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
+ 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
+ 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
+ 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
+ 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
+ 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
+ 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
+ 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
+ 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
+ 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
+ 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
+ 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
+ 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
+ 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
+ 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
+ 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
+ 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
+ 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
+ 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
+ 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
+ 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
+ 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
+ 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
+ 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
+ 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
+ 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
+ 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
+ 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
+ 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
+ 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
+ 0x72fd2493UL
+ },
+ {
+ 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
+ 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
+ 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
+ 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
+ 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
+ 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
+ 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
+ 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
+ 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
+ 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
+ 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
+ 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
+ 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
+ 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
+ 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
+ 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
+ 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
+ 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
+ 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
+ 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
+ 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
+ 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
+ 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
+ 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
+ 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
+ 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
+ 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
+ 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
+ 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
+ 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
+ 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
+ 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
+ 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
+ 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
+ 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
+ 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
+ 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
+ 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
+ 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
+ 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
+ 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
+ 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
+ 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
+ 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
+ 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
+ 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
+ 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
+ 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
+ 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
+ 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
+ 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
+ 0xed3498beUL
+ },
+ {
+ 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
+ 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
+ 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
+ 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
+ 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
+ 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
+ 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
+ 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
+ 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
+ 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
+ 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
+ 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
+ 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
+ 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
+ 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
+ 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
+ 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
+ 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
+ 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
+ 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
+ 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
+ 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
+ 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
+ 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
+ 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
+ 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
+ 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
+ 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
+ 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
+ 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
+ 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
+ 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
+ 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
+ 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
+ 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
+ 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
+ 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
+ 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
+ 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
+ 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
+ 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
+ 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
+ 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
+ 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
+ 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
+ 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
+ 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
+ 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
+ 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
+ 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
+ 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
+ 0xf10605deUL
+#endif
+ }
+};
diff --git a/lib/libz/deflate.c b/lib/libz/deflate.c
new file mode 100644
index 0000000..5cc3f7a
--- /dev/null
+++ b/lib/libz/deflate.c
@@ -0,0 +1,1734 @@
+/* $OpenBSD: deflate.c,v 1.11 2009/10/27 23:59:31 deraadt Exp $ */
+/* deflate.c -- compress data using the deflation algorithm
+ * Copyright (C) 1995-2005 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/*
+ * ALGORITHM
+ *
+ * The "deflation" process depends on being able to identify portions
+ * of the input text which are identical to earlier input (within a
+ * sliding window trailing behind the input currently being processed).
+ *
+ * The most straightforward technique turns out to be the fastest for
+ * most input files: try all possible matches and select the longest.
+ * The key feature of this algorithm is that insertions into the string
+ * dictionary are very simple and thus fast, and deletions are avoided
+ * completely. Insertions are performed at each input character, whereas
+ * string matches are performed only when the previous match ends. So it
+ * is preferable to spend more time in matches to allow very fast string
+ * insertions and avoid deletions. The matching algorithm for small
+ * strings is inspired from that of Rabin & Karp. A brute force approach
+ * is used to find longer strings when a small match has been found.
+ * A similar algorithm is used in comic (by Jan-Mark Wams) and freeze
+ * (by Leonid Broukhis).
+ * A previous version of this file used a more sophisticated algorithm
+ * (by Fiala and Greene) which is guaranteed to run in linear amortized
+ * time, but has a larger average cost, uses more memory and is patented.
+ * However the F&G algorithm may be faster for some highly redundant
+ * files if the parameter max_chain_length (described below) is too large.
+ *
+ * ACKNOWLEDGEMENTS
+ *
+ * The idea of lazy evaluation of matches is due to Jan-Mark Wams, and
+ * I found it in 'freeze' written by Leonid Broukhis.
+ * Thanks to many people for bug reports and testing.
+ *
+ * REFERENCES
+ *
+ * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification".
+ * Available in http://www.ietf.org/rfc/rfc1951.txt
+ *
+ * A description of the Rabin and Karp algorithm is given in the book
+ * "Algorithms" by R. Sedgewick, Addison-Wesley, p252.
+ *
+ * Fiala,E.R., and Greene,D.H.
+ * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595
+ *
+ */
+
+
+#include "deflate.h"
+
+/*
+ If you use the zlib library in a product, an acknowledgment is welcome
+ in the documentation of your product. If for some reason you cannot
+ include such an acknowledgment, I would appreciate that you keep this
+ copyright string in the executable of your product.
+ */
+
+/* ===========================================================================
+ * Function prototypes.
+ */
+typedef enum {
+ need_more, /* block not completed, need more input or more output */
+ block_done, /* block flush performed */
+ finish_started, /* finish started, need only more output at next deflate */
+ finish_done /* finish done, accept no more input or output */
+} block_state;
+
+typedef block_state (*compress_func) OF((deflate_state *s, int flush));
+/* Compression function. Returns the block state after the call. */
+
+local void fill_window OF((deflate_state *s));
+local block_state deflate_stored OF((deflate_state *s, int flush));
+local block_state deflate_fast OF((deflate_state *s, int flush));
+#ifndef FASTEST
+local block_state deflate_slow OF((deflate_state *s, int flush));
+#endif
+local void lm_init OF((deflate_state *s));
+local void putShortMSB OF((deflate_state *s, uInt b));
+local void flush_pending OF((z_streamp strm));
+local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
+#ifndef FASTEST
+#ifdef ASMV
+ void match_init OF((void)); /* asm code initialization */
+ uInt longest_match OF((deflate_state *s, IPos cur_match));
+#else
+local uInt longest_match OF((deflate_state *s, IPos cur_match));
+#endif
+#endif
+local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
+
+#ifdef DEBUG
+local void check_match OF((deflate_state *s, IPos start, IPos match,
+ int length));
+#endif
+
+/* ===========================================================================
+ * Local data
+ */
+
+#define NIL 0
+/* Tail of hash chains */
+
+#ifndef TOO_FAR
+# define TOO_FAR 4096
+#endif
+/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */
+
+#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
+/* Minimum amount of lookahead, except at the end of the input file.
+ * See deflate.c for comments about the MIN_MATCH+1.
+ */
+
+/* Values for max_lazy_match, good_match and max_chain_length, depending on
+ * the desired pack level (0..9). The values given below have been tuned to
+ * exclude worst case performance for pathological files. Better values may be
+ * found for specific files.
+ */
+typedef struct config_s {
+ ush good_length; /* reduce lazy search above this match length */
+ ush max_lazy; /* do not perform lazy search above this match length */
+ ush nice_length; /* quit search above this match length */
+ ush max_chain;
+ compress_func func;
+} config;
+
+#ifdef FASTEST
+local const config configuration_table[2] = {
+/* good lazy nice chain */
+/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */
+/* 1 */ {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
+#else
+local const config configuration_table[10] = {
+/* good lazy nice chain */
+/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */
+/* 1 */ {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
+/* 2 */ {4, 5, 16, 8, deflate_fast},
+/* 3 */ {4, 6, 32, 32, deflate_fast},
+
+/* 4 */ {4, 4, 16, 16, deflate_slow}, /* lazy matches */
+/* 5 */ {8, 16, 32, 32, deflate_slow},
+/* 6 */ {8, 16, 128, 128, deflate_slow},
+/* 7 */ {8, 32, 128, 256, deflate_slow},
+/* 8 */ {32, 128, 258, 1024, deflate_slow},
+/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* max compression */
+#endif
+
+/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4
+ * For deflate_fast() (levels <= 3) good is ignored and lazy has a different
+ * meaning.
+ */
+
+#define EQUAL 0
+/* result of memcmp for equal strings */
+
+#ifndef NO_DUMMY_DECL
+struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
+#endif
+
+/* ===========================================================================
+ * Update a hash value with the given input byte
+ * IN assertion: all calls to UPDATE_HASH are made with consecutive
+ * input characters, so that a running hash key can be computed from the
+ * previous key instead of complete recalculation each time.
+ */
+#define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
+
+
+/* ===========================================================================
+ * Insert string str in the dictionary and set match_head to the previous head
+ * of the hash chain (the most recent string with same hash key). Return
+ * the previous length of the hash chain.
+ * If this file is compiled with -DFASTEST, the compression level is forced
+ * to 1, and no hash chains are maintained.
+ * IN assertion: all calls to INSERT_STRING are made with consecutive
+ * input characters and the first MIN_MATCH bytes of str are valid
+ * (except for the last MIN_MATCH-1 bytes of the input file).
+ */
+#ifdef FASTEST
+#define INSERT_STRING(s, str, match_head) \
+ (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
+ match_head = s->head[s->ins_h], \
+ s->head[s->ins_h] = (Pos)(str))
+#else
+#define INSERT_STRING(s, str, match_head) \
+ (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
+ match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
+ s->head[s->ins_h] = (Pos)(str))
+#endif
+
+/* ===========================================================================
+ * Initialize the hash table (avoiding 64K overflow for 16 bit systems).
+ * prev[] will be initialized on the fly.
+ */
+#define CLEAR_HASH(s) \
+ s->head[s->hash_size-1] = NIL; \
+ zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
+
+/* ========================================================================= */
+int ZEXPORT deflateInit_(strm, level, version, stream_size)
+ z_streamp strm;
+ int level;
+ const char *version;
+ int stream_size;
+{
+ return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
+ Z_DEFAULT_STRATEGY, version, stream_size);
+ /* To do: ignore strm->next_in if we use it as window */
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy,
+ version, stream_size)
+ z_streamp strm;
+ int level;
+ int method;
+ int windowBits;
+ int memLevel;
+ int strategy;
+ const char *version;
+ int stream_size;
+{
+ deflate_state *s;
+ int wrap = 1;
+ static const char my_version[] = ZLIB_VERSION;
+
+ ushf *overlay;
+ /* We overlay pending_buf and d_buf+l_buf. This works since the average
+ * output size for (length,distance) codes is <= 24 bits.
+ */
+
+ if (version == Z_NULL || version[0] != my_version[0] ||
+ stream_size != sizeof(z_stream)) {
+ return Z_VERSION_ERROR;
+ }
+ if (strm == Z_NULL) return Z_STREAM_ERROR;
+
+ strm->msg = Z_NULL;
+ if (strm->zalloc == (alloc_func)0) {
+ strm->zalloc = zcalloc;
+ strm->opaque = (voidpf)0;
+ }
+ if (strm->zfree == (free_func)0) strm->zfree = zcfree;
+
+#ifdef FASTEST
+ if (level != 0) level = 1;
+#else
+ if (level == Z_DEFAULT_COMPRESSION) level = 6;
+#endif
+
+ if (windowBits < 0) { /* suppress zlib wrapper */
+ wrap = 0;
+ windowBits = -windowBits;
+ }
+#ifdef GZIP
+ else if (windowBits > 15) {
+ wrap = 2; /* write gzip wrapper instead */
+ windowBits -= 16;
+ }
+#endif
+ if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
+ windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
+ strategy < 0 || strategy > Z_FIXED) {
+ return Z_STREAM_ERROR;
+ }
+ if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
+ s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
+ if (s == Z_NULL) return Z_MEM_ERROR;
+ strm->state = (struct internal_state FAR *)s;
+ s->strm = strm;
+
+ s->wrap = wrap;
+ s->gzhead = Z_NULL;
+ s->w_bits = windowBits;
+ s->w_size = 1 << s->w_bits;
+ s->w_mask = s->w_size - 1;
+
+ s->hash_bits = memLevel + 7;
+ s->hash_size = 1 << s->hash_bits;
+ s->hash_mask = s->hash_size - 1;
+ s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
+
+ s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
+ s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
+ s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
+
+ s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
+
+ overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
+ s->pending_buf = (uchf *) overlay;
+ s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
+
+ if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
+ s->pending_buf == Z_NULL) {
+ s->status = FINISH_STATE;
+ strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
+ deflateEnd (strm);
+ return Z_MEM_ERROR;
+ }
+ s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
+ s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
+
+ s->level = level;
+ s->strategy = strategy;
+ s->method = (Byte)method;
+
+ return deflateReset(strm);
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength)
+ z_streamp strm;
+ const Bytef *dictionary;
+ uInt dictLength;
+{
+ deflate_state *s;
+ uInt length = dictLength;
+ uInt n;
+ IPos hash_head = 0;
+
+ if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
+ strm->state->wrap == 2 ||
+ (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
+ return Z_STREAM_ERROR;
+
+ s = strm->state;
+ if (s->wrap)
+ strm->adler = adler32(strm->adler, dictionary, dictLength);
+
+ if (length < MIN_MATCH) return Z_OK;
+ if (length > MAX_DIST(s)) {
+ length = MAX_DIST(s);
+ dictionary += dictLength - length; /* use the tail of the dictionary */
+ }
+ zmemcpy(s->window, dictionary, length);
+ s->strstart = length;
+ s->block_start = (long)length;
+
+ /* Insert all strings in the hash table (except for the last two bytes).
+ * s->lookahead stays null, so s->ins_h will be recomputed at the next
+ * call of fill_window.
+ */
+ s->ins_h = s->window[0];
+ UPDATE_HASH(s, s->ins_h, s->window[1]);
+ for (n = 0; n <= length - MIN_MATCH; n++) {
+ INSERT_STRING(s, n, hash_head);
+ }
+ if (hash_head) hash_head = 0; /* to make compiler happy */
+ return Z_OK;
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateReset (strm)
+ z_streamp strm;
+{
+ deflate_state *s;
+
+ if (strm == Z_NULL || strm->state == Z_NULL ||
+ strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
+ return Z_STREAM_ERROR;
+ }
+
+ strm->total_in = strm->total_out = 0;
+ strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
+ strm->data_type = Z_UNKNOWN;
+
+ s = (deflate_state *)strm->state;
+ s->pending = 0;
+ s->pending_out = s->pending_buf;
+
+ if (s->wrap < 0) {
+ s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
+ }
+ s->status = s->wrap ? INIT_STATE : BUSY_STATE;
+ strm->adler =
+#ifdef GZIP
+ s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
+#endif
+ adler32(0L, Z_NULL, 0);
+ s->last_flush = Z_NO_FLUSH;
+
+ _tr_init(s);
+ lm_init(s);
+
+ return Z_OK;
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateSetHeader (strm, head)
+ z_streamp strm;
+ gz_headerp head;
+{
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ if (strm->state->wrap != 2) return Z_STREAM_ERROR;
+ strm->state->gzhead = head;
+ return Z_OK;
+}
+
+/* ========================================================================= */
+int ZEXPORT deflatePrime (strm, bits, value)
+ z_streamp strm;
+ int bits;
+ int value;
+{
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ strm->state->bi_valid = bits;
+ strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
+ return Z_OK;
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateParams(strm, level, strategy)
+ z_streamp strm;
+ int level;
+ int strategy;
+{
+ deflate_state *s;
+ compress_func func;
+ int err = Z_OK;
+
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ s = strm->state;
+
+#ifdef FASTEST
+ if (level != 0) level = 1;
+#else
+ if (level == Z_DEFAULT_COMPRESSION) level = 6;
+#endif
+ if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
+ return Z_STREAM_ERROR;
+ }
+ func = configuration_table[s->level].func;
+
+ if (func != configuration_table[level].func && strm->total_in != 0) {
+ /* Flush the last buffer: */
+ err = deflate(strm, Z_PARTIAL_FLUSH);
+ }
+ if (s->level != level) {
+ s->level = level;
+ s->max_lazy_match = configuration_table[level].max_lazy;
+ s->good_match = configuration_table[level].good_length;
+ s->nice_match = configuration_table[level].nice_length;
+ s->max_chain_length = configuration_table[level].max_chain;
+ }
+ s->strategy = strategy;
+ return err;
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain)
+ z_streamp strm;
+ int good_length;
+ int max_lazy;
+ int nice_length;
+ int max_chain;
+{
+ deflate_state *s;
+
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ s = strm->state;
+ s->good_match = good_length;
+ s->max_lazy_match = max_lazy;
+ s->nice_match = nice_length;
+ s->max_chain_length = max_chain;
+ return Z_OK;
+}
+
+/* =========================================================================
+ * For the default windowBits of 15 and memLevel of 8, this function returns
+ * a close to exact, as well as small, upper bound on the compressed size.
+ * They are coded as constants here for a reason--if the #define's are
+ * changed, then this function needs to be changed as well. The return
+ * value for 15 and 8 only works for those exact settings.
+ *
+ * For any setting other than those defaults for windowBits and memLevel,
+ * the value returned is a conservative worst case for the maximum expansion
+ * resulting from using fixed blocks instead of stored blocks, which deflate
+ * can emit on compressed data for some combinations of the parameters.
+ *
+ * This function could be more sophisticated to provide closer upper bounds
+ * for every combination of windowBits and memLevel, as well as wrap.
+ * But even the conservative upper bound of about 14% expansion does not
+ * seem onerous for output buffer allocation.
+ */
+uLong ZEXPORT deflateBound(strm, sourceLen)
+ z_streamp strm;
+ uLong sourceLen;
+{
+ deflate_state *s;
+ uLong destLen;
+
+ /* conservative upper bound */
+ destLen = sourceLen +
+ ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
+
+ /* if can't get parameters, return conservative bound */
+ if (strm == Z_NULL || strm->state == Z_NULL)
+ return destLen;
+
+ /* if not default parameters, return conservative bound */
+ s = strm->state;
+ if (s->w_bits != 15 || s->hash_bits != 8 + 7)
+ return destLen;
+
+ /* default settings: return tight bound for that case */
+ return compressBound(sourceLen);
+}
+
+/* =========================================================================
+ * Put a short in the pending buffer. The 16-bit value is put in MSB order.
+ * IN assertion: the stream state is correct and there is enough room in
+ * pending_buf.
+ */
+local void putShortMSB (s, b)
+ deflate_state *s;
+ uInt b;
+{
+ put_byte(s, (Byte)(b >> 8));
+ put_byte(s, (Byte)(b & 0xff));
+}
+
+/* =========================================================================
+ * Flush as much pending output as possible. All deflate() output goes
+ * through this function so some applications may wish to modify it
+ * to avoid allocating a large strm->next_out buffer and copying into it.
+ * (See also read_buf()).
+ */
+local void flush_pending(strm)
+ z_streamp strm;
+{
+ unsigned len = strm->state->pending;
+
+ if (len > strm->avail_out) len = strm->avail_out;
+ if (len == 0) return;
+
+ zmemcpy(strm->next_out, strm->state->pending_out, len);
+ strm->next_out += len;
+ strm->state->pending_out += len;
+ strm->total_out += len;
+ strm->avail_out -= len;
+ strm->state->pending -= len;
+ if (strm->state->pending == 0) {
+ strm->state->pending_out = strm->state->pending_buf;
+ }
+}
+
+/* ========================================================================= */
+int ZEXPORT deflate (strm, flush)
+ z_streamp strm;
+ int flush;
+{
+ int old_flush; /* value of flush param for previous deflate call */
+ deflate_state *s;
+
+ if (strm == Z_NULL || strm->state == Z_NULL ||
+ flush > Z_FINISH || flush < 0) {
+ return Z_STREAM_ERROR;
+ }
+ s = strm->state;
+
+ if (strm->next_out == Z_NULL ||
+ (strm->next_in == Z_NULL && strm->avail_in != 0) ||
+ (s->status == FINISH_STATE && flush != Z_FINISH)) {
+ ERR_RETURN(strm, Z_STREAM_ERROR);
+ }
+ if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
+
+ s->strm = strm; /* just in case */
+ old_flush = s->last_flush;
+ s->last_flush = flush;
+
+ /* Write the header */
+ if (s->status == INIT_STATE) {
+#ifdef GZIP
+ if (s->wrap == 2) {
+ strm->adler = crc32(0L, Z_NULL, 0);
+ put_byte(s, 31);
+ put_byte(s, 139);
+ put_byte(s, 8);
+ if (s->gzhead == NULL) {
+ put_byte(s, 0);
+ put_byte(s, 0);
+ put_byte(s, 0);
+ put_byte(s, 0);
+ put_byte(s, 0);
+ put_byte(s, s->level == 9 ? 2 :
+ (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
+ 4 : 0));
+ put_byte(s, OS_CODE);
+ s->status = BUSY_STATE;
+ }
+ else {
+ put_byte(s, (s->gzhead->text ? 1 : 0) +
+ (s->gzhead->hcrc ? 2 : 0) +
+ (s->gzhead->extra == Z_NULL ? 0 : 4) +
+ (s->gzhead->name == Z_NULL ? 0 : 8) +
+ (s->gzhead->comment == Z_NULL ? 0 : 16)
+ );
+ put_byte(s, (Byte)(s->gzhead->time & 0xff));
+ put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
+ put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
+ put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
+ put_byte(s, s->level == 9 ? 2 :
+ (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
+ 4 : 0));
+ put_byte(s, s->gzhead->os & 0xff);
+ if (s->gzhead->extra != NULL) {
+ put_byte(s, s->gzhead->extra_len & 0xff);
+ put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
+ }
+ if (s->gzhead->hcrc)
+ strm->adler = crc32(strm->adler, s->pending_buf,
+ s->pending);
+ s->gzindex = 0;
+ s->status = EXTRA_STATE;
+ }
+ }
+ else
+#endif
+ {
+ uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
+ uInt level_flags;
+
+ if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
+ level_flags = 0;
+ else if (s->level < 6)
+ level_flags = 1;
+ else if (s->level == 6)
+ level_flags = 2;
+ else
+ level_flags = 3;
+ header |= (level_flags << 6);
+ if (s->strstart != 0) header |= PRESET_DICT;
+ header += 31 - (header % 31);
+
+ s->status = BUSY_STATE;
+ putShortMSB(s, header);
+
+ /* Save the adler32 of the preset dictionary: */
+ if (s->strstart != 0) {
+ putShortMSB(s, (uInt)(strm->adler >> 16));
+ putShortMSB(s, (uInt)(strm->adler & 0xffff));
+ }
+ strm->adler = adler32(0L, Z_NULL, 0);
+ }
+ }
+#ifdef GZIP
+ if (s->status == EXTRA_STATE) {
+ if (s->gzhead->extra != NULL) {
+ uInt beg = s->pending; /* start of bytes to update crc */
+
+ while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
+ if (s->pending == s->pending_buf_size) {
+ if (s->gzhead->hcrc && s->pending > beg)
+ strm->adler = crc32(strm->adler, s->pending_buf + beg,
+ s->pending - beg);
+ flush_pending(strm);
+ beg = s->pending;
+ if (s->pending == s->pending_buf_size)
+ break;
+ }
+ put_byte(s, s->gzhead->extra[s->gzindex]);
+ s->gzindex++;
+ }
+ if (s->gzhead->hcrc && s->pending > beg)
+ strm->adler = crc32(strm->adler, s->pending_buf + beg,
+ s->pending - beg);
+ if (s->gzindex == s->gzhead->extra_len) {
+ s->gzindex = 0;
+ s->status = NAME_STATE;
+ }
+ }
+ else
+ s->status = NAME_STATE;
+ }
+ if (s->status == NAME_STATE) {
+ if (s->gzhead->name != NULL) {
+ uInt beg = s->pending; /* start of bytes to update crc */
+ int val;
+
+ do {
+ if (s->pending == s->pending_buf_size) {
+ if (s->gzhead->hcrc && s->pending > beg)
+ strm->adler = crc32(strm->adler, s->pending_buf + beg,
+ s->pending - beg);
+ flush_pending(strm);
+ beg = s->pending;
+ if (s->pending == s->pending_buf_size) {
+ val = 1;
+ break;
+ }
+ }
+ val = s->gzhead->name[s->gzindex++];
+ put_byte(s, val);
+ } while (val != 0);
+ if (s->gzhead->hcrc && s->pending > beg)
+ strm->adler = crc32(strm->adler, s->pending_buf + beg,
+ s->pending - beg);
+ if (val == 0) {
+ s->gzindex = 0;
+ s->status = COMMENT_STATE;
+ }
+ }
+ else
+ s->status = COMMENT_STATE;
+ }
+ if (s->status == COMMENT_STATE) {
+ if (s->gzhead->comment != NULL) {
+ uInt beg = s->pending; /* start of bytes to update crc */
+ int val;
+
+ do {
+ if (s->pending == s->pending_buf_size) {
+ if (s->gzhead->hcrc && s->pending > beg)
+ strm->adler = crc32(strm->adler, s->pending_buf + beg,
+ s->pending - beg);
+ flush_pending(strm);
+ beg = s->pending;
+ if (s->pending == s->pending_buf_size) {
+ val = 1;
+ break;
+ }
+ }
+ val = s->gzhead->comment[s->gzindex++];
+ put_byte(s, val);
+ } while (val != 0);
+ if (s->gzhead->hcrc && s->pending > beg)
+ strm->adler = crc32(strm->adler, s->pending_buf + beg,
+ s->pending - beg);
+ if (val == 0)
+ s->status = HCRC_STATE;
+ }
+ else
+ s->status = HCRC_STATE;
+ }
+ if (s->status == HCRC_STATE) {
+ if (s->gzhead->hcrc) {
+ if (s->pending + 2 > s->pending_buf_size)
+ flush_pending(strm);
+ if (s->pending + 2 <= s->pending_buf_size) {
+ put_byte(s, (Byte)(strm->adler & 0xff));
+ put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
+ strm->adler = crc32(0L, Z_NULL, 0);
+ s->status = BUSY_STATE;
+ }
+ }
+ else
+ s->status = BUSY_STATE;
+ }
+#endif
+
+ /* Flush as much pending output as possible */
+ if (s->pending != 0) {
+ flush_pending(strm);
+ if (strm->avail_out == 0) {
+ /* Since avail_out is 0, deflate will be called again with
+ * more output space, but possibly with both pending and
+ * avail_in equal to zero. There won't be anything to do,
+ * but this is not an error situation so make sure we
+ * return OK instead of BUF_ERROR at next call of deflate:
+ */
+ s->last_flush = -1;
+ return Z_OK;
+ }
+
+ /* Make sure there is something to do and avoid duplicate consecutive
+ * flushes. For repeated and useless calls with Z_FINISH, we keep
+ * returning Z_STREAM_END instead of Z_BUF_ERROR.
+ */
+ } else if (strm->avail_in == 0 && flush <= old_flush &&
+ flush != Z_FINISH) {
+ ERR_RETURN(strm, Z_BUF_ERROR);
+ }
+
+ /* User must not provide more input after the first FINISH: */
+ if (s->status == FINISH_STATE && strm->avail_in != 0) {
+ ERR_RETURN(strm, Z_BUF_ERROR);
+ }
+
+ /* Start a new block or continue the current one.
+ */
+ if (strm->avail_in != 0 || s->lookahead != 0 ||
+ (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
+ block_state bstate;
+
+ bstate = (*(configuration_table[s->level].func))(s, flush);
+
+ if (bstate == finish_started || bstate == finish_done) {
+ s->status = FINISH_STATE;
+ }
+ if (bstate == need_more || bstate == finish_started) {
+ if (strm->avail_out == 0) {
+ s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
+ }
+ return Z_OK;
+ /* If flush != Z_NO_FLUSH && avail_out == 0, the next call
+ * of deflate should use the same flush parameter to make sure
+ * that the flush is complete. So we don't have to output an
+ * empty block here, this will be done at next call. This also
+ * ensures that for a very small output buffer, we emit at most
+ * one empty block.
+ */
+ }
+ if (bstate == block_done) {
+ if (flush == Z_PARTIAL_FLUSH) {
+ _tr_align(s);
+ } else { /* FULL_FLUSH or SYNC_FLUSH */
+ _tr_stored_block(s, (char*)0, 0L, 0);
+ /* For a full flush, this empty block will be recognized
+ * as a special marker by inflate_sync().
+ */
+ if (flush == Z_FULL_FLUSH) {
+ CLEAR_HASH(s); /* forget history */
+ }
+ }
+ flush_pending(strm);
+ if (strm->avail_out == 0) {
+ s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
+ return Z_OK;
+ }
+ }
+ }
+ Assert(strm->avail_out > 0, "bug2");
+
+ if (flush != Z_FINISH) return Z_OK;
+ if (s->wrap <= 0) return Z_STREAM_END;
+
+ /* Write the trailer */
+#ifdef GZIP
+ if (s->wrap == 2) {
+ put_byte(s, (Byte)(strm->adler & 0xff));
+ put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
+ put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
+ put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
+ put_byte(s, (Byte)(strm->total_in & 0xff));
+ put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
+ put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
+ put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
+ }
+ else
+#endif
+ {
+ putShortMSB(s, (uInt)(strm->adler >> 16));
+ putShortMSB(s, (uInt)(strm->adler & 0xffff));
+ }
+ flush_pending(strm);
+ /* If avail_out is zero, the application will call deflate again
+ * to flush the rest.
+ */
+ if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
+ return s->pending != 0 ? Z_OK : Z_STREAM_END;
+}
+
+/* ========================================================================= */
+int ZEXPORT deflateEnd (strm)
+ z_streamp strm;
+{
+ int status;
+
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+
+ status = strm->state->status;
+ if (status != INIT_STATE &&
+ status != EXTRA_STATE &&
+ status != NAME_STATE &&
+ status != COMMENT_STATE &&
+ status != HCRC_STATE &&
+ status != BUSY_STATE &&
+ status != FINISH_STATE) {
+ return Z_STREAM_ERROR;
+ }
+
+ /* Deallocate in reverse order of allocations: */
+ TRY_FREE(strm, strm->state->pending_buf);
+ TRY_FREE(strm, strm->state->head);
+ TRY_FREE(strm, strm->state->prev);
+ TRY_FREE(strm, strm->state->window);
+
+ ZFREE(strm, strm->state);
+ strm->state = Z_NULL;
+
+ return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
+}
+
+/* =========================================================================
+ * Copy the source state to the destination state.
+ * To simplify the source, this is not supported for 16-bit MSDOS (which
+ * doesn't have enough memory anyway to duplicate compression states).
+ */
+int ZEXPORT deflateCopy (dest, source)
+ z_streamp dest;
+ z_streamp source;
+{
+#ifdef MAXSEG_64K
+ return Z_STREAM_ERROR;
+#else
+ deflate_state *ds;
+ deflate_state *ss;
+ ushf *overlay;
+
+
+ if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
+ return Z_STREAM_ERROR;
+ }
+
+ ss = source->state;
+
+ zmemcpy(dest, source, sizeof(z_stream));
+
+ ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
+ if (ds == Z_NULL) return Z_MEM_ERROR;
+ dest->state = (struct internal_state FAR *) ds;
+ zmemcpy(ds, ss, sizeof(deflate_state));
+ ds->strm = dest;
+
+ ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
+ ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
+ ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
+ overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
+ ds->pending_buf = (uchf *) overlay;
+
+ if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
+ ds->pending_buf == Z_NULL) {
+ deflateEnd (dest);
+ return Z_MEM_ERROR;
+ }
+ /* following zmemcpy do not work for 16-bit MSDOS */
+ zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
+ zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
+ zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
+ zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
+
+ ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
+ ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
+ ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
+
+ ds->l_desc.dyn_tree = ds->dyn_ltree;
+ ds->d_desc.dyn_tree = ds->dyn_dtree;
+ ds->bl_desc.dyn_tree = ds->bl_tree;
+
+ return Z_OK;
+#endif /* MAXSEG_64K */
+}
+
+/* ===========================================================================
+ * Read a new buffer from the current input stream, update the adler32
+ * and total number of bytes read. All deflate() input goes through
+ * this function so some applications may wish to modify it to avoid
+ * allocating a large strm->next_in buffer and copying from it.
+ * (See also flush_pending()).
+ */
+local int read_buf(strm, buf, size)
+ z_streamp strm;
+ Bytef *buf;
+ unsigned size;
+{
+ unsigned len = strm->avail_in;
+
+ if (len > size) len = size;
+ if (len == 0) return 0;
+
+ strm->avail_in -= len;
+
+ if (strm->state->wrap == 1) {
+ strm->adler = adler32(strm->adler, strm->next_in, len);
+ }
+#ifdef GZIP
+ else if (strm->state->wrap == 2) {
+ strm->adler = crc32(strm->adler, strm->next_in, len);
+ }
+#endif
+ zmemcpy(buf, strm->next_in, len);
+ strm->next_in += len;
+ strm->total_in += len;
+
+ return (int)len;
+}
+
+/* ===========================================================================
+ * Initialize the "longest match" routines for a new zlib stream
+ */
+local void lm_init (s)
+ deflate_state *s;
+{
+ s->window_size = (ulg)2L*s->w_size;
+
+ CLEAR_HASH(s);
+
+ /* Set the default configuration parameters:
+ */
+ s->max_lazy_match = configuration_table[s->level].max_lazy;
+ s->good_match = configuration_table[s->level].good_length;
+ s->nice_match = configuration_table[s->level].nice_length;
+ s->max_chain_length = configuration_table[s->level].max_chain;
+
+ s->strstart = 0;
+ s->block_start = 0L;
+ s->lookahead = 0;
+ s->match_length = s->prev_length = MIN_MATCH-1;
+ s->match_available = 0;
+ s->ins_h = 0;
+#ifndef FASTEST
+#ifdef ASMV
+ match_init(); /* initialize the asm code */
+#endif
+#endif
+}
+
+#ifndef FASTEST
+/* ===========================================================================
+ * Set match_start to the longest match starting at the given string and
+ * return its length. Matches shorter or equal to prev_length are discarded,
+ * in which case the result is equal to prev_length and match_start is
+ * garbage.
+ * IN assertions: cur_match is the head of the hash chain for the current
+ * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1
+ * OUT assertion: the match length is not greater than s->lookahead.
+ */
+#ifndef ASMV
+/* For 80x86 and 680x0, an optimized version will be provided in match.asm or
+ * match.S. The code will be functionally equivalent.
+ */
+local uInt longest_match(s, cur_match)
+ deflate_state *s;
+ IPos cur_match; /* current match */
+{
+ unsigned chain_length = s->max_chain_length;/* max hash chain length */
+ register Bytef *scan = s->window + s->strstart; /* current string */
+ register Bytef *match; /* matched string */
+ register int len; /* length of current match */
+ int best_len = s->prev_length; /* best match length so far */
+ int nice_match = s->nice_match; /* stop if match long enough */
+ IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
+ s->strstart - (IPos)MAX_DIST(s) : NIL;
+ /* Stop when cur_match becomes <= limit. To simplify the code,
+ * we prevent matches with the string of window index 0.
+ */
+ Posf *prev = s->prev;
+ uInt wmask = s->w_mask;
+
+#ifdef UNALIGNED_OK
+ /* Compare two bytes at a time. Note: this is not always beneficial.
+ * Try with and without -DUNALIGNED_OK to check.
+ */
+ register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
+ register ush scan_start = *(ushf*)scan;
+ register ush scan_end = *(ushf*)(scan+best_len-1);
+#else
+ register Bytef *strend = s->window + s->strstart + MAX_MATCH;
+ register Byte scan_end1 = scan[best_len-1];
+ register Byte scan_end = scan[best_len];
+#endif
+
+ /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
+ * It is easy to get rid of this optimization if necessary.
+ */
+ Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
+
+ /* Do not waste too much time if we already have a good match: */
+ if (s->prev_length >= s->good_match) {
+ chain_length >>= 2;
+ }
+ /* Do not look for matches beyond the end of the input. This is necessary
+ * to make deflate deterministic.
+ */
+ if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
+
+ Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
+
+ do {
+ Assert(cur_match < s->strstart, "no future");
+ match = s->window + cur_match;
+
+ /* Skip to next match if the match length cannot increase
+ * or if the match length is less than 2. Note that the checks below
+ * for insufficient lookahead only occur occasionally for performance
+ * reasons. Therefore uninitialized memory will be accessed, and
+ * conditional jumps will be made that depend on those values.
+ * However the length of the match is limited to the lookahead, so
+ * the output of deflate is not affected by the uninitialized values.
+ */
+#if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
+ /* This code assumes sizeof(unsigned short) == 2. Do not use
+ * UNALIGNED_OK if your compiler uses a different size.
+ */
+ if (*(ushf*)(match+best_len-1) != scan_end ||
+ *(ushf*)match != scan_start) continue;
+
+ /* It is not necessary to compare scan[2] and match[2] since they are
+ * always equal when the other bytes match, given that the hash keys
+ * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at
+ * strstart+3, +5, ... up to strstart+257. We check for insufficient
+ * lookahead only every 4th comparison; the 128th check will be made
+ * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is
+ * necessary to put more guard bytes at the end of the window, or
+ * to check more often for insufficient lookahead.
+ */
+ Assert(scan[2] == match[2], "scan[2]?");
+ scan++, match++;
+ do {
+ } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
+ *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
+ *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
+ *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
+ scan < strend);
+ /* The funny "do {}" generates better code on most compilers */
+
+ /* Here, scan <= window+strstart+257 */
+ Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
+ if (*scan == *match) scan++;
+
+ len = (MAX_MATCH - 1) - (int)(strend-scan);
+ scan = strend - (MAX_MATCH-1);
+
+#else /* UNALIGNED_OK */
+
+ if (match[best_len] != scan_end ||
+ match[best_len-1] != scan_end1 ||
+ *match != *scan ||
+ *++match != scan[1]) continue;
+
+ /* The check at best_len-1 can be removed because it will be made
+ * again later. (This heuristic is not always a win.)
+ * It is not necessary to compare scan[2] and match[2] since they
+ * are always equal when the other bytes match, given that
+ * the hash keys are equal and that HASH_BITS >= 8.
+ */
+ scan += 2, match++;
+ Assert(*scan == *match, "match[2]?");
+
+ /* We check for insufficient lookahead only every 8th comparison;
+ * the 256th check will be made at strstart+258.
+ */
+ do {
+ } while (*++scan == *++match && *++scan == *++match &&
+ *++scan == *++match && *++scan == *++match &&
+ *++scan == *++match && *++scan == *++match &&
+ *++scan == *++match && *++scan == *++match &&
+ scan < strend);
+
+ Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
+
+ len = MAX_MATCH - (int)(strend - scan);
+ scan = strend - MAX_MATCH;
+
+#endif /* UNALIGNED_OK */
+
+ if (len > best_len) {
+ s->match_start = cur_match;
+ best_len = len;
+ if (len >= nice_match) break;
+#ifdef UNALIGNED_OK
+ scan_end = *(ushf*)(scan+best_len-1);
+#else
+ scan_end1 = scan[best_len-1];
+ scan_end = scan[best_len];
+#endif
+ }
+ } while ((cur_match = prev[cur_match & wmask]) > limit
+ && --chain_length != 0);
+
+ if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
+ return s->lookahead;
+}
+#endif /* ASMV */
+#endif /* FASTEST */
+
+/* ---------------------------------------------------------------------------
+ * Optimized version for level == 1 or strategy == Z_RLE only
+ */
+local uInt longest_match_fast(s, cur_match)
+ deflate_state *s;
+ IPos cur_match; /* current match */
+{
+ register Bytef *scan = s->window + s->strstart; /* current string */
+ register Bytef *match; /* matched string */
+ register int len; /* length of current match */
+ register Bytef *strend = s->window + s->strstart + MAX_MATCH;
+
+ /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16.
+ * It is easy to get rid of this optimization if necessary.
+ */
+ Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
+
+ Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
+
+ Assert(cur_match < s->strstart, "no future");
+
+ match = s->window + cur_match;
+
+ /* Return failure if the match length is less than 2:
+ */
+ if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
+
+ /* The check at best_len-1 can be removed because it will be made
+ * again later. (This heuristic is not always a win.)
+ * It is not necessary to compare scan[2] and match[2] since they
+ * are always equal when the other bytes match, given that
+ * the hash keys are equal and that HASH_BITS >= 8.
+ */
+ scan += 2, match += 2;
+ Assert(*scan == *match, "match[2]?");
+
+ /* We check for insufficient lookahead only every 8th comparison;
+ * the 256th check will be made at strstart+258.
+ */
+ do {
+ } while (*++scan == *++match && *++scan == *++match &&
+ *++scan == *++match && *++scan == *++match &&
+ *++scan == *++match && *++scan == *++match &&
+ *++scan == *++match && *++scan == *++match &&
+ scan < strend);
+
+ Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
+
+ len = MAX_MATCH - (int)(strend - scan);
+
+ if (len < MIN_MATCH) return MIN_MATCH - 1;
+
+ s->match_start = cur_match;
+ return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
+}
+
+#ifdef DEBUG
+/* ===========================================================================
+ * Check that the match at match_start is indeed a match.
+ */
+local void check_match(s, start, match, length)
+ deflate_state *s;
+ IPos start, match;
+ int length;
+{
+ /* check that the match is indeed a match */
+ if (zmemcmp(s->window + match,
+ s->window + start, length) != EQUAL) {
+ fprintf(stderr, " start %u, match %u, length %d\n",
+ start, match, length);
+ do {
+ fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
+ } while (--length != 0);
+ z_error("invalid match");
+ }
+ if (z_verbose > 1) {
+ fprintf(stderr,"\\[%d,%d]", start-match, length);
+ do { putc(s->window[start++], stderr); } while (--length != 0);
+ }
+}
+#else
+# define check_match(s, start, match, length)
+#endif /* DEBUG */
+
+/* ===========================================================================
+ * Fill the window when the lookahead becomes insufficient.
+ * Updates strstart and lookahead.
+ *
+ * IN assertion: lookahead < MIN_LOOKAHEAD
+ * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD
+ * At least one byte has been read, or avail_in == 0; reads are
+ * performed for at least two bytes (required for the zip translate_eol
+ * option -- not supported here).
+ */
+local void fill_window(s)
+ deflate_state *s;
+{
+ register unsigned n, m;
+ register Posf *p;
+ unsigned more; /* Amount of free space at the end of the window. */
+ uInt wsize = s->w_size;
+
+ do {
+ more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
+
+ /* Deal with !@#$% 64K limit: */
+ if (sizeof(int) <= 2) {
+ if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
+ more = wsize;
+
+ } else if (more == (unsigned)(-1)) {
+ /* Very unlikely, but possible on 16 bit machine if
+ * strstart == 0 && lookahead == 1 (input done a byte at time)
+ */
+ more--;
+ }
+ }
+
+ /* If the window is almost full and there is insufficient lookahead,
+ * move the upper half to the lower one to make room in the upper half.
+ */
+ if (s->strstart >= wsize+MAX_DIST(s)) {
+
+ zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
+ s->match_start -= wsize;
+ s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
+ s->block_start -= (long) wsize;
+
+ /* Slide the hash table (could be avoided with 32 bit values
+ at the expense of memory usage). We slide even when level == 0
+ to keep the hash table consistent if we switch back to level > 0
+ later. (Using level 0 permanently is not an optimal usage of
+ zlib, so we don't care about this pathological case.)
+ */
+ /* %%% avoid this when Z_RLE */
+ n = s->hash_size;
+ p = &s->head[n];
+ do {
+ m = *--p;
+ *p = (Pos)(m >= wsize ? m-wsize : NIL);
+ } while (--n);
+
+ n = wsize;
+#ifndef FASTEST
+ p = &s->prev[n];
+ do {
+ m = *--p;
+ *p = (Pos)(m >= wsize ? m-wsize : NIL);
+ /* If n is not on any hash chain, prev[n] is garbage but
+ * its value will never be used.
+ */
+ } while (--n);
+#endif
+ more += wsize;
+ }
+ if (s->strm->avail_in == 0) return;
+
+ /* If there was no sliding:
+ * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 &&
+ * more == window_size - lookahead - strstart
+ * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1)
+ * => more >= window_size - 2*WSIZE + 2
+ * In the BIG_MEM or MMAP case (not yet supported),
+ * window_size == input_size + MIN_LOOKAHEAD &&
+ * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD.
+ * Otherwise, window_size == 2*WSIZE so more >= 2.
+ * If there was sliding, more >= WSIZE. So in all cases, more >= 2.
+ */
+ Assert(more >= 2, "more < 2");
+
+ n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
+ s->lookahead += n;
+
+ /* Initialize the hash value now that we have some input: */
+ if (s->lookahead >= MIN_MATCH) {
+ s->ins_h = s->window[s->strstart];
+ UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
+#if MIN_MATCH != 3
+ Call UPDATE_HASH() MIN_MATCH-3 more times
+#endif
+ }
+ /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage,
+ * but this is not important since only literal bytes will be emitted.
+ */
+
+ } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
+}
+
+/* ===========================================================================
+ * Flush the current block, with given end-of-file flag.
+ * IN assertion: strstart is set to the end of the current match.
+ */
+#define FLUSH_BLOCK_ONLY(s, eof) { \
+ _tr_flush_block(s, (s->block_start >= 0L ? \
+ (charf *)&s->window[(unsigned)s->block_start] : \
+ (charf *)Z_NULL), \
+ (ulg)((long)s->strstart - s->block_start), \
+ (eof)); \
+ s->block_start = s->strstart; \
+ flush_pending(s->strm); \
+ Tracev((stderr,"[FLUSH]")); \
+}
+
+/* Same but force premature exit if necessary. */
+#define FLUSH_BLOCK(s, eof) { \
+ FLUSH_BLOCK_ONLY(s, eof); \
+ if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
+}
+
+/* ===========================================================================
+ * Copy without compression as much as possible from the input stream, return
+ * the current block state.
+ * This function does not insert new strings in the dictionary since
+ * uncompressible data is probably not useful. This function is used
+ * only for the level=0 compression option.
+ * NOTE: this function should be optimized to avoid extra copying from
+ * window to pending_buf.
+ */
+local block_state deflate_stored(s, flush)
+ deflate_state *s;
+ int flush;
+{
+ /* Stored blocks are limited to 0xffff bytes, pending_buf is limited
+ * to pending_buf_size, and each stored block has a 5 byte header:
+ */
+ ulg max_block_size = 0xffff;
+ ulg max_start;
+
+ if (max_block_size > s->pending_buf_size - 5) {
+ max_block_size = s->pending_buf_size - 5;
+ }
+
+ /* Copy as much as possible from input to output: */
+ for (;;) {
+ /* Fill the window as much as possible: */
+ if (s->lookahead <= 1) {
+
+ Assert(s->strstart < s->w_size+MAX_DIST(s) ||
+ s->block_start >= (long)s->w_size, "slide too late");
+
+ fill_window(s);
+ if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
+
+ if (s->lookahead == 0) break; /* flush the current block */
+ }
+ Assert(s->block_start >= 0L, "block gone");
+
+ s->strstart += s->lookahead;
+ s->lookahead = 0;
+
+ /* Emit a stored block if pending_buf will be full: */
+ max_start = s->block_start + max_block_size;
+ if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
+ /* strstart == 0 is possible when wraparound on 16-bit machine */
+ s->lookahead = (uInt)(s->strstart - max_start);
+ s->strstart = (uInt)max_start;
+ FLUSH_BLOCK(s, 0);
+ }
+ /* Flush if we may have to slide, otherwise block_start may become
+ * negative and the data will be gone:
+ */
+ if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
+ FLUSH_BLOCK(s, 0);
+ }
+ }
+ FLUSH_BLOCK(s, flush == Z_FINISH);
+ return flush == Z_FINISH ? finish_done : block_done;
+}
+
+/* ===========================================================================
+ * Compress as much as possible from the input stream, return the current
+ * block state.
+ * This function does not perform lazy evaluation of matches and inserts
+ * new strings in the dictionary only for unmatched strings or for short
+ * matches. It is used only for the fast compression options.
+ */
+local block_state deflate_fast(s, flush)
+ deflate_state *s;
+ int flush;
+{
+ IPos hash_head = NIL; /* head of the hash chain */
+ int bflush; /* set if current block must be flushed */
+
+ for (;;) {
+ /* Make sure that we always have enough lookahead, except
+ * at the end of the input file. We need MAX_MATCH bytes
+ * for the next match, plus MIN_MATCH bytes to insert the
+ * string following the next match.
+ */
+ if (s->lookahead < MIN_LOOKAHEAD) {
+ fill_window(s);
+ if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
+ return need_more;
+ }
+ if (s->lookahead == 0) break; /* flush the current block */
+ }
+
+ /* Insert the string window[strstart .. strstart+2] in the
+ * dictionary, and set hash_head to the head of the hash chain:
+ */
+ if (s->lookahead >= MIN_MATCH) {
+ INSERT_STRING(s, s->strstart, hash_head);
+ }
+
+ /* Find the longest match, discarding those <= prev_length.
+ * At this point we have always match_length < MIN_MATCH
+ */
+ if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
+ /* To simplify the code, we prevent matches with the string
+ * of window index 0 (in particular we have to avoid a match
+ * of the string with itself at the start of the input file).
+ */
+#ifdef FASTEST
+ if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
+ (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
+ s->match_length = longest_match_fast (s, hash_head);
+ }
+#else
+ if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
+ s->match_length = longest_match (s, hash_head);
+ } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
+ s->match_length = longest_match_fast (s, hash_head);
+ }
+#endif
+ /* longest_match() or longest_match_fast() sets match_start */
+ }
+ if (s->match_length >= MIN_MATCH) {
+ check_match(s, s->strstart, s->match_start, s->match_length);
+
+ _tr_tally_dist(s, s->strstart - s->match_start,
+ s->match_length - MIN_MATCH, bflush);
+
+ s->lookahead -= s->match_length;
+
+ /* Insert new strings in the hash table only if the match length
+ * is not too large. This saves time but degrades compression.
+ */
+#ifndef FASTEST
+ if (s->match_length <= s->max_insert_length &&
+ s->lookahead >= MIN_MATCH) {
+ s->match_length--; /* string at strstart already in table */
+ do {
+ s->strstart++;
+ INSERT_STRING(s, s->strstart, hash_head);
+ /* strstart never exceeds WSIZE-MAX_MATCH, so there are
+ * always MIN_MATCH bytes ahead.
+ */
+ } while (--s->match_length != 0);
+ s->strstart++;
+ } else
+#endif
+ {
+ s->strstart += s->match_length;
+ s->match_length = 0;
+ s->ins_h = s->window[s->strstart];
+ UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
+#if MIN_MATCH != 3
+ Call UPDATE_HASH() MIN_MATCH-3 more times
+#endif
+ /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not
+ * matter since it will be recomputed at next deflate call.
+ */
+ }
+ } else {
+ /* No match, output a literal byte */
+ Tracevv((stderr,"%c", s->window[s->strstart]));
+ _tr_tally_lit (s, s->window[s->strstart], bflush);
+ s->lookahead--;
+ s->strstart++;
+ }
+ if (bflush) FLUSH_BLOCK(s, 0);
+ }
+ FLUSH_BLOCK(s, flush == Z_FINISH);
+ return flush == Z_FINISH ? finish_done : block_done;
+}
+
+#ifndef FASTEST
+/* ===========================================================================
+ * Same as above, but achieves better compression. We use a lazy
+ * evaluation for matches: a match is finally adopted only if there is
+ * no better match at the next window position.
+ */
+local block_state deflate_slow(s, flush)
+ deflate_state *s;
+ int flush;
+{
+ IPos hash_head = NIL; /* head of hash chain */
+ int bflush; /* set if current block must be flushed */
+
+ /* Process the input block. */
+ for (;;) {
+ /* Make sure that we always have enough lookahead, except
+ * at the end of the input file. We need MAX_MATCH bytes
+ * for the next match, plus MIN_MATCH bytes to insert the
+ * string following the next match.
+ */
+ if (s->lookahead < MIN_LOOKAHEAD) {
+ fill_window(s);
+ if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
+ return need_more;
+ }
+ if (s->lookahead == 0) break; /* flush the current block */
+ }
+
+ /* Insert the string window[strstart .. strstart+2] in the
+ * dictionary, and set hash_head to the head of the hash chain:
+ */
+ if (s->lookahead >= MIN_MATCH) {
+ INSERT_STRING(s, s->strstart, hash_head);
+ }
+
+ /* Find the longest match, discarding those <= prev_length.
+ */
+ s->prev_length = s->match_length, s->prev_match = s->match_start;
+ s->match_length = MIN_MATCH-1;
+
+ if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
+ s->strstart - hash_head <= MAX_DIST(s)) {
+ /* To simplify the code, we prevent matches with the string
+ * of window index 0 (in particular we have to avoid a match
+ * of the string with itself at the start of the input file).
+ */
+ if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
+ s->match_length = longest_match (s, hash_head);
+ } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
+ s->match_length = longest_match_fast (s, hash_head);
+ }
+ /* longest_match() or longest_match_fast() sets match_start */
+
+ if (s->match_length <= 5 && (s->strategy == Z_FILTERED
+#if TOO_FAR <= 32767
+ || (s->match_length == MIN_MATCH &&
+ s->strstart - s->match_start > TOO_FAR)
+#endif
+ )) {
+
+ /* If prev_match is also MIN_MATCH, match_start is garbage
+ * but we will ignore the current match anyway.
+ */
+ s->match_length = MIN_MATCH-1;
+ }
+ }
+ /* If there was a match at the previous step and the current
+ * match is not better, output the previous match:
+ */
+ if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
+ uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
+ /* Do not insert strings in hash table beyond this. */
+
+ check_match(s, s->strstart-1, s->prev_match, s->prev_length);
+
+ _tr_tally_dist(s, s->strstart -1 - s->prev_match,
+ s->prev_length - MIN_MATCH, bflush);
+
+ /* Insert in hash table all strings up to the end of the match.
+ * strstart-1 and strstart are already inserted. If there is not
+ * enough lookahead, the last two strings are not inserted in
+ * the hash table.
+ */
+ s->lookahead -= s->prev_length-1;
+ s->prev_length -= 2;
+ do {
+ if (++s->strstart <= max_insert) {
+ INSERT_STRING(s, s->strstart, hash_head);
+ }
+ } while (--s->prev_length != 0);
+ s->match_available = 0;
+ s->match_length = MIN_MATCH-1;
+ s->strstart++;
+
+ if (bflush) FLUSH_BLOCK(s, 0);
+
+ } else if (s->match_available) {
+ /* If there was no match at the previous position, output a
+ * single literal. If there was a match but the current match
+ * is longer, truncate the previous match to a single literal.
+ */
+ Tracevv((stderr,"%c", s->window[s->strstart-1]));
+ _tr_tally_lit(s, s->window[s->strstart-1], bflush);
+ if (bflush) {
+ FLUSH_BLOCK_ONLY(s, 0);
+ }
+ s->strstart++;
+ s->lookahead--;
+ if (s->strm->avail_out == 0) return need_more;
+ } else {
+ /* There is no previous match to compare with, wait for
+ * the next step to decide.
+ */
+ s->match_available = 1;
+ s->strstart++;
+ s->lookahead--;
+ }
+ }
+ Assert (flush != Z_NO_FLUSH, "no flush?");
+ if (s->match_available) {
+ Tracevv((stderr,"%c", s->window[s->strstart-1]));
+ _tr_tally_lit(s, s->window[s->strstart-1], bflush);
+ s->match_available = 0;
+ }
+ FLUSH_BLOCK(s, flush == Z_FINISH);
+ return flush == Z_FINISH ? finish_done : block_done;
+}
+#endif /* FASTEST */
+
+#if 0
+/* ===========================================================================
+ * For Z_RLE, simply look for runs of bytes, generate matches only of distance
+ * one. Do not maintain a hash table. (It will be regenerated if this run of
+ * deflate switches away from Z_RLE.)
+ */
+local block_state deflate_rle(s, flush)
+ deflate_state *s;
+ int flush;
+{
+ int bflush; /* set if current block must be flushed */
+ uInt run; /* length of run */
+ uInt max; /* maximum length of run */
+ uInt prev; /* byte at distance one to match */
+ Bytef *scan; /* scan for end of run */
+
+ for (;;) {
+ /* Make sure that we always have enough lookahead, except
+ * at the end of the input file. We need MAX_MATCH bytes
+ * for the longest encodable run.
+ */
+ if (s->lookahead < MAX_MATCH) {
+ fill_window(s);
+ if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
+ return need_more;
+ }
+ if (s->lookahead == 0) break; /* flush the current block */
+ }
+
+ /* See how many times the previous byte repeats */
+ run = 0;
+ if (s->strstart > 0) { /* if there is a previous byte, that is */
+ max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
+ scan = s->window + s->strstart - 1;
+ prev = *scan++;
+ do {
+ if (*scan++ != prev)
+ break;
+ } while (++run < max);
+ }
+
+ /* Emit match if have run of MIN_MATCH or longer, else emit literal */
+ if (run >= MIN_MATCH) {
+ check_match(s, s->strstart, s->strstart - 1, run);
+ _tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
+ s->lookahead -= run;
+ s->strstart += run;
+ } else {
+ /* No match, output a literal byte */
+ Tracevv((stderr,"%c", s->window[s->strstart]));
+ _tr_tally_lit (s, s->window[s->strstart], bflush);
+ s->lookahead--;
+ s->strstart++;
+ }
+ if (bflush) FLUSH_BLOCK(s, 0);
+ }
+ FLUSH_BLOCK(s, flush == Z_FINISH);
+ return flush == Z_FINISH ? finish_done : block_done;
+}
+#endif
diff --git a/lib/libz/deflate.h b/lib/libz/deflate.h
new file mode 100644
index 0000000..8d2a878
--- /dev/null
+++ b/lib/libz/deflate.h
@@ -0,0 +1,331 @@
+/* $OpenBSD: deflate.h,v 1.8 2007/11/26 09:28:33 martynas Exp $ */
+/* deflate.h -- internal compression state
+ * Copyright (C) 1995-2004 Jean-loup Gailly
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+ part of the implementation of the compression library and is
+ subject to change. Applications should only use zlib.h.
+ */
+
+
+#ifndef DEFLATE_H
+#define DEFLATE_H
+
+#include "zutil.h"
+
+/* define NO_GZIP when compiling if you want to disable gzip header and
+ trailer creation by deflate(). NO_GZIP would be used to avoid linking in
+ the crc code when it is not needed. For shared libraries, gzip encoding
+ should be left enabled. */
+#ifndef NO_GZIP
+# define GZIP
+#endif
+
+/* ===========================================================================
+ * Internal compression state.
+ */
+
+#define LENGTH_CODES 29
+/* number of length codes, not counting the special END_BLOCK code */
+
+#define LITERALS 256
+/* number of literal bytes 0..255 */
+
+#define L_CODES (LITERALS+1+LENGTH_CODES)
+/* number of Literal or Length codes, including the END_BLOCK code */
+
+#define D_CODES 30
+/* number of distance codes */
+
+#define BL_CODES 19
+/* number of codes used to transfer the bit lengths */
+
+#define HEAP_SIZE (2*L_CODES+1)
+/* maximum heap size */
+
+#define MAX_BITS 15
+/* All codes must not exceed MAX_BITS bits */
+
+#define INIT_STATE 42
+#define EXTRA_STATE 69
+#define NAME_STATE 73
+#define COMMENT_STATE 91
+#define HCRC_STATE 103
+#define BUSY_STATE 113
+#define FINISH_STATE 666
+/* Stream status */
+
+
+/* Data structure describing a single value and its code string. */
+typedef struct ct_data_s {
+ union {
+ ush freq; /* frequency count */
+ ush code; /* bit string */
+ } fc;
+ union {
+ ush dad; /* father node in Huffman tree */
+ ush len; /* length of bit string */
+ } dl;
+} FAR ct_data;
+
+#define Freq fc.freq
+#define Code fc.code
+#define Dad dl.dad
+#define Len dl.len
+
+typedef struct static_tree_desc_s static_tree_desc;
+
+typedef struct tree_desc_s {
+ ct_data *dyn_tree; /* the dynamic tree */
+ int max_code; /* largest code with non zero frequency */
+ static_tree_desc *stat_desc; /* the corresponding static tree */
+} FAR tree_desc;
+
+typedef ush Pos;
+typedef Pos FAR Posf;
+typedef unsigned IPos;
+
+/* A Pos is an index in the character window. We use short instead of int to
+ * save space in the various tables. IPos is used only for parameter passing.
+ */
+
+typedef struct internal_state {
+ z_streamp strm; /* pointer back to this zlib stream */
+ int status; /* as the name implies */
+ Bytef *pending_buf; /* output still pending */
+ ulg pending_buf_size; /* size of pending_buf */
+ Bytef *pending_out; /* next pending byte to output to the stream */
+ uInt pending; /* nb of bytes in the pending buffer */
+ int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
+ gz_headerp gzhead; /* gzip header information to write */
+ uInt gzindex; /* where in extra, name, or comment */
+ Byte method; /* STORED (for zip only) or DEFLATED */
+ int last_flush; /* value of flush param for previous deflate call */
+
+ /* used by deflate.c: */
+
+ uInt w_size; /* LZ77 window size (32K by default) */
+ uInt w_bits; /* log2(w_size) (8..16) */
+ uInt w_mask; /* w_size - 1 */
+
+ Bytef *window;
+ /* Sliding window. Input bytes are read into the second half of the window,
+ * and move to the first half later to keep a dictionary of at least wSize
+ * bytes. With this organization, matches are limited to a distance of
+ * wSize-MAX_MATCH bytes, but this ensures that IO is always
+ * performed with a length multiple of the block size. Also, it limits
+ * the window size to 64K, which is quite useful on MSDOS.
+ * To do: use the user input buffer as sliding window.
+ */
+
+ ulg window_size;
+ /* Actual size of window: 2*wSize, except when the user input buffer
+ * is directly used as sliding window.
+ */
+
+ Posf *prev;
+ /* Link to older string with same hash index. To limit the size of this
+ * array to 64K, this link is maintained only for the last 32K strings.
+ * An index in this array is thus a window index modulo 32K.
+ */
+
+ Posf *head; /* Heads of the hash chains or NIL. */
+
+ uInt ins_h; /* hash index of string to be inserted */
+ uInt hash_size; /* number of elements in hash table */
+ uInt hash_bits; /* log2(hash_size) */
+ uInt hash_mask; /* hash_size-1 */
+
+ uInt hash_shift;
+ /* Number of bits by which ins_h must be shifted at each input
+ * step. It must be such that after MIN_MATCH steps, the oldest
+ * byte no longer takes part in the hash key, that is:
+ * hash_shift * MIN_MATCH >= hash_bits
+ */
+
+ long block_start;
+ /* Window position at the beginning of the current output block. Gets
+ * negative when the window is moved backwards.
+ */
+
+ uInt match_length; /* length of best match */
+ IPos prev_match; /* previous match */
+ int match_available; /* set if previous match exists */
+ uInt strstart; /* start of string to insert */
+ uInt match_start; /* start of matching string */
+ uInt lookahead; /* number of valid bytes ahead in window */
+
+ uInt prev_length;
+ /* Length of the best match at previous step. Matches not greater than this
+ * are discarded. This is used in the lazy match evaluation.
+ */
+
+ uInt max_chain_length;
+ /* To speed up deflation, hash chains are never searched beyond this
+ * length. A higher limit improves compression ratio but degrades the
+ * speed.
+ */
+
+ uInt max_lazy_match;
+ /* Attempt to find a better match only when the current match is strictly
+ * smaller than this value. This mechanism is used only for compression
+ * levels >= 4.
+ */
+# define max_insert_length max_lazy_match
+ /* Insert new strings in the hash table only if the match length is not
+ * greater than this length. This saves time but degrades compression.
+ * max_insert_length is used only for compression levels <= 3.
+ */
+
+ int level; /* compression level (1..9) */
+ int strategy; /* favor or force Huffman coding*/
+
+ uInt good_match;
+ /* Use a faster search when the previous match is longer than this */
+
+ int nice_match; /* Stop searching when current match exceeds this */
+
+ /* used by trees.c: */
+ /* Didn't use ct_data typedef below to suppress compiler warning */
+ struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
+ struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
+ struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
+
+ struct tree_desc_s l_desc; /* desc. for literal tree */
+ struct tree_desc_s d_desc; /* desc. for distance tree */
+ struct tree_desc_s bl_desc; /* desc. for bit length tree */
+
+ ush bl_count[MAX_BITS+1];
+ /* number of codes at each bit length for an optimal tree */
+
+ int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
+ int heap_len; /* number of elements in the heap */
+ int heap_max; /* element of largest frequency */
+ /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used.
+ * The same heap array is used to build all trees.
+ */
+
+ uch depth[2*L_CODES+1];
+ /* Depth of each subtree used as tie breaker for trees of equal frequency
+ */
+
+ uchf *l_buf; /* buffer for literals or lengths */
+
+ uInt lit_bufsize;
+ /* Size of match buffer for literals/lengths. There are 4 reasons for
+ * limiting lit_bufsize to 64K:
+ * - frequencies can be kept in 16 bit counters
+ * - if compression is not successful for the first block, all input
+ * data is still in the window so we can still emit a stored block even
+ * when input comes from standard input. (This can also be done for
+ * all blocks if lit_bufsize is not greater than 32K.)
+ * - if compression is not successful for a file smaller than 64K, we can
+ * even emit a stored file instead of a stored block (saving 5 bytes).
+ * This is applicable only for zip (not gzip or zlib).
+ * - creating new Huffman trees less frequently may not provide fast
+ * adaptation to changes in the input data statistics. (Take for
+ * example a binary file with poorly compressible code followed by
+ * a highly compressible string table.) Smaller buffer sizes give
+ * fast adaptation but have of course the overhead of transmitting
+ * trees more frequently.
+ * - I can't count above 4
+ */
+
+ uInt last_lit; /* running index in l_buf */
+
+ ushf *d_buf;
+ /* Buffer for distances. To simplify the code, d_buf and l_buf have
+ * the same number of elements. To use different lengths, an extra flag
+ * array would be necessary.
+ */
+
+ ulg opt_len; /* bit length of current block with optimal trees */
+ ulg static_len; /* bit length of current block with static trees */
+ uInt matches; /* number of string matches in current block */
+ int last_eob_len; /* bit length of EOB code for last block */
+
+#ifdef DEBUG
+ ulg compressed_len; /* total bit length of compressed file mod 2^32 */
+ ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
+#endif
+
+ ush bi_buf;
+ /* Output buffer. bits are inserted starting at the bottom (least
+ * significant bits).
+ */
+ int bi_valid;
+ /* Number of valid bits in bi_buf. All bits above the last valid bit
+ * are always zero.
+ */
+
+} FAR deflate_state;
+
+/* Output a byte on the stream.
+ * IN assertion: there is enough room in pending_buf.
+ */
+#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
+
+
+#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
+/* Minimum amount of lookahead, except at the end of the input file.
+ * See deflate.c for comments about the MIN_MATCH+1.
+ */
+
+#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
+/* In order to simplify the code, particularly on 16 bit machines, match
+ * distances are limited to MAX_DIST instead of WSIZE.
+ */
+
+ /* in trees.c */
+void _tr_init OF((deflate_state *s));
+int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
+void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
+ int eof));
+void _tr_align OF((deflate_state *s));
+void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
+ int eof));
+
+#define d_code(dist) \
+ ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
+/* Mapping from a distance to a distance code. dist is the distance - 1 and
+ * must not have side effects. _dist_code[256] and _dist_code[257] are never
+ * used.
+ */
+
+#ifndef DEBUG
+/* Inline versions of _tr_tally for speed: */
+
+#if defined(GEN_TREES_H) || !defined(STDC)
+ extern uch _length_code[];
+ extern uch _dist_code[];
+#else
+ extern const uch _length_code[];
+ extern const uch _dist_code[];
+#endif
+
+# define _tr_tally_lit(s, c, flush) \
+ { uch cc = (c); \
+ s->d_buf[s->last_lit] = 0; \
+ s->l_buf[s->last_lit++] = cc; \
+ s->dyn_ltree[cc].Freq++; \
+ flush = (s->last_lit == s->lit_bufsize-1); \
+ }
+# define _tr_tally_dist(s, distance, length, flush) \
+ { uch len = (length); \
+ ush dist = (distance); \
+ s->d_buf[s->last_lit] = dist; \
+ s->l_buf[s->last_lit++] = len; \
+ dist--; \
+ s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
+ s->dyn_dtree[d_code(dist)].Freq++; \
+ flush = (s->last_lit == s->lit_bufsize-1); \
+ }
+#else
+# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
+# define _tr_tally_dist(s, distance, length, flush) \
+ flush = _tr_tally(s, distance, length)
+#endif
+
+#endif /* DEFLATE_H */
diff --git a/lib/libz/generate_pkgconfig.sh b/lib/libz/generate_pkgconfig.sh
new file mode 100644
index 0000000..5d75d1c
--- /dev/null
+++ b/lib/libz/generate_pkgconfig.sh
@@ -0,0 +1,70 @@
+#!/bin/sh
+#
+# $OpenBSD: generate_pkgconfig.sh,v 1.2 2011/05/05 20:58:15 jasper Exp $
+#
+# Copyright (c) 2010,2011 Jasper Lievisse Adriaanse <jasper@openbsd.org>
+#
+# 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.
+#
+# Generate pkg-config file for zlib.
+
+usage() {
+ echo "usage: ${0##*/} -c current_directory -o obj_directory"
+ exit 1
+}
+
+curdir=
+objdir=
+while getopts "c:o:" flag; do
+ case "$flag" in
+ c)
+ curdir=$OPTARG
+ ;;
+ o)
+ objdir=$OPTARG
+ ;;
+ *)
+ usage
+ ;;
+ esac
+done
+
+[ -n "${curdir}" ] || usage
+if [ ! -d "${curdir}" ]; then
+ echo "${0##*/}: ${curdir}: not found"
+ exit 1
+fi
+[ -n "${objdir}" ] || usage
+if [ ! -w "${objdir}" ]; then
+ echo "${0##*/}: ${objdir}: not found or not writable"
+ exit 1
+fi
+
+version_re="s/^#define[[:blank:]]+ZLIB_VERSION[[:blank:]]+\"(.*)\".*/\1/p"
+version_file=${curdir}/zlib.h
+lib_version=$(sed -nE ${version_re} ${version_file})
+
+pc_file="${objdir}/zlib.pc"
+cat > ${pc_file} << __EOF__
+prefix=/usr
+exec_prefix=\${prefix}
+libdir=\${exec_prefix}/lib
+includedir=\${prefix}/include
+
+Name: zlib
+Description: zlib compression library
+Version: ${lib_version}
+Requires:
+Libs: -L\${libdir} -lz
+Cflags: -I\${includedir}
+__EOF__
diff --git a/lib/libz/gzio.c b/lib/libz/gzio.c
new file mode 100644
index 0000000..ab77ad9
--- /dev/null
+++ b/lib/libz/gzio.c
@@ -0,0 +1,1003 @@
+/* $OpenBSD: gzio.c,v 1.15 2020/04/18 17:11:37 schwarze Exp $ */
+/* gzio.c -- IO on .gz files
+ * Copyright (C) 1995-2005 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ *
+ * Compile this file with -DNO_GZCOMPRESS to avoid the compression code.
+ */
+
+
+#include <stdio.h>
+
+#include "zutil.h"
+
+#ifdef NO_DEFLATE /* for compatibility with old definition */
+# define NO_GZCOMPRESS
+#endif
+
+#ifndef NO_DUMMY_DECL
+struct internal_state {int dummy;}; /* for buggy compilers */
+#endif
+
+#ifndef Z_BUFSIZE
+# ifdef MAXSEG_64K
+# define Z_BUFSIZE 4096 /* minimize memory usage for 16-bit DOS */
+# else
+# define Z_BUFSIZE 16384
+# endif
+#endif
+#ifndef Z_PRINTF_BUFSIZE
+# define Z_PRINTF_BUFSIZE 4096
+#endif
+
+#ifdef __MVS__
+# pragma map (fdopen , "\174\174FDOPEN")
+ FILE *fdopen(int, const char *);
+#endif
+
+#ifndef STDC
+extern voidp malloc OF((uInt size));
+extern void free OF((voidpf ptr));
+#endif
+
+#define ALLOC(size) malloc(size)
+#define TRYFREE(p) {if (p) free(p);}
+
+static int const gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
+
+/* gzip flag byte */
+#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
+#define HEAD_CRC 0x02 /* bit 1 set: header CRC present */
+#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
+#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
+#define COMMENT 0x10 /* bit 4 set: file comment present */
+#define RESERVED 0xE0 /* bits 5..7: reserved */
+
+typedef struct gz_stream {
+ z_stream stream;
+ int z_err; /* error code for last stream operation */
+ int z_eof; /* set if end of input file */
+ FILE *file; /* .gz file */
+ Byte *inbuf; /* input buffer */
+ Byte *outbuf; /* output buffer */
+ uLong crc; /* crc32 of uncompressed data */
+ char *msg; /* error message */
+ char *path; /* path name for debugging only */
+ int transparent; /* 1 if input file is not a .gz file */
+ char mode; /* 'w' or 'r' */
+ z_off_t start; /* start of compressed data in file (header skipped) */
+ z_off_t in; /* bytes into deflate or inflate */
+ z_off_t out; /* bytes out of deflate or inflate */
+ int back; /* one character push-back */
+ int last; /* true if push-back is last character */
+} gz_stream;
+
+
+local gzFile gz_open OF((const char *path, const char *mode, int fd));
+local int do_flush OF((gzFile file, int flush));
+local int get_byte OF((gz_stream *s));
+local void check_header OF((gz_stream *s));
+local int destroy OF((gz_stream *s));
+local void putLong OF((FILE *file, uLong x));
+local uLong getLong OF((gz_stream *s));
+
+/* ===========================================================================
+ Opens a gzip (.gz) file for reading or writing. The mode parameter
+ is as in fopen ("rb" or "wb"). The file is given either by file descriptor
+ or path name (if fd == -1).
+ gz_open returns NULL if the file could not be opened or if there was
+ insufficient memory to allocate the (de)compression state; errno
+ can be checked to distinguish the two cases (if errno is zero, the
+ zlib error is Z_MEM_ERROR).
+*/
+local gzFile gz_open (path, mode, fd)
+ const char *path;
+ const char *mode;
+ int fd;
+{
+ int err;
+ int level = Z_DEFAULT_COMPRESSION; /* compression level */
+ int strategy = Z_DEFAULT_STRATEGY; /* compression strategy */
+ char *p = (char*)mode;
+ gz_stream *s;
+ char fmode[80]; /* copy of mode, without the compression level */
+ char *m = fmode;
+ size_t len;
+
+ if (!path || !mode) return Z_NULL;
+
+ s = (gz_stream *)ALLOC(sizeof(gz_stream));
+ if (!s) return Z_NULL;
+
+ s->stream.zalloc = (alloc_func)0;
+ s->stream.zfree = (free_func)0;
+ s->stream.opaque = (voidpf)0;
+ s->stream.next_in = s->inbuf = Z_NULL;
+ s->stream.next_out = s->outbuf = Z_NULL;
+ s->stream.avail_in = s->stream.avail_out = 0;
+ s->file = NULL;
+ s->z_err = Z_OK;
+ s->z_eof = 0;
+ s->in = 0;
+ s->out = 0;
+ s->back = EOF;
+ s->crc = crc32(0L, Z_NULL, 0);
+ s->msg = NULL;
+ s->transparent = 0;
+
+ len = strlen(path)+1;
+ s->path = (char*)ALLOC(len);
+ if (s->path == NULL) {
+ return destroy(s), (gzFile)Z_NULL;
+ }
+ strlcpy(s->path, path, len); /* do this early for debugging */
+
+ s->mode = '\0';
+ do {
+ if (*p == 'r') s->mode = 'r';
+ if (*p == 'w' || *p == 'a') s->mode = 'w';
+ if (*p >= '0' && *p <= '9') {
+ level = *p - '0';
+ } else if (*p == 'f') {
+ strategy = Z_FILTERED;
+ } else if (*p == 'h') {
+ strategy = Z_HUFFMAN_ONLY;
+ } else if (*p == 'R') {
+ strategy = Z_RLE;
+ } else {
+ *m++ = *p; /* copy the mode */
+ }
+ } while (*p++ && m != fmode + sizeof(fmode));
+ if (s->mode == '\0') return destroy(s), (gzFile)Z_NULL;
+
+ if (s->mode == 'w') {
+#ifdef NO_GZCOMPRESS
+ err = Z_STREAM_ERROR;
+#else
+ err = deflateInit2(&(s->stream), level,
+ Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL, strategy);
+ /* windowBits is passed < 0 to suppress zlib header */
+
+ s->stream.next_out = s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
+#endif
+ if (err != Z_OK || s->outbuf == Z_NULL) {
+ return destroy(s), (gzFile)Z_NULL;
+ }
+ } else {
+ s->stream.next_in = s->inbuf = (Byte*)ALLOC(Z_BUFSIZE);
+
+ err = inflateInit2(&(s->stream), -MAX_WBITS);
+ /* windowBits is passed < 0 to tell that there is no zlib header.
+ * Note that in this case inflate *requires* an extra "dummy" byte
+ * after the compressed stream in order to complete decompression and
+ * return Z_STREAM_END. Here the gzip CRC32 ensures that 4 bytes are
+ * present after the compressed stream.
+ */
+ if (err != Z_OK || s->inbuf == Z_NULL) {
+ return destroy(s), (gzFile)Z_NULL;
+ }
+ }
+ s->stream.avail_out = Z_BUFSIZE;
+
+ errno = 0;
+ s->file = fd < 0 ? F_OPEN(path, fmode) : (FILE*)fdopen(fd, fmode);
+
+ if (s->file == NULL) {
+ return destroy(s), (gzFile)Z_NULL;
+ }
+ if (s->mode == 'w') {
+ /* Write a very simple .gz header:
+ */
+ fprintf(s->file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1],
+ Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE);
+ s->start = 10L;
+ /* We use 10L instead of ftell(s->file) to because ftell causes an
+ * fflush on some systems. This version of the library doesn't use
+ * start anyway in write mode, so this initialization is not
+ * necessary.
+ */
+ } else {
+ check_header(s); /* skip the .gz header */
+ s->start = ftell(s->file) - s->stream.avail_in;
+ }
+
+ return (gzFile)s;
+}
+
+/* ===========================================================================
+ Opens a gzip (.gz) file for reading or writing.
+*/
+gzFile ZEXPORT gzopen (path, mode)
+ const char *path;
+ const char *mode;
+{
+ return gz_open (path, mode, -1);
+}
+
+/* ===========================================================================
+ Associate a gzFile with the file descriptor fd. fd is not dup'ed here
+ to mimic the behavio(u)r of fdopen.
+*/
+gzFile ZEXPORT gzdopen (fd, mode)
+ int fd;
+ const char *mode;
+{
+ char name[46]; /* allow for up to 128-bit integers */
+
+ if (fd < 0) return (gzFile)Z_NULL;
+ snprintf(name, sizeof name, "<fd:%d>", fd); /* for debugging */
+
+ return gz_open (name, mode, fd);
+}
+
+/* ===========================================================================
+ * Update the compression level and strategy
+ */
+int ZEXPORT gzsetparams (file, level, strategy)
+ gzFile file;
+ int level;
+ int strategy;
+{
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
+
+ /* Make room to allow flushing */
+ if (s->stream.avail_out == 0) {
+
+ s->stream.next_out = s->outbuf;
+ if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
+ s->z_err = Z_ERRNO;
+ }
+ s->stream.avail_out = Z_BUFSIZE;
+ }
+
+ return deflateParams (&(s->stream), level, strategy);
+}
+
+/* ===========================================================================
+ Read a byte from a gz_stream; update next_in and avail_in. Return EOF
+ for end of file.
+ IN assertion: the stream s has been successfully opened for reading.
+*/
+local int get_byte(s)
+ gz_stream *s;
+{
+ if (s->z_eof) return EOF;
+ if (s->stream.avail_in == 0) {
+ errno = 0;
+ s->stream.avail_in = (uInt)fread(s->inbuf, 1, Z_BUFSIZE, s->file);
+ if (s->stream.avail_in == 0) {
+ s->z_eof = 1;
+ if (ferror(s->file)) s->z_err = Z_ERRNO;
+ return EOF;
+ }
+ s->stream.next_in = s->inbuf;
+ }
+ s->stream.avail_in--;
+ return *(s->stream.next_in)++;
+}
+
+/* ===========================================================================
+ Check the gzip header of a gz_stream opened for reading. Set the stream
+ mode to transparent if the gzip magic header is not present; set s->err
+ to Z_DATA_ERROR if the magic header is present but the rest of the header
+ is incorrect.
+ IN assertion: the stream s has already been created successfully;
+ s->stream.avail_in is zero for the first time, but may be non-zero
+ for concatenated .gz files.
+*/
+local void check_header(s)
+ gz_stream *s;
+{
+ int method; /* method byte */
+ int flags; /* flags byte */
+ uInt len;
+ int c;
+
+ /* Assure two bytes in the buffer so we can peek ahead -- handle case
+ where first byte of header is at the end of the buffer after the last
+ gzip segment */
+ len = s->stream.avail_in;
+ if (len < 2) {
+ if (len) s->inbuf[0] = s->stream.next_in[0];
+ errno = 0;
+ len = (uInt)fread(s->inbuf + len, 1, Z_BUFSIZE >> len, s->file);
+ if (len == 0 && ferror(s->file)) s->z_err = Z_ERRNO;
+ s->stream.avail_in += len;
+ s->stream.next_in = s->inbuf;
+ if (s->stream.avail_in < 2) {
+ s->transparent = 1;
+ return;
+ }
+ }
+
+ /* Peek ahead to check the gzip magic header */
+ if (s->stream.next_in[0] != gz_magic[0] ||
+ s->stream.next_in[1] != gz_magic[1]) {
+ s->transparent = 1;
+ return;
+ }
+ s->stream.avail_in -= 2;
+ s->stream.next_in += 2;
+
+ /* Check the rest of the gzip header */
+ method = get_byte(s);
+ flags = get_byte(s);
+ if (method != Z_DEFLATED || (flags & RESERVED) != 0) {
+ s->z_err = Z_DATA_ERROR;
+ return;
+ }
+
+ /* Discard time, xflags and OS code: */
+ for (len = 0; len < 6; len++) (void)get_byte(s);
+
+ if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */
+ len = (uInt)get_byte(s);
+ len += ((uInt)get_byte(s))<<8;
+ /* len is garbage if EOF but the loop below will quit anyway */
+ while (len-- != 0 && get_byte(s) != EOF) ;
+ }
+ if ((flags & ORIG_NAME) != 0) { /* skip the original file name */
+ while ((c = get_byte(s)) != 0 && c != EOF) ;
+ }
+ if ((flags & COMMENT) != 0) { /* skip the .gz file comment */
+ while ((c = get_byte(s)) != 0 && c != EOF) ;
+ }
+ if ((flags & HEAD_CRC) != 0) { /* skip the header crc */
+ for (len = 0; len < 2; len++) (void)get_byte(s);
+ }
+ s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK;
+}
+
+ /* ===========================================================================
+ * Cleanup then free the given gz_stream. Return a zlib error code.
+ Try freeing in the reverse order of allocations.
+ */
+local int destroy (s)
+ gz_stream *s;
+{
+ int err = Z_OK;
+
+ if (!s) return Z_STREAM_ERROR;
+
+ TRYFREE(s->msg);
+
+ if (s->stream.state != NULL) {
+ if (s->mode == 'w') {
+#ifdef NO_GZCOMPRESS
+ err = Z_STREAM_ERROR;
+#else
+ err = deflateEnd(&(s->stream));
+#endif
+ } else if (s->mode == 'r') {
+ err = inflateEnd(&(s->stream));
+ }
+ }
+ if (s->file != NULL && fclose(s->file)) {
+#ifdef ESPIPE
+ if (errno != ESPIPE) /* fclose is broken for pipes in HP/UX */
+#endif
+ err = Z_ERRNO;
+ }
+ if (s->z_err < 0) err = s->z_err;
+
+ TRYFREE(s->inbuf);
+ TRYFREE(s->outbuf);
+ TRYFREE(s->path);
+ TRYFREE(s);
+ return err;
+}
+
+/* ===========================================================================
+ Reads the given number of uncompressed bytes from the compressed file.
+ gzread returns the number of bytes actually read (0 for end of file).
+*/
+int ZEXPORT gzread (file, buf, len)
+ gzFile file;
+ voidp buf;
+ unsigned len;
+{
+ gz_stream *s = (gz_stream*)file;
+ Bytef *start = (Bytef*)buf; /* starting point for crc computation */
+ Byte *next_out; /* == stream.next_out but not forced far (for MSDOS) */
+
+ if (s == NULL || s->mode != 'r') return Z_STREAM_ERROR;
+
+ if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO) return -1;
+ if (s->z_err == Z_STREAM_END) return 0; /* EOF */
+
+ next_out = (Byte*)buf;
+ s->stream.next_out = (Bytef*)buf;
+ s->stream.avail_out = len;
+
+ if (s->stream.avail_out && s->back != EOF) {
+ *next_out++ = s->back;
+ s->stream.next_out++;
+ s->stream.avail_out--;
+ s->back = EOF;
+ s->out++;
+ start++;
+ if (s->last) {
+ s->z_err = Z_STREAM_END;
+ return 1;
+ }
+ }
+
+ while (s->stream.avail_out != 0) {
+
+ if (s->transparent) {
+ /* Copy first the lookahead bytes: */
+ uInt n = s->stream.avail_in;
+ if (n > s->stream.avail_out) n = s->stream.avail_out;
+ if (n > 0) {
+ zmemcpy(s->stream.next_out, s->stream.next_in, n);
+ next_out += n;
+ s->stream.next_out = next_out;
+ s->stream.next_in += n;
+ s->stream.avail_out -= n;
+ s->stream.avail_in -= n;
+ }
+ if (s->stream.avail_out > 0) {
+ s->stream.avail_out -=
+ (uInt)fread(next_out, 1, s->stream.avail_out, s->file);
+ }
+ len -= s->stream.avail_out;
+ s->in += len;
+ s->out += len;
+ if (len == 0) s->z_eof = 1;
+ return (int)len;
+ }
+ if (s->stream.avail_in == 0 && !s->z_eof) {
+
+ errno = 0;
+ s->stream.avail_in = (uInt)fread(s->inbuf, 1, Z_BUFSIZE, s->file);
+ if (s->stream.avail_in == 0) {
+ s->z_eof = 1;
+ if (ferror(s->file)) {
+ s->z_err = Z_ERRNO;
+ break;
+ }
+ }
+ s->stream.next_in = s->inbuf;
+ }
+ s->in += s->stream.avail_in;
+ s->out += s->stream.avail_out;
+ s->z_err = inflate(&(s->stream), Z_NO_FLUSH);
+ s->in -= s->stream.avail_in;
+ s->out -= s->stream.avail_out;
+
+ if (s->z_err == Z_STREAM_END) {
+ /* Check CRC and original size */
+ s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
+ start = s->stream.next_out;
+
+ if (getLong(s) != s->crc) {
+ s->z_err = Z_DATA_ERROR;
+ } else {
+ (void)getLong(s);
+ /* The uncompressed length returned by above getlong() may be
+ * different from s->out in case of concatenated .gz files.
+ * Check for such files:
+ */
+ check_header(s);
+ if (s->z_err == Z_OK) {
+ inflateReset(&(s->stream));
+ s->crc = crc32(0L, Z_NULL, 0);
+ }
+ }
+ }
+ if (s->z_err != Z_OK || s->z_eof) break;
+ }
+ s->crc = crc32(s->crc, start, (uInt)(s->stream.next_out - start));
+
+ if (len == s->stream.avail_out &&
+ (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO))
+ return -1;
+ return (int)(len - s->stream.avail_out);
+}
+
+
+/* ===========================================================================
+ Reads one byte from the compressed file. gzgetc returns this byte
+ or -1 in case of end of file or error.
+*/
+int ZEXPORT gzgetc(file)
+ gzFile file;
+{
+ unsigned char c;
+
+ return gzread(file, &c, 1) == 1 ? c : -1;
+}
+
+
+/* ===========================================================================
+ Push one byte back onto the stream.
+*/
+int ZEXPORT gzungetc(c, file)
+ int c;
+ gzFile file;
+{
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL || s->mode != 'r' || c == EOF || s->back != EOF) return EOF;
+ s->back = c;
+ s->out--;
+ s->last = (s->z_err == Z_STREAM_END);
+ if (s->last) s->z_err = Z_OK;
+ s->z_eof = 0;
+ return c;
+}
+
+
+/* ===========================================================================
+ Reads bytes from the compressed file until len-1 characters are
+ read, or a newline character is read and transferred to buf, or an
+ end-of-file condition is encountered. The string is then terminated
+ with a null character.
+ gzgets returns buf, or Z_NULL in case of error.
+
+ The current implementation is not optimized at all.
+*/
+char * ZEXPORT gzgets(file, buf, len)
+ gzFile file;
+ char *buf;
+ int len;
+{
+ char *b = buf;
+ if (buf == Z_NULL || len <= 0) return Z_NULL;
+
+ while (--len > 0 && gzread(file, buf, 1) == 1 && *buf++ != '\n') ;
+ *buf = '\0';
+ return b == buf && len > 0 ? Z_NULL : b;
+}
+
+
+#ifndef NO_GZCOMPRESS
+/* ===========================================================================
+ Writes the given number of uncompressed bytes into the compressed file.
+ gzwrite returns the number of bytes actually written (0 in case of error).
+*/
+int ZEXPORT gzwrite (file, buf, len)
+ gzFile file;
+ voidpc buf;
+ unsigned len;
+{
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
+
+ s->stream.next_in = (Bytef*)buf;
+ s->stream.avail_in = len;
+
+ while (s->stream.avail_in != 0) {
+
+ if (s->stream.avail_out == 0) {
+
+ s->stream.next_out = s->outbuf;
+ if (fwrite(s->outbuf, 1, Z_BUFSIZE, s->file) != Z_BUFSIZE) {
+ s->z_err = Z_ERRNO;
+ break;
+ }
+ s->stream.avail_out = Z_BUFSIZE;
+ }
+ s->in += s->stream.avail_in;
+ s->out += s->stream.avail_out;
+ s->z_err = deflate(&(s->stream), Z_NO_FLUSH);
+ s->in -= s->stream.avail_in;
+ s->out -= s->stream.avail_out;
+ if (s->z_err != Z_OK) break;
+ }
+ s->crc = crc32(s->crc, (const Bytef *)buf, len);
+
+ return (int)(len - s->stream.avail_in);
+}
+
+
+/* ===========================================================================
+ Converts, formats, and writes the args to the compressed file under
+ control of the format string, as in fprintf. gzprintf returns the number of
+ uncompressed bytes actually written (0 in case of error).
+*/
+#ifdef STDC
+#include <stdarg.h>
+
+int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...)
+{
+ char buf[Z_PRINTF_BUFSIZE];
+ va_list va;
+ int len;
+
+ va_start(va, format);
+#ifdef HAS_vsnprintf
+ len = vsnprintf(buf, sizeof(buf), format, va);
+#else
+ (void)vsprintf(buf, format, va);
+ len = strlen(buf); /* some *sprintf don't return the nb of bytes written */
+#endif
+ va_end(va);
+ if (len <= 0 || len >= sizeof(buf)) return 0;
+
+ return gzwrite(file, buf, (unsigned)len);
+}
+#else /* not ANSI C */
+
+int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
+ a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
+ gzFile file;
+ const char *format;
+ int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
+ a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
+{
+ char buf[Z_PRINTF_BUFSIZE];
+ int len;
+
+#ifdef HAS_snprintf
+ len = snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8,
+ a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
+#else
+ sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8,
+ a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
+ len = strlen(buf); /* old sprintf doesn't return the nb of bytes written */
+#endif
+ if (len <= 0 || len >= sizeof(buf)) return 0;
+
+ return gzwrite(file, buf, len);
+}
+#endif
+
+/* ===========================================================================
+ Writes c, converted to an unsigned char, into the compressed file.
+ gzputc returns the value that was written, or -1 in case of error.
+*/
+int ZEXPORT gzputc(file, c)
+ gzFile file;
+ int c;
+{
+ unsigned char cc = (unsigned char) c; /* required for big endian systems */
+
+ return gzwrite(file, &cc, 1) == 1 ? (int)cc : -1;
+}
+
+
+/* ===========================================================================
+ Writes the given null-terminated string to the compressed file, excluding
+ the terminating null character.
+ gzputs returns the number of characters written, or -1 in case of error.
+*/
+int ZEXPORT gzputs(file, s)
+ gzFile file;
+ const char *s;
+{
+ return gzwrite(file, (char*)s, (unsigned)strlen(s));
+}
+
+
+/* ===========================================================================
+ Flushes all pending output into the compressed file. The parameter
+ flush is as in the deflate() function.
+*/
+local int do_flush (file, flush)
+ gzFile file;
+ int flush;
+{
+ uInt len;
+ int done = 0;
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL || s->mode != 'w') return Z_STREAM_ERROR;
+
+ s->stream.avail_in = 0; /* should be zero already anyway */
+
+ for (;;) {
+ len = Z_BUFSIZE - s->stream.avail_out;
+
+ if (len != 0) {
+ if ((uInt)fwrite(s->outbuf, 1, len, s->file) != len) {
+ s->z_err = Z_ERRNO;
+ return Z_ERRNO;
+ }
+ s->stream.next_out = s->outbuf;
+ s->stream.avail_out = Z_BUFSIZE;
+ }
+ if (done) break;
+ s->out += s->stream.avail_out;
+ s->z_err = deflate(&(s->stream), flush);
+ s->out -= s->stream.avail_out;
+
+ /* Ignore the second of two consecutive flushes: */
+ if (len == 0 && s->z_err == Z_BUF_ERROR) s->z_err = Z_OK;
+
+ /* deflate has finished flushing only when it hasn't used up
+ * all the available space in the output buffer:
+ */
+ done = (s->stream.avail_out != 0 || s->z_err == Z_STREAM_END);
+
+ if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break;
+ }
+ return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
+}
+
+int ZEXPORT gzflush (file, flush)
+ gzFile file;
+ int flush;
+{
+ gz_stream *s = (gz_stream*)file;
+ int err = do_flush (file, flush);
+
+ if (err) return err;
+ fflush(s->file);
+ return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
+}
+#endif /* NO_GZCOMPRESS */
+
+/* ===========================================================================
+ Sets the starting position for the next gzread or gzwrite on the given
+ compressed file. The offset represents a number of bytes in the
+ gzseek returns the resulting offset location as measured in bytes from
+ the beginning of the uncompressed stream, or -1 in case of error.
+ SEEK_END is not implemented, returns error.
+ In this version of the library, gzseek can be extremely slow.
+*/
+z_off_t ZEXPORT gzseek (file, offset, whence)
+ gzFile file;
+ z_off_t offset;
+ int whence;
+{
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL || whence == SEEK_END ||
+ s->z_err == Z_ERRNO || s->z_err == Z_DATA_ERROR) {
+ return -1L;
+ }
+
+ if (s->mode == 'w') {
+#ifdef NO_GZCOMPRESS
+ return -1L;
+#else
+ if (whence == SEEK_SET) {
+ offset -= s->in;
+ }
+ if (offset < 0) return -1L;
+
+ /* At this point, offset is the number of zero bytes to write. */
+ if (s->inbuf == Z_NULL) {
+ s->inbuf = (Byte*)ALLOC(Z_BUFSIZE); /* for seeking */
+ if (s->inbuf == Z_NULL) return -1L;
+ zmemzero(s->inbuf, Z_BUFSIZE);
+ }
+ while (offset > 0) {
+ uInt size = Z_BUFSIZE;
+ if (offset < Z_BUFSIZE) size = (uInt)offset;
+
+ size = gzwrite(file, s->inbuf, size);
+ if (size == 0) return -1L;
+
+ offset -= size;
+ }
+ return s->in;
+#endif
+ }
+ /* Rest of function is for reading only */
+
+ /* compute absolute position */
+ if (whence == SEEK_CUR) {
+ offset += s->out;
+ }
+ if (offset < 0) return -1L;
+
+ if (s->transparent) {
+ /* map to fseek */
+ s->back = EOF;
+ s->stream.avail_in = 0;
+ s->stream.next_in = s->inbuf;
+ if (fseek(s->file, offset, SEEK_SET) < 0) return -1L;
+
+ s->in = s->out = offset;
+ return offset;
+ }
+
+ /* For a negative seek, rewind and use positive seek */
+ if (offset >= s->out) {
+ offset -= s->out;
+ } else if (gzrewind(file) < 0) {
+ return -1L;
+ }
+ /* offset is now the number of bytes to skip. */
+
+ if (offset != 0 && s->outbuf == Z_NULL) {
+ s->outbuf = (Byte*)ALLOC(Z_BUFSIZE);
+ if (s->outbuf == Z_NULL) return -1L;
+ }
+ if (offset && s->back != EOF) {
+ s->back = EOF;
+ s->out++;
+ offset--;
+ if (s->last) s->z_err = Z_STREAM_END;
+ }
+ while (offset > 0) {
+ int size = Z_BUFSIZE;
+ if (offset < Z_BUFSIZE) size = (int)offset;
+
+ size = gzread(file, s->outbuf, (uInt)size);
+ if (size <= 0) return -1L;
+ offset -= size;
+ }
+ return s->out;
+}
+
+/* ===========================================================================
+ Rewinds input file.
+*/
+int ZEXPORT gzrewind (file)
+ gzFile file;
+{
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL || s->mode != 'r') return -1;
+
+ s->z_err = Z_OK;
+ s->z_eof = 0;
+ s->back = EOF;
+ s->stream.avail_in = 0;
+ s->stream.next_in = s->inbuf;
+ s->crc = crc32(0L, Z_NULL, 0);
+ if (!s->transparent) (void)inflateReset(&s->stream);
+ s->in = 0;
+ s->out = 0;
+ return fseek(s->file, s->start, SEEK_SET);
+}
+
+/* ===========================================================================
+ Returns the starting position for the next gzread or gzwrite on the
+ given compressed file. This position represents a number of bytes in the
+ uncompressed data stream.
+*/
+z_off_t ZEXPORT gztell (file)
+ gzFile file;
+{
+ return gzseek(file, 0L, SEEK_CUR);
+}
+
+/* ===========================================================================
+ Returns 1 when EOF has previously been detected reading the given
+ input stream, otherwise zero.
+*/
+int ZEXPORT gzeof (file)
+ gzFile file;
+{
+ gz_stream *s = (gz_stream*)file;
+
+ /* With concatenated compressed files that can have embedded
+ * crc trailers, z_eof is no longer the only/best indicator of EOF
+ * on a gz_stream. Handle end-of-stream error explicitly here.
+ */
+ if (s == NULL || s->mode != 'r') return 0;
+ if (s->z_eof) return 1;
+ return s->z_err == Z_STREAM_END;
+}
+
+/* ===========================================================================
+ Returns 1 if reading and doing so transparently, otherwise zero.
+*/
+int ZEXPORT gzdirect (file)
+ gzFile file;
+{
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL || s->mode != 'r') return 0;
+ return s->transparent;
+}
+
+/* ===========================================================================
+ Outputs a long in LSB order to the given file
+*/
+local void putLong (file, x)
+ FILE *file;
+ uLong x;
+{
+ int n;
+ for (n = 0; n < 4; n++) {
+ fputc((int)(x & 0xff), file);
+ x >>= 8;
+ }
+}
+
+/* ===========================================================================
+ Reads a long in LSB order from the given gz_stream. Sets z_err in case
+ of error.
+*/
+local uLong getLong (s)
+ gz_stream *s;
+{
+ uLong x = (uLong)get_byte(s);
+ int c;
+
+ x += ((uLong)get_byte(s))<<8;
+ x += ((uLong)get_byte(s))<<16;
+ c = get_byte(s);
+ if (c == EOF) s->z_err = Z_DATA_ERROR;
+ x += ((uLong)c)<<24;
+ return x;
+}
+
+/* ===========================================================================
+ Flushes all pending output if necessary, closes the compressed file
+ and deallocates all the (de)compression state.
+*/
+int ZEXPORT gzclose (file)
+ gzFile file;
+{
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL) return Z_STREAM_ERROR;
+
+ if (s->mode == 'w') {
+#ifdef NO_GZCOMPRESS
+ return Z_STREAM_ERROR;
+#else
+ if (do_flush (file, Z_FINISH) != Z_OK)
+ return destroy((gz_stream*)file);
+
+ putLong (s->file, s->crc);
+ putLong (s->file, (uLong)(s->in & 0xffffffff));
+#endif
+ }
+ return destroy((gz_stream*)file);
+}
+
+#ifdef STDC
+# define zstrerror(errnum) strerror(errnum)
+#else
+# define zstrerror(errnum) ""
+#endif
+
+/* ===========================================================================
+ Returns the error message for the last error which occurred on the
+ given compressed file. errnum is set to zlib error number. If an
+ error occurred in the file system and not in the compression library,
+ errnum is set to Z_ERRNO and the application may consult errno
+ to get the exact error code.
+*/
+const char * ZEXPORT gzerror (file, errnum)
+ gzFile file;
+ int *errnum;
+{
+ char *m;
+ gz_stream *s = (gz_stream*)file;
+ size_t len;
+
+ if (s == NULL) {
+ *errnum = Z_STREAM_ERROR;
+ return (const char*)ERR_MSG(Z_STREAM_ERROR);
+ }
+ *errnum = s->z_err;
+ if (*errnum == Z_OK) return (const char*)"";
+
+ m = (char*)(*errnum == Z_ERRNO ? zstrerror(errno) : s->stream.msg);
+
+ if (m == NULL || *m == '\0') m = (char*)ERR_MSG(s->z_err);
+
+ TRYFREE(s->msg);
+ len = strlen(s->path) + strlen(m) + 3;
+ s->msg = (char*)ALLOC(len);
+ if (s->msg == Z_NULL) return (const char*)ERR_MSG(Z_MEM_ERROR);
+ strlcpy(s->msg, s->path, len);
+ strlcat(s->msg, ": ", len);
+ strlcat(s->msg, m, len);
+ return (const char*)s->msg;
+}
+
+/* ===========================================================================
+ Clear the error and end-of-file flags, and do the same for the real file.
+*/
+void ZEXPORT gzclearerr (file)
+ gzFile file;
+{
+ gz_stream *s = (gz_stream*)file;
+
+ if (s == NULL) return;
+ if (s->z_err != Z_STREAM_END) s->z_err = Z_OK;
+ s->z_eof = 0;
+ clearerr(s->file);
+}
diff --git a/lib/libz/infback.c b/lib/libz/infback.c
new file mode 100644
index 0000000..e980358
--- /dev/null
+++ b/lib/libz/infback.c
@@ -0,0 +1,637 @@
+/* infback.c -- inflate using a call-back interface
+ * Copyright (C) 1995-2005 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/*
+ This code is largely copied from inflate.c. Normally either infback.o or
+ inflate.o would be linked into an application--not both. The interface
+ with inffast.c is retained so that optimized assembler-coded versions of
+ inflate_fast() can be used with either inflate.c or infback.c.
+ */
+
+#include "zutil.h"
+#include "inftrees.h"
+#include "inflate.h"
+#include "inffast.h"
+
+/* function prototypes */
+local void fixedtables OF((struct inflate_state FAR *state));
+
+/*
+ strm provides memory allocation functions in zalloc and zfree, or
+ Z_NULL to use the library memory allocation functions.
+
+ windowBits is in the range 8..15, and window is a user-supplied
+ window and output buffer that is 2**windowBits bytes.
+ */
+int ZEXPORT inflateBackInit_(strm, windowBits, window, version, stream_size)
+z_streamp strm;
+int windowBits;
+unsigned char FAR *window;
+const char *version;
+int stream_size;
+{
+ struct inflate_state FAR *state;
+
+ if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
+ stream_size != (int)(sizeof(z_stream)))
+ return Z_VERSION_ERROR;
+ if (strm == Z_NULL || window == Z_NULL ||
+ windowBits < 8 || windowBits > 15)
+ return Z_STREAM_ERROR;
+ strm->msg = Z_NULL; /* in case we return an error */
+ if (strm->zalloc == (alloc_func)0) {
+ strm->zalloc = zcalloc;
+ strm->opaque = (voidpf)0;
+ }
+ if (strm->zfree == (free_func)0) strm->zfree = zcfree;
+ state = (struct inflate_state FAR *)ZALLOC(strm, 1,
+ sizeof(struct inflate_state));
+ if (state == Z_NULL) return Z_MEM_ERROR;
+ Tracev((stderr, "inflate: allocated\n"));
+ strm->state = (struct internal_state FAR *)state;
+ state->dmax = 32768U;
+ state->wbits = windowBits;
+ state->wsize = 1U << windowBits;
+ state->window = window;
+ state->write = 0;
+ state->whave = 0;
+ return Z_OK;
+}
+
+/*
+ Return state with length and distance decoding tables and index sizes set to
+ fixed code decoding. Normally this returns fixed tables from inffixed.h.
+ If BUILDFIXED is defined, then instead this routine builds the tables the
+ first time it's called, and returns those tables the first time and
+ thereafter. This reduces the size of the code by about 2K bytes, in
+ exchange for a little execution time. However, BUILDFIXED should not be
+ used for threaded applications, since the rewriting of the tables and virgin
+ may not be thread-safe.
+ */
+local void fixedtables(state)
+struct inflate_state FAR *state;
+{
+#ifdef BUILDFIXED
+ static int virgin = 1;
+ static code *lenfix, *distfix;
+ static code fixed[544];
+
+ /* build fixed huffman tables if first call (may not be thread safe) */
+ if (virgin) {
+ unsigned sym, bits;
+ static code *next;
+
+ /* literal/length table */
+ sym = 0;
+ while (sym < 144) state->lens[sym++] = 8;
+ while (sym < 256) state->lens[sym++] = 9;
+ while (sym < 280) state->lens[sym++] = 7;
+ while (sym < 288) state->lens[sym++] = 8;
+ next = fixed;
+ lenfix = next;
+ bits = 9;
+ inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
+
+ /* distance table */
+ sym = 0;
+ while (sym < 32) state->lens[sym++] = 5;
+ distfix = next;
+ bits = 5;
+ inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
+
+ /* do this just once */
+ virgin = 0;
+ }
+#else /* !BUILDFIXED */
+# include "inffixed.h"
+#endif /* BUILDFIXED */
+ state->lencode = lenfix;
+ state->lenbits = 9;
+ state->distcode = distfix;
+ state->distbits = 5;
+}
+
+/* Macros for inflateBack(): */
+
+/* Load returned state from inflate_fast() */
+#define LOAD() \
+ do { \
+ put = strm->next_out; \
+ left = strm->avail_out; \
+ next = strm->next_in; \
+ have = strm->avail_in; \
+ hold = state->hold; \
+ bits = state->bits; \
+ } while (0)
+
+/* Set state from registers for inflate_fast() */
+#define RESTORE() \
+ do { \
+ strm->next_out = put; \
+ strm->avail_out = left; \
+ strm->next_in = next; \
+ strm->avail_in = have; \
+ state->hold = hold; \
+ state->bits = bits; \
+ } while (0)
+
+/* Clear the input bit accumulator */
+#define INITBITS() \
+ do { \
+ hold = 0; \
+ bits = 0; \
+ } while (0)
+
+/* Assure that some input is available. If input is requested, but denied,
+ then return a Z_BUF_ERROR from inflateBack(). */
+#define PULL() \
+ do { \
+ if (have == 0) { \
+ have = in(in_desc, &next); \
+ if (have == 0) { \
+ next = Z_NULL; \
+ ret = Z_BUF_ERROR; \
+ goto inf_leave; \
+ } \
+ } \
+ } while (0)
+
+/* Get a byte of input into the bit accumulator, or return from inflateBack()
+ with an error if there is no input available. */
+#define PULLBYTE() \
+ do { \
+ PULL(); \
+ have--; \
+ hold += (unsigned long)(*next++) << bits; \
+ bits += 8; \
+ } while (0)
+
+/* Assure that there are at least n bits in the bit accumulator. If there is
+ not enough available input to do that, then return from inflateBack() with
+ an error. */
+#define NEEDBITS(n) \
+ do { \
+ while (bits < (unsigned)(n)) \
+ PULLBYTE(); \
+ } while (0)
+
+/* Return the low n bits of the bit accumulator (n < 16) */
+#define BITS(n) \
+ ((unsigned)hold & ((1U << (n)) - 1))
+
+/* Remove n bits from the bit accumulator */
+#define DROPBITS(n) \
+ do { \
+ hold >>= (n); \
+ bits -= (unsigned)(n); \
+ } while (0)
+
+/* Remove zero to seven bits as needed to go to a byte boundary */
+#define BYTEBITS() \
+ do { \
+ hold >>= bits & 7; \
+ bits -= bits & 7; \
+ } while (0)
+
+/* Assure that some output space is available, by writing out the window
+ if it's full. If the write fails, return from inflateBack() with a
+ Z_BUF_ERROR. */
+#define ROOM() \
+ do { \
+ if (left == 0) { \
+ put = state->window; \
+ left = state->wsize; \
+ state->whave = left; \
+ if (out(out_desc, put, left)) { \
+ ret = Z_BUF_ERROR; \
+ goto inf_leave; \
+ } \
+ } \
+ } while (0)
+
+/*
+ strm provides the memory allocation functions and window buffer on input,
+ and provides information on the unused input on return. For Z_DATA_ERROR
+ returns, strm will also provide an error message.
+
+ in() and out() are the call-back input and output functions. When
+ inflateBack() needs more input, it calls in(). When inflateBack() has
+ filled the window with output, or when it completes with data in the
+ window, it calls out() to write out the data. The application must not
+ change the provided input until in() is called again or inflateBack()
+ returns. The application must not change the window/output buffer until
+ inflateBack() returns.
+
+ in() and out() are called with a descriptor parameter provided in the
+ inflateBack() call. This parameter can be a structure that provides the
+ information required to do the read or write, as well as accumulated
+ information on the input and output such as totals and check values.
+
+ in() should return zero on failure. out() should return non-zero on
+ failure. If either in() or out() fails, than inflateBack() returns a
+ Z_BUF_ERROR. strm->next_in can be checked for Z_NULL to see whether it
+ was in() or out() that caused in the error. Otherwise, inflateBack()
+ returns Z_STREAM_END on success, Z_DATA_ERROR for an deflate format
+ error, or Z_MEM_ERROR if it could not allocate memory for the state.
+ inflateBack() can also return Z_STREAM_ERROR if the input parameters
+ are not correct, i.e. strm is Z_NULL or the state was not initialized.
+ */
+int ZEXPORT inflateBack(strm, in, in_desc, out, out_desc)
+z_streamp strm;
+in_func in;
+void FAR *in_desc;
+out_func out;
+void FAR *out_desc;
+{
+ struct inflate_state FAR *state;
+ z_const unsigned char FAR *next; /* next input */
+ unsigned char FAR *put; /* next output */
+ unsigned have, left; /* available input and output */
+ unsigned long hold; /* bit buffer */
+ unsigned bits; /* bits in bit buffer */
+ unsigned copy; /* number of stored or match bytes to copy */
+ unsigned char FAR *from; /* where to copy match bytes from */
+ code this; /* current decoding table entry */
+ code last; /* parent table entry */
+ unsigned len; /* length to copy for repeats, bits to drop */
+ int ret; /* return code */
+ static const unsigned short order[19] = /* permutation of code lengths */
+ {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
+
+ /* Check that the strm exists and that the state was initialized */
+ if (strm == Z_NULL || strm->state == Z_NULL)
+ return Z_STREAM_ERROR;
+ state = (struct inflate_state FAR *)strm->state;
+
+ /* Reset the state */
+ strm->msg = Z_NULL;
+ state->mode = TYPE;
+ state->last = 0;
+ state->whave = 0;
+ next = strm->next_in;
+ have = next != Z_NULL ? strm->avail_in : 0;
+ hold = 0;
+ bits = 0;
+ put = state->window;
+ left = state->wsize;
+
+ /* Inflate until end of block marked as last */
+ for (;;)
+ switch (state->mode) {
+ case TYPE:
+ /* determine and dispatch block type */
+ if (state->last) {
+ BYTEBITS();
+ state->mode = DONE;
+ break;
+ }
+ NEEDBITS(3);
+ state->last = BITS(1);
+ DROPBITS(1);
+ switch (BITS(2)) {
+ case 0: /* stored block */
+ Tracev((stderr, "inflate: stored block%s\n",
+ state->last ? " (last)" : ""));
+ state->mode = STORED;
+ break;
+ case 1: /* fixed block */
+ fixedtables(state);
+ Tracev((stderr, "inflate: fixed codes block%s\n",
+ state->last ? " (last)" : ""));
+ state->mode = LEN; /* decode codes */
+ break;
+ case 2: /* dynamic block */
+ Tracev((stderr, "inflate: dynamic codes block%s\n",
+ state->last ? " (last)" : ""));
+ state->mode = TABLE;
+ break;
+ case 3:
+#ifdef SMALL
+ strm->msg = "error";
+#else
+ strm->msg = (char *)"invalid block type";
+#endif
+ state->mode = BAD;
+ }
+ DROPBITS(2);
+ break;
+
+ case STORED:
+ /* get and verify stored block length */
+ BYTEBITS(); /* go to byte boundary */
+ NEEDBITS(32);
+ if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
+#ifdef SMALL
+ strm->msg = "error";
+#else
+ strm->msg = (char *)"invalid stored block lengths";
+#endif
+ state->mode = BAD;
+ break;
+ }
+ state->length = (unsigned)hold & 0xffff;
+ Tracev((stderr, "inflate: stored length %u\n",
+ state->length));
+ INITBITS();
+
+ /* copy stored block from input to output */
+ while (state->length != 0) {
+ copy = state->length;
+ PULL();
+ ROOM();
+ if (copy > have) copy = have;
+ if (copy > left) copy = left;
+ zmemcpy(put, next, copy);
+ have -= copy;
+ next += copy;
+ left -= copy;
+ put += copy;
+ state->length -= copy;
+ }
+ Tracev((stderr, "inflate: stored end\n"));
+ state->mode = TYPE;
+ break;
+
+ case TABLE:
+ /* get dynamic table entries descriptor */
+ NEEDBITS(14);
+ state->nlen = BITS(5) + 257;
+ DROPBITS(5);
+ state->ndist = BITS(5) + 1;
+ DROPBITS(5);
+ state->ncode = BITS(4) + 4;
+ DROPBITS(4);
+#ifndef PKZIP_BUG_WORKAROUND
+ if (state->nlen > 286 || state->ndist > 30) {
+#ifdef SMALL
+ strm->msg = "error";
+#else
+ strm->msg = (char *)"too many length or distance symbols";
+#endif
+ state->mode = BAD;
+ break;
+ }
+#endif
+ Tracev((stderr, "inflate: table sizes ok\n"));
+
+ /* get code length code lengths (not a typo) */
+ state->have = 0;
+ while (state->have < state->ncode) {
+ NEEDBITS(3);
+ state->lens[order[state->have++]] = (unsigned short)BITS(3);
+ DROPBITS(3);
+ }
+ while (state->have < 19)
+ state->lens[order[state->have++]] = 0;
+ state->next = state->codes;
+ state->lencode = (code const FAR *)(state->next);
+ state->lenbits = 7;
+ ret = inflate_table(CODES, state->lens, 19, &(state->next),
+ &(state->lenbits), state->work);
+ if (ret) {
+ strm->msg = (char *)"invalid code lengths set";
+ state->mode = BAD;
+ break;
+ }
+ Tracev((stderr, "inflate: code lengths ok\n"));
+
+ /* get length and distance code code lengths */
+ state->have = 0;
+ while (state->have < state->nlen + state->ndist) {
+ for (;;) {
+ this = state->lencode[BITS(state->lenbits)];
+ if ((unsigned)(this.bits) <= bits) break;
+ PULLBYTE();
+ }
+ if (this.val < 16) {
+ NEEDBITS(this.bits);
+ DROPBITS(this.bits);
+ state->lens[state->have++] = this.val;
+ }
+ else {
+ if (this.val == 16) {
+ NEEDBITS(this.bits + 2);
+ DROPBITS(this.bits);
+ if (state->have == 0) {
+ strm->msg = (char *)"invalid bit length repeat";
+ state->mode = BAD;
+ break;
+ }
+ len = (unsigned)(state->lens[state->have - 1]);
+ copy = 3 + BITS(2);
+ DROPBITS(2);
+ }
+ else if (this.val == 17) {
+ NEEDBITS(this.bits + 3);
+ DROPBITS(this.bits);
+ len = 0;
+ copy = 3 + BITS(3);
+ DROPBITS(3);
+ }
+ else {
+ NEEDBITS(this.bits + 7);
+ DROPBITS(this.bits);
+ len = 0;
+ copy = 11 + BITS(7);
+ DROPBITS(7);
+ }
+ if (state->have + copy > state->nlen + state->ndist) {
+ strm->msg = (char *)"invalid bit length repeat";
+ state->mode = BAD;
+ break;
+ }
+ while (copy--)
+ state->lens[state->have++] = (unsigned short)len;
+ }
+ }
+
+ /* handle error breaks in while */
+ if (state->mode == BAD) break;
+
+ /* build code tables */
+ state->next = state->codes;
+ state->lencode = (code const FAR *)(state->next);
+ state->lenbits = 9;
+ ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
+ &(state->lenbits), state->work);
+ if (ret) {
+ strm->msg = (char *)"invalid literal/lengths set";
+ state->mode = BAD;
+ break;
+ }
+ state->distcode = (code const FAR *)(state->next);
+ state->distbits = 6;
+ ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
+ &(state->next), &(state->distbits), state->work);
+ if (ret) {
+ strm->msg = (char *)"invalid distances set";
+ state->mode = BAD;
+ break;
+ }
+ Tracev((stderr, "inflate: codes ok\n"));
+ state->mode = LEN;
+
+ case LEN:
+#ifndef SLOW
+ /* use inflate_fast() if we have enough input and output */
+ if (have >= 6 && left >= 258) {
+ RESTORE();
+ if (state->whave < state->wsize)
+ state->whave = state->wsize - left;
+ inflate_fast(strm, state->wsize);
+ LOAD();
+ break;
+ }
+#endif
+
+ /* get a literal, length, or end-of-block code */
+ for (;;) {
+ this = state->lencode[BITS(state->lenbits)];
+ if ((unsigned)(this.bits) <= bits) break;
+ PULLBYTE();
+ }
+ if (this.op && (this.op & 0xf0) == 0) {
+ last = this;
+ for (;;) {
+ this = state->lencode[last.val +
+ (BITS(last.bits + last.op) >> last.bits)];
+ if ((unsigned)(last.bits + this.bits) <= bits) break;
+ PULLBYTE();
+ }
+ DROPBITS(last.bits);
+ }
+ DROPBITS(this.bits);
+ state->length = (unsigned)this.val;
+
+ /* process literal */
+ if (this.op == 0) {
+ Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
+ "inflate: literal '%c'\n" :
+ "inflate: literal 0x%02x\n", this.val));
+ ROOM();
+ *put++ = (unsigned char)(state->length);
+ left--;
+ state->mode = LEN;
+ break;
+ }
+
+ /* process end of block */
+ if (this.op & 32) {
+ Tracevv((stderr, "inflate: end of block\n"));
+ state->mode = TYPE;
+ break;
+ }
+
+ /* invalid code */
+ if (this.op & 64) {
+ strm->msg = (char *)"invalid literal/length code";
+ state->mode = BAD;
+ break;
+ }
+
+ /* length code -- get extra bits, if any */
+ state->extra = (unsigned)(this.op) & 15;
+ if (state->extra != 0) {
+ NEEDBITS(state->extra);
+ state->length += BITS(state->extra);
+ DROPBITS(state->extra);
+ }
+ Tracevv((stderr, "inflate: length %u\n", state->length));
+
+ /* get distance code */
+ for (;;) {
+ this = state->distcode[BITS(state->distbits)];
+ if ((unsigned)(this.bits) <= bits) break;
+ PULLBYTE();
+ }
+ if ((this.op & 0xf0) == 0) {
+ last = this;
+ for (;;) {
+ this = state->distcode[last.val +
+ (BITS(last.bits + last.op) >> last.bits)];
+ if ((unsigned)(last.bits + this.bits) <= bits) break;
+ PULLBYTE();
+ }
+ DROPBITS(last.bits);
+ }
+ DROPBITS(this.bits);
+ if (this.op & 64) {
+ strm->msg = (char *)"invalid distance code";
+ state->mode = BAD;
+ break;
+ }
+ state->offset = (unsigned)this.val;
+
+ /* get distance extra bits, if any */
+ state->extra = (unsigned)(this.op) & 15;
+ if (state->extra != 0) {
+ NEEDBITS(state->extra);
+ state->offset += BITS(state->extra);
+ DROPBITS(state->extra);
+ }
+ if (state->offset > state->wsize - (state->whave < state->wsize ?
+ left : 0)) {
+ strm->msg = (char *)"invalid distance too far back";
+ state->mode = BAD;
+ break;
+ }
+ Tracevv((stderr, "inflate: distance %u\n", state->offset));
+
+ /* copy match from window to output */
+ do {
+ ROOM();
+ copy = state->wsize - state->offset;
+ if (copy < left) {
+ from = put + copy;
+ copy = left - copy;
+ }
+ else {
+ from = put - state->offset;
+ copy = left;
+ }
+ if (copy > state->length) copy = state->length;
+ state->length -= copy;
+ left -= copy;
+ do {
+ *put++ = *from++;
+ } while (--copy);
+ } while (state->length != 0);
+ break;
+
+ case DONE:
+ /* inflate stream terminated properly -- write leftover output */
+ ret = Z_STREAM_END;
+ if (left < state->wsize) {
+ if (out(out_desc, state->window, state->wsize - left))
+ ret = Z_BUF_ERROR;
+ }
+ goto inf_leave;
+
+ case BAD:
+ ret = Z_DATA_ERROR;
+ goto inf_leave;
+
+ default: /* can't happen, but makes compilers happy */
+ ret = Z_STREAM_ERROR;
+ goto inf_leave;
+ }
+
+ /* Return unused input */
+ inf_leave:
+ strm->next_in = next;
+ strm->avail_in = have;
+ return ret;
+}
+
+int ZEXPORT inflateBackEnd(strm)
+z_streamp strm;
+{
+ if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
+ return Z_STREAM_ERROR;
+ ZFREE(strm, strm->state);
+ strm->state = Z_NULL;
+ Tracev((stderr, "inflate: end\n"));
+ return Z_OK;
+}
diff --git a/lib/libz/inffast.c b/lib/libz/inffast.c
new file mode 100644
index 0000000..988806c
--- /dev/null
+++ b/lib/libz/inffast.c
@@ -0,0 +1,331 @@
+/* $OpenBSD: inffast.c,v 1.8 2019/06/01 11:39:57 jca Exp $ */
+/* inffast.c -- fast decoding
+ * Copyright (C) 1995-2004 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#include "zutil.h"
+#include "inftrees.h"
+#include "inflate.h"
+#include "inffast.h"
+
+#ifndef ASMINF
+
+/* Allow machine dependent optimization for post-increment or pre-increment.
+ Based on testing to date,
+ Pre-increment preferred for:
+ - PowerPC G3 (Adler)
+ - MIPS R5000 (Randers-Pehrson)
+ Post-increment preferred for:
+ - none
+ No measurable difference:
+ - Pentium III (Anderson)
+ - M68060 (Nikl)
+ */
+#ifdef POSTINC
+# define OFF 0
+# define PUP(a) *(a)++
+#else
+# define OFF 1
+# define PUP(a) *++(a)
+#endif
+
+/*
+ Decode literal, length, and distance codes and write out the resulting
+ literal and match bytes until either not enough input or output is
+ available, an end-of-block is encountered, or a data error is encountered.
+ When large enough input and output buffers are supplied to inflate(), for
+ example, a 16K input buffer and a 64K output buffer, more than 95% of the
+ inflate execution time is spent in this routine.
+
+ Entry assumptions:
+
+ state->mode == LEN
+ strm->avail_in >= 6
+ strm->avail_out >= 258
+ start >= strm->avail_out
+ state->bits < 8
+
+ On return, state->mode is one of:
+
+ LEN -- ran out of enough output space or enough available input
+ TYPE -- reached end of block code, inflate() to interpret next block
+ BAD -- error in block data
+
+ Notes:
+
+ - The maximum input bits used by a length/distance pair is 15 bits for the
+ length code, 5 bits for the length extra, 15 bits for the distance code,
+ and 13 bits for the distance extra. This totals 48 bits, or six bytes.
+ Therefore if strm->avail_in >= 6, then there is enough input to avoid
+ checking for available input while decoding.
+
+ - The maximum bytes that a single length/distance pair can output is 258
+ bytes, which is the maximum length that can be coded. inflate_fast()
+ requires strm->avail_out >= 258 for each loop to avoid checking for
+ output space.
+ */
+void inflate_fast(strm, start)
+z_streamp strm;
+unsigned start; /* inflate()'s starting value for strm->avail_out */
+{
+ struct inflate_state FAR *state;
+ z_const unsigned char FAR *in; /* local strm->next_in */
+ z_const unsigned char FAR *last; /* while in < last, enough input available */
+ unsigned char FAR *out; /* local strm->next_out */
+ unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
+ unsigned char FAR *end; /* while out < end, enough space available */
+#ifdef INFLATE_STRICT
+ unsigned dmax; /* maximum distance from zlib header */
+#endif
+ unsigned wsize; /* window size or zero if not using window */
+ unsigned whave; /* valid bytes in the window */
+ unsigned write; /* window write index */
+ unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
+ unsigned long hold; /* local strm->hold */
+ unsigned bits; /* local strm->bits */
+ code const FAR *lcode; /* local strm->lencode */
+ code const FAR *dcode; /* local strm->distcode */
+ unsigned lmask; /* mask for first level of length codes */
+ unsigned dmask; /* mask for first level of distance codes */
+ code this; /* retrieved table entry */
+ unsigned op; /* code bits, operation, extra bits, or */
+ /* window position, window bytes to copy */
+ unsigned len; /* match length, unused bytes */
+ unsigned dist; /* match distance */
+ unsigned char FAR *from; /* where to copy match from */
+
+ /* copy state to local variables */
+ state = (struct inflate_state FAR *)strm->state;
+ in = strm->next_in - OFF;
+ last = in + (strm->avail_in - 5);
+ out = strm->next_out - OFF;
+ beg = out - (start - strm->avail_out);
+ end = out + (strm->avail_out - 257);
+#ifdef INFLATE_STRICT
+ dmax = state->dmax;
+#endif
+ wsize = state->wsize;
+ whave = state->whave;
+ write = state->write;
+ window = state->window;
+ hold = state->hold;
+ bits = state->bits;
+ lcode = state->lencode;
+ dcode = state->distcode;
+ lmask = (1U << state->lenbits) - 1;
+ dmask = (1U << state->distbits) - 1;
+
+ /* decode literals and length/distances until end-of-block or not enough
+ input data or output space */
+ do {
+ if (bits < 15) {
+ hold += (unsigned long)(PUP(in)) << bits;
+ bits += 8;
+ hold += (unsigned long)(PUP(in)) << bits;
+ bits += 8;
+ }
+ this = lcode[hold & lmask];
+ dolen:
+ op = (unsigned)(this.bits);
+ hold >>= op;
+ bits -= op;
+ op = (unsigned)(this.op);
+ if (op == 0) { /* literal */
+ Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
+ "inflate: literal '%c'\n" :
+ "inflate: literal 0x%02x\n", this.val));
+ PUP(out) = (unsigned char)(this.val);
+ }
+ else if (op & 16) { /* length base */
+ len = (unsigned)(this.val);
+ op &= 15; /* number of extra bits */
+ if (op) {
+ if (bits < op) {
+ hold += (unsigned long)(PUP(in)) << bits;
+ bits += 8;
+ }
+ len += (unsigned)hold & ((1U << op) - 1);
+ hold >>= op;
+ bits -= op;
+ }
+ Tracevv((stderr, "inflate: length %u\n", len));
+ if (bits < 15) {
+ hold += (unsigned long)(PUP(in)) << bits;
+ bits += 8;
+ hold += (unsigned long)(PUP(in)) << bits;
+ bits += 8;
+ }
+ this = dcode[hold & dmask];
+ dodist:
+ op = (unsigned)(this.bits);
+ hold >>= op;
+ bits -= op;
+ op = (unsigned)(this.op);
+ if (op & 16) { /* distance base */
+ dist = (unsigned)(this.val);
+ op &= 15; /* number of extra bits */
+ if (bits < op) {
+ hold += (unsigned long)(PUP(in)) << bits;
+ bits += 8;
+ if (bits < op) {
+ hold += (unsigned long)(PUP(in)) << bits;
+ bits += 8;
+ }
+ }
+ dist += (unsigned)hold & ((1U << op) - 1);
+#ifdef INFLATE_STRICT
+ if (dist > dmax) {
+ strm->msg = (char *)"invalid distance too far back";
+ state->mode = BAD;
+ break;
+ }
+#endif
+ hold >>= op;
+ bits -= op;
+ Tracevv((stderr, "inflate: distance %u\n", dist));
+ op = (unsigned)(out - beg); /* max distance in output */
+ if (dist > op) { /* see if copy from window */
+ op = dist - op; /* distance back in window */
+ if (op > whave) {
+#ifdef SMALL
+ strm->msg = "error";
+#else
+ strm->msg = (char *)"invalid distance too far back";
+#endif
+ state->mode = BAD;
+ break;
+ }
+ from = window - OFF;
+ if (write == 0) { /* very common case */
+ from += wsize - op;
+ if (op < len) { /* some from window */
+ len -= op;
+ do {
+ PUP(out) = PUP(from);
+ } while (--op);
+ from = out - dist; /* rest from output */
+ }
+ }
+ else if (write < op) { /* wrap around window */
+ from += wsize + write - op;
+ op -= write;
+ if (op < len) { /* some from end of window */
+ len -= op;
+ do {
+ PUP(out) = PUP(from);
+ } while (--op);
+ from = window - OFF;
+ if (write < len) { /* some from start of window */
+ op = write;
+ len -= op;
+ do {
+ PUP(out) = PUP(from);
+ } while (--op);
+ from = out - dist; /* rest from output */
+ }
+ }
+ }
+ else { /* contiguous in window */
+ from += write - op;
+ if (op < len) { /* some from window */
+ len -= op;
+ do {
+ PUP(out) = PUP(from);
+ } while (--op);
+ from = out - dist; /* rest from output */
+ }
+ }
+ while (len > 2) {
+ PUP(out) = PUP(from);
+ PUP(out) = PUP(from);
+ PUP(out) = PUP(from);
+ len -= 3;
+ }
+ if (len) {
+ PUP(out) = PUP(from);
+ if (len > 1)
+ PUP(out) = PUP(from);
+ }
+ }
+ else {
+ from = out - dist; /* copy direct from output */
+ do { /* minimum length is three */
+ PUP(out) = PUP(from);
+ PUP(out) = PUP(from);
+ PUP(out) = PUP(from);
+ len -= 3;
+ } while (len > 2);
+ if (len) {
+ PUP(out) = PUP(from);
+ if (len > 1)
+ PUP(out) = PUP(from);
+ }
+ }
+ }
+ else if ((op & 64) == 0) { /* 2nd level distance code */
+ this = dcode[this.val + (hold & ((1U << op) - 1))];
+ goto dodist;
+ }
+ else {
+#ifdef SMALL
+ strm->msg = "error";
+#else
+ strm->msg = (char *)"invalid distance code";
+#endif
+ state->mode = BAD;
+ break;
+ }
+ }
+ else if ((op & 64) == 0) { /* 2nd level length code */
+ this = lcode[this.val + (hold & ((1U << op) - 1))];
+ goto dolen;
+ }
+ else if (op & 32) { /* end-of-block */
+ Tracevv((stderr, "inflate: end of block\n"));
+ state->mode = TYPE;
+ break;
+ }
+ else {
+#ifdef SMALL
+ strm->msg = "error";
+#else
+ strm->msg = (char *)"invalid literal/length code";
+#endif
+ state->mode = BAD;
+ break;
+ }
+ } while (in < last && out < end);
+
+ /* return unused bytes (on entry, bits < 8, so in won't go too far back) */
+ len = bits >> 3;
+ in -= len;
+ bits -= len << 3;
+ hold &= (1U << bits) - 1;
+
+ /* update state and return */
+ strm->next_in = in + OFF;
+ strm->next_out = out + OFF;
+ strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
+ strm->avail_out = (unsigned)(out < end ?
+ 257 + (end - out) : 257 - (out - end));
+ state->hold = hold;
+ state->bits = bits;
+ return;
+}
+
+/*
+ inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe):
+ - Using bit fields for code structure
+ - Different op definition to avoid & for extra bits (do & for table bits)
+ - Three separate decoding do-loops for direct, window, and write == 0
+ - Special case for distance > 1 copies to do overlapped load and store copy
+ - Explicit branch predictions (based on measured branch probabilities)
+ - Deferring match copy and interspersed it with decoding subsequent codes
+ - Swapping literal/length else
+ - Swapping window/direct else
+ - Larger unrolled copy loops (three is about right)
+ - Moving len -= 3 statement into middle of loop
+ */
+
+#endif /* !ASMINF */
diff --git a/lib/libz/inffast.h b/lib/libz/inffast.h
new file mode 100644
index 0000000..0283eea
--- /dev/null
+++ b/lib/libz/inffast.h
@@ -0,0 +1,12 @@
+/* $OpenBSD: inffast.h,v 1.4 2003/12/16 22:33:02 henning Exp $ */
+/* inffast.h -- header to use inffast.c
+ * Copyright (C) 1995-2003 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+ part of the implementation of the compression library and is
+ subject to change. Applications should only use zlib.h.
+ */
+
+void inflate_fast OF((z_streamp strm, unsigned start));
diff --git a/lib/libz/inffixed.h b/lib/libz/inffixed.h
new file mode 100644
index 0000000..be9fb24
--- /dev/null
+++ b/lib/libz/inffixed.h
@@ -0,0 +1,95 @@
+/* $OpenBSD: inffixed.h,v 1.3 2003/12/16 22:33:02 henning Exp $ */
+ /* inffixed.h -- table for decoding fixed codes
+ * Generated automatically by makefixed().
+ */
+
+ /* WARNING: this file should *not* be used by applications. It
+ is part of the implementation of the compression library and
+ is subject to change. Applications should only use zlib.h.
+ */
+
+ static const code lenfix[512] = {
+ {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
+ {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
+ {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
+ {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
+ {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
+ {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
+ {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
+ {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
+ {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
+ {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
+ {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
+ {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
+ {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
+ {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
+ {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
+ {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
+ {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
+ {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
+ {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
+ {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
+ {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
+ {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
+ {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
+ {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
+ {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
+ {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
+ {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
+ {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
+ {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
+ {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
+ {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
+ {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
+ {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
+ {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
+ {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
+ {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
+ {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
+ {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
+ {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
+ {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
+ {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
+ {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
+ {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
+ {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
+ {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
+ {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
+ {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
+ {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
+ {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
+ {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
+ {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
+ {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
+ {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
+ {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
+ {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
+ {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
+ {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
+ {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
+ {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
+ {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
+ {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
+ {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
+ {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
+ {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
+ {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
+ {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
+ {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
+ {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
+ {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
+ {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
+ {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
+ {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
+ {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
+ {0,9,255}
+ };
+
+ static const code distfix[32] = {
+ {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
+ {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
+ {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
+ {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
+ {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
+ {22,5,193},{64,5,0}
+ };
diff --git a/lib/libz/inflate.c b/lib/libz/inflate.c
new file mode 100644
index 0000000..37930a9
--- /dev/null
+++ b/lib/libz/inflate.c
@@ -0,0 +1,1447 @@
+/* $OpenBSD: inflate.c,v 1.10 2019/06/01 11:39:57 jca Exp $ */
+/* inflate.c -- zlib decompression
+ * Copyright (C) 1995-2005 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/*
+ * Change history:
+ *
+ * 1.2.beta0 24 Nov 2002
+ * - First version -- complete rewrite of inflate to simplify code, avoid
+ * creation of window when not needed, minimize use of window when it is
+ * needed, make inffast.c even faster, implement gzip decoding, and to
+ * improve code readability and style over the previous zlib inflate code
+ *
+ * 1.2.beta1 25 Nov 2002
+ * - Use pointers for available input and output checking in inffast.c
+ * - Remove input and output counters in inffast.c
+ * - Change inffast.c entry and loop from avail_in >= 7 to >= 6
+ * - Remove unnecessary second byte pull from length extra in inffast.c
+ * - Unroll direct copy to three copies per loop in inffast.c
+ *
+ * 1.2.beta2 4 Dec 2002
+ * - Change external routine names to reduce potential conflicts
+ * - Correct filename to inffixed.h for fixed tables in inflate.c
+ * - Make hbuf[] unsigned char to match parameter type in inflate.c
+ * - Change strm->next_out[-state->offset] to *(strm->next_out - state->offset)
+ * to avoid negation problem on Alphas (64 bit) in inflate.c
+ *
+ * 1.2.beta3 22 Dec 2002
+ * - Add comments on state->bits assertion in inffast.c
+ * - Add comments on op field in inftrees.h
+ * - Fix bug in reuse of allocated window after inflateReset()
+ * - Remove bit fields--back to byte structure for speed
+ * - Remove distance extra == 0 check in inflate_fast()--only helps for lengths
+ * - Change post-increments to pre-increments in inflate_fast(), PPC biased?
+ * - Add compile time option, POSTINC, to use post-increments instead (Intel?)
+ * - Make MATCH copy in inflate() much faster for when inflate_fast() not used
+ * - Use local copies of stream next and avail values, as well as local bit
+ * buffer and bit count in inflate()--for speed when inflate_fast() not used
+ *
+ * 1.2.beta4 1 Jan 2003
+ * - Split ptr - 257 statements in inflate_table() to avoid compiler warnings
+ * - Move a comment on output buffer sizes from inffast.c to inflate.c
+ * - Add comments in inffast.c to introduce the inflate_fast() routine
+ * - Rearrange window copies in inflate_fast() for speed and simplification
+ * - Unroll last copy for window match in inflate_fast()
+ * - Use local copies of window variables in inflate_fast() for speed
+ * - Pull out common write == 0 case for speed in inflate_fast()
+ * - Make op and len in inflate_fast() unsigned for consistency
+ * - Add FAR to lcode and dcode declarations in inflate_fast()
+ * - Simplified bad distance check in inflate_fast()
+ * - Added inflateBackInit(), inflateBack(), and inflateBackEnd() in new
+ * source file infback.c to provide a call-back interface to inflate for
+ * programs like gzip and unzip -- uses window as output buffer to avoid
+ * window copying
+ *
+ * 1.2.beta5 1 Jan 2003
+ * - Improved inflateBack() interface to allow the caller to provide initial
+ * input in strm.
+ * - Fixed stored blocks bug in inflateBack()
+ *
+ * 1.2.beta6 4 Jan 2003
+ * - Added comments in inffast.c on effectiveness of POSTINC
+ * - Typecasting all around to reduce compiler warnings
+ * - Changed loops from while (1) or do {} while (1) to for (;;), again to
+ * make compilers happy
+ * - Changed type of window in inflateBackInit() to unsigned char *
+ *
+ * 1.2.beta7 27 Jan 2003
+ * - Changed many types to unsigned or unsigned short to avoid warnings
+ * - Added inflateCopy() function
+ *
+ * 1.2.0 9 Mar 2003
+ * - Changed inflateBack() interface to provide separate opaque descriptors
+ * for the in() and out() functions
+ * - Changed inflateBack() argument and in_func typedef to swap the length
+ * and buffer address return values for the input function
+ * - Check next_in and next_out for Z_NULL on entry to inflate()
+ *
+ * The history for versions after 1.2.0 are in ChangeLog in zlib distribution.
+ */
+
+#include "zutil.h"
+#include "inftrees.h"
+#include "inflate.h"
+#include "inffast.h"
+
+#ifdef MAKEFIXED
+# ifndef BUILDFIXED
+# define BUILDFIXED
+# endif
+#endif
+
+/* function prototypes */
+local void fixedtables OF((struct inflate_state FAR *state));
+local int updatewindow OF((z_streamp strm, unsigned out));
+#ifdef BUILDFIXED
+ void makefixed OF((void));
+#endif
+local unsigned syncsearch OF((unsigned FAR *have, z_const unsigned char FAR *buf,
+ unsigned len));
+
+int ZEXPORT inflateReset(strm)
+z_streamp strm;
+{
+ struct inflate_state FAR *state;
+
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ state = (struct inflate_state FAR *)strm->state;
+ strm->total_in = strm->total_out = state->total = 0;
+ strm->msg = Z_NULL;
+ strm->adler = 1; /* to support ill-conceived Java test suite */
+ state->mode = HEAD;
+ state->last = 0;
+ state->havedict = 0;
+ state->dmax = 32768U;
+ state->head = Z_NULL;
+ state->wsize = 0;
+ state->whave = 0;
+ state->write = 0;
+ state->hold = 0;
+ state->bits = 0;
+ state->lencode = state->distcode = state->next = state->codes;
+ Tracev((stderr, "inflate: reset\n"));
+ return Z_OK;
+}
+
+int ZEXPORT inflatePrime(strm, bits, value)
+z_streamp strm;
+int bits;
+int value;
+{
+ struct inflate_state FAR *state;
+
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ state = (struct inflate_state FAR *)strm->state;
+ if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
+ value &= (1L << bits) - 1;
+ state->hold += value << state->bits;
+ state->bits += bits;
+ return Z_OK;
+}
+
+int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size)
+z_streamp strm;
+int windowBits;
+const char *version;
+int stream_size;
+{
+ struct inflate_state FAR *state;
+
+ if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
+ stream_size != (int)(sizeof(z_stream)))
+ return Z_VERSION_ERROR;
+ if (strm == Z_NULL) return Z_STREAM_ERROR;
+ strm->msg = Z_NULL; /* in case we return an error */
+ if (strm->zalloc == (alloc_func)0) {
+ strm->zalloc = zcalloc;
+ strm->opaque = (voidpf)0;
+ }
+ if (strm->zfree == (free_func)0) strm->zfree = zcfree;
+ state = (struct inflate_state FAR *)
+ ZALLOC(strm, 1, sizeof(struct inflate_state));
+ if (state == Z_NULL) return Z_MEM_ERROR;
+ Tracev((stderr, "inflate: allocated\n"));
+ strm->state = (struct internal_state FAR *)state;
+ if (windowBits < 0) {
+ state->wrap = 0;
+ windowBits = -windowBits;
+ }
+ else {
+ state->wrap = (windowBits >> 4) + 1;
+#ifdef GUNZIP
+ if (windowBits < 48) windowBits &= 15;
+#endif
+ }
+ if (windowBits < 8 || windowBits > 15) {
+ ZFREE(strm, state);
+ strm->state = Z_NULL;
+ return Z_STREAM_ERROR;
+ }
+ state->wbits = (unsigned)windowBits;
+ state->window = Z_NULL;
+ return inflateReset(strm);
+}
+
+int ZEXPORT inflateInit_(strm, version, stream_size)
+z_streamp strm;
+const char *version;
+int stream_size;
+{
+ return inflateInit2_(strm, DEF_WBITS, version, stream_size);
+}
+
+/*
+ Return state with length and distance decoding tables and index sizes set to
+ fixed code decoding. Normally this returns fixed tables from inffixed.h.
+ If BUILDFIXED is defined, then instead this routine builds the tables the
+ first time it's called, and returns those tables the first time and
+ thereafter. This reduces the size of the code by about 2K bytes, in
+ exchange for a little execution time. However, BUILDFIXED should not be
+ used for threaded applications, since the rewriting of the tables and virgin
+ may not be thread-safe.
+ */
+local void fixedtables(state)
+struct inflate_state FAR *state;
+{
+#ifdef BUILDFIXED
+ static int virgin = 1;
+ static code *lenfix, *distfix;
+ static code fixed[544];
+
+ /* build fixed huffman tables if first call (may not be thread safe) */
+ if (virgin) {
+ unsigned sym, bits;
+ static code *next;
+
+ /* literal/length table */
+ sym = 0;
+ while (sym < 144) state->lens[sym++] = 8;
+ while (sym < 256) state->lens[sym++] = 9;
+ while (sym < 280) state->lens[sym++] = 7;
+ while (sym < 288) state->lens[sym++] = 8;
+ next = fixed;
+ lenfix = next;
+ bits = 9;
+ inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
+
+ /* distance table */
+ sym = 0;
+ while (sym < 32) state->lens[sym++] = 5;
+ distfix = next;
+ bits = 5;
+ inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
+
+ /* do this just once */
+ virgin = 0;
+ }
+#else /* !BUILDFIXED */
+# include "inffixed.h"
+#endif /* BUILDFIXED */
+ state->lencode = lenfix;
+ state->lenbits = 9;
+ state->distcode = distfix;
+ state->distbits = 5;
+}
+
+#ifdef MAKEFIXED
+#include <stdio.h>
+
+/*
+ Write out the inffixed.h that is #include'd above. Defining MAKEFIXED also
+ defines BUILDFIXED, so the tables are built on the fly. makefixed() writes
+ those tables to stdout, which would be piped to inffixed.h. A small program
+ can simply call makefixed to do this:
+
+ void makefixed(void);
+
+ int main(void)
+ {
+ makefixed();
+ return 0;
+ }
+
+ Then that can be linked with zlib built with MAKEFIXED defined and run:
+
+ a.out > inffixed.h
+ */
+void makefixed()
+{
+ unsigned low, size;
+ struct inflate_state state;
+
+ fixedtables(&state);
+ puts(" /* inffixed.h -- table for decoding fixed codes");
+ puts(" * Generated automatically by makefixed().");
+ puts(" */");
+ puts("");
+ puts(" /* WARNING: this file should *not* be used by applications.");
+ puts(" It is part of the implementation of this library and is");
+ puts(" subject to change. Applications should only use zlib.h.");
+ puts(" */");
+ puts("");
+ size = 1U << 9;
+ printf(" static const code lenfix[%u] = {", size);
+ low = 0;
+ for (;;) {
+ if ((low % 7) == 0) printf("\n ");
+ printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
+ state.lencode[low].val);
+ if (++low == size) break;
+ putchar(',');
+ }
+ puts("\n };");
+ size = 1U << 5;
+ printf("\n static const code distfix[%u] = {", size);
+ low = 0;
+ for (;;) {
+ if ((low % 6) == 0) printf("\n ");
+ printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
+ state.distcode[low].val);
+ if (++low == size) break;
+ putchar(',');
+ }
+ puts("\n };");
+}
+#endif /* MAKEFIXED */
+
+/*
+ Update the window with the last wsize (normally 32K) bytes written before
+ returning. If window does not exist yet, create it. This is only called
+ when a window is already in use, or when output has been written during this
+ inflate call, but the end of the deflate stream has not been reached yet.
+ It is also called to create a window for dictionary data when a dictionary
+ is loaded.
+
+ Providing output buffers larger than 32K to inflate() should provide a speed
+ advantage, since only the last 32K of output is copied to the sliding window
+ upon return from inflate(), and since all distances after the first 32K of
+ output will fall in the output data, making match copies simpler and faster.
+ The advantage may be dependent on the size of the processor's data caches.
+ */
+local int updatewindow(strm, out)
+z_streamp strm;
+unsigned out;
+{
+ struct inflate_state FAR *state;
+ unsigned copy, dist;
+
+ state = (struct inflate_state FAR *)strm->state;
+
+ /* if it hasn't been done already, allocate space for the window */
+ if (state->window == Z_NULL) {
+ state->window = (unsigned char FAR *)
+ ZALLOC(strm, 1U << state->wbits,
+ sizeof(unsigned char));
+ if (state->window == Z_NULL) return 1;
+ }
+
+ /* if window not in use yet, initialize */
+ if (state->wsize == 0) {
+ state->wsize = 1U << state->wbits;
+ state->write = 0;
+ state->whave = 0;
+ }
+
+ /* copy state->wsize or less output bytes into the circular window */
+ copy = out - strm->avail_out;
+ if (copy >= state->wsize) {
+ zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
+ state->write = 0;
+ state->whave = state->wsize;
+ }
+ else {
+ dist = state->wsize - state->write;
+ if (dist > copy) dist = copy;
+ zmemcpy(state->window + state->write, strm->next_out - copy, dist);
+ copy -= dist;
+ if (copy) {
+ zmemcpy(state->window, strm->next_out - copy, copy);
+ state->write = copy;
+ state->whave = state->wsize;
+ }
+ else {
+ state->write += dist;
+ if (state->write == state->wsize) state->write = 0;
+ if (state->whave < state->wsize) state->whave += dist;
+ }
+ }
+ return 0;
+}
+
+/* Macros for inflate(): */
+
+/* check function to use adler32() for zlib or crc32() for gzip */
+#ifdef GUNZIP
+# define UPDATE(check, buf, len) \
+ (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
+#else
+# define UPDATE(check, buf, len) adler32(check, buf, len)
+#endif
+
+/* check macros for header crc */
+#ifdef GUNZIP
+# define CRC2(check, word) \
+ do { \
+ hbuf[0] = (unsigned char)(word); \
+ hbuf[1] = (unsigned char)((word) >> 8); \
+ check = crc32(check, hbuf, 2); \
+ } while (0)
+
+# define CRC4(check, word) \
+ do { \
+ hbuf[0] = (unsigned char)(word); \
+ hbuf[1] = (unsigned char)((word) >> 8); \
+ hbuf[2] = (unsigned char)((word) >> 16); \
+ hbuf[3] = (unsigned char)((word) >> 24); \
+ check = crc32(check, hbuf, 4); \
+ } while (0)
+#endif
+
+/* Load registers with state in inflate() for speed */
+#define LOAD() \
+ do { \
+ put = strm->next_out; \
+ left = strm->avail_out; \
+ next = strm->next_in; \
+ have = strm->avail_in; \
+ hold = state->hold; \
+ bits = state->bits; \
+ } while (0)
+
+/* Restore state from registers in inflate() */
+#define RESTORE() \
+ do { \
+ strm->next_out = put; \
+ strm->avail_out = left; \
+ strm->next_in = next; \
+ strm->avail_in = have; \
+ state->hold = hold; \
+ state->bits = bits; \
+ } while (0)
+
+/* Clear the input bit accumulator */
+#define INITBITS() \
+ do { \
+ hold = 0; \
+ bits = 0; \
+ } while (0)
+
+/* Get a byte of input into the bit accumulator, or return from inflate()
+ if there is no input available. */
+#define PULLBYTE() \
+ do { \
+ if (have == 0) goto inf_leave; \
+ have--; \
+ hold += (unsigned long)(*next++) << bits; \
+ bits += 8; \
+ } while (0)
+
+/* Assure that there are at least n bits in the bit accumulator. If there is
+ not enough available input to do that, then return from inflate(). */
+#define NEEDBITS(n) \
+ do { \
+ while (bits < (unsigned)(n)) \
+ PULLBYTE(); \
+ } while (0)
+
+/* Return the low n bits of the bit accumulator (n < 16) */
+#define BITS(n) \
+ ((unsigned)hold & ((1U << (n)) - 1))
+
+/* Remove n bits from the bit accumulator */
+#define DROPBITS(n) \
+ do { \
+ hold >>= (n); \
+ bits -= (unsigned)(n); \
+ } while (0)
+
+/* Remove zero to seven bits as needed to go to a byte boundary */
+#define BYTEBITS() \
+ do { \
+ hold >>= bits & 7; \
+ bits -= bits & 7; \
+ } while (0)
+
+/* Reverse the bytes in a 32-bit value */
+#define REVERSE(q) \
+ ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
+ (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
+
+/*
+ inflate() uses a state machine to process as much input data and generate as
+ much output data as possible before returning. The state machine is
+ structured roughly as follows:
+
+ for (;;) switch (state) {
+ ...
+ case STATEn:
+ if (not enough input data or output space to make progress)
+ return;
+ ... make progress ...
+ state = STATEm;
+ break;
+ ...
+ }
+
+ so when inflate() is called again, the same case is attempted again, and
+ if the appropriate resources are provided, the machine proceeds to the
+ next state. The NEEDBITS() macro is usually the way the state evaluates
+ whether it can proceed or should return. NEEDBITS() does the return if
+ the requested bits are not available. The typical use of the BITS macros
+ is:
+
+ NEEDBITS(n);
+ ... do something with BITS(n) ...
+ DROPBITS(n);
+
+ where NEEDBITS(n) either returns from inflate() if there isn't enough
+ input left to load n bits into the accumulator, or it continues. BITS(n)
+ gives the low n bits in the accumulator. When done, DROPBITS(n) drops
+ the low n bits off the accumulator. INITBITS() clears the accumulator
+ and sets the number of available bits to zero. BYTEBITS() discards just
+ enough bits to put the accumulator on a byte boundary. After BYTEBITS()
+ and a NEEDBITS(8), then BITS(8) would return the next byte in the stream.
+
+ NEEDBITS(n) uses PULLBYTE() to get an available byte of input, or to return
+ if there is no input available. The decoding of variable length codes uses
+ PULLBYTE() directly in order to pull just enough bytes to decode the next
+ code, and no more.
+
+ Some states loop until they get enough input, making sure that enough
+ state information is maintained to continue the loop where it left off
+ if NEEDBITS() returns in the loop. For example, want, need, and keep
+ would all have to actually be part of the saved state in case NEEDBITS()
+ returns:
+
+ case STATEw:
+ while (want < need) {
+ NEEDBITS(n);
+ keep[want++] = BITS(n);
+ DROPBITS(n);
+ }
+ state = STATEx;
+ case STATEx:
+
+ As shown above, if the next state is also the next case, then the break
+ is omitted.
+
+ A state may also return if there is not enough output space available to
+ complete that state. Those states are copying stored data, writing a
+ literal byte, and copying a matching string.
+
+ When returning, a "goto inf_leave" is used to update the total counters,
+ update the check value, and determine whether any progress has been made
+ during that inflate() call in order to return the proper return code.
+ Progress is defined as a change in either strm->avail_in or strm->avail_out.
+ When there is a window, goto inf_leave will update the window with the last
+ output written. If a goto inf_leave occurs in the middle of decompression
+ and there is no window currently, goto inf_leave will create one and copy
+ output to the window for the next call of inflate().
+
+ In this implementation, the flush parameter of inflate() only affects the
+ return code (per zlib.h). inflate() always writes as much as possible to
+ strm->next_out, given the space available and the provided input--the effect
+ documented in zlib.h of Z_SYNC_FLUSH. Furthermore, inflate() always defers
+ the allocation of and copying into a sliding window until necessary, which
+ provides the effect documented in zlib.h for Z_FINISH when the entire input
+ stream available. So the only thing the flush parameter actually does is:
+ when flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it
+ will return Z_BUF_ERROR if it has not reached the end of the stream.
+ */
+
+int ZEXPORT inflate(strm, flush)
+z_streamp strm;
+int flush;
+{
+ struct inflate_state FAR *state;
+ z_const unsigned char FAR *next; /* next input */
+ unsigned char FAR *put; /* next output */
+ unsigned have, left; /* available input and output */
+ unsigned long hold; /* bit buffer */
+ unsigned bits; /* bits in bit buffer */
+ unsigned in, out; /* save starting available input and output */
+ unsigned copy; /* number of stored or match bytes to copy */
+ unsigned char FAR *from; /* where to copy match bytes from */
+ code this; /* current decoding table entry */
+ code last; /* parent table entry */
+ unsigned len; /* length to copy for repeats, bits to drop */
+ int ret; /* return code */
+#ifdef GUNZIP
+ unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
+#endif
+ static const unsigned short order[19] = /* permutation of code lengths */
+ {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
+
+ if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
+ (strm->next_in == Z_NULL && strm->avail_in != 0))
+ return Z_STREAM_ERROR;
+
+ state = (struct inflate_state FAR *)strm->state;
+ if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
+ LOAD();
+ in = have;
+ out = left;
+ ret = Z_OK;
+ for (;;)
+ switch (state->mode) {
+ case HEAD:
+ if (state->wrap == 0) {
+ state->mode = TYPEDO;
+ break;
+ }
+ NEEDBITS(16);
+#ifdef GUNZIP
+ if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
+ state->check = crc32(0L, Z_NULL, 0);
+ CRC2(state->check, hold);
+ INITBITS();
+ state->mode = FLAGS;
+ break;
+ }
+ state->flags = 0; /* expect zlib header */
+ if (state->head != Z_NULL)
+ state->head->done = -1;
+ if (!(state->wrap & 1) || /* check if zlib header allowed */
+#else
+ if (
+#endif
+ ((BITS(8) << 8) + (hold >> 8)) % 31) {
+#ifdef SMALL
+ strm->msg = "error";
+#else
+ strm->msg = (char *)"incorrect header check";
+#endif
+ state->mode = BAD;
+ break;
+ }
+ if (BITS(4) != Z_DEFLATED) {
+#ifdef SMALL
+ strm->msg = "error";
+#else
+ strm->msg = (char *)"unknown compression method";
+#endif
+ state->mode = BAD;
+ break;
+ }
+ DROPBITS(4);
+ len = BITS(4) + 8;
+ if (len > state->wbits) {
+#ifdef SMALL
+ strm->msg = "error";
+#else
+ strm->msg = (char *)"invalid window size";
+#endif
+ state->mode = BAD;
+ break;
+ }
+ state->dmax = 1U << len;
+ Tracev((stderr, "inflate: zlib header ok\n"));
+ strm->adler = state->check = adler32(0L, Z_NULL, 0);
+ state->mode = hold & 0x200 ? DICTID : TYPE;
+ INITBITS();
+ break;
+#ifdef GUNZIP
+ case FLAGS:
+ NEEDBITS(16);
+ state->flags = (int)(hold);
+ if ((state->flags & 0xff) != Z_DEFLATED) {
+#ifdef SMALL
+ strm->msg = "error";
+#else
+ strm->msg = (char *)"unknown compression method";
+#endif
+ state->mode = BAD;
+ break;
+ }
+ if (state->flags & 0xe000) {
+#ifdef SMALL
+ strm->msg = "error";
+#else
+ strm->msg = (char *)"unknown header flags set";
+#endif
+ state->mode = BAD;
+ break;
+ }
+ if (state->head != Z_NULL)
+ state->head->text = (int)((hold >> 8) & 1);
+ if (state->flags & 0x0200) CRC2(state->check, hold);
+ INITBITS();
+ state->mode = TIME;
+ case TIME:
+ NEEDBITS(32);
+ if (state->head != Z_NULL)
+ state->head->time = hold;
+ if (state->flags & 0x0200) CRC4(state->check, hold);
+ INITBITS();
+ state->mode = OS;
+ case OS:
+ NEEDBITS(16);
+ if (state->head != Z_NULL) {
+ state->head->xflags = (int)(hold & 0xff);
+ state->head->os = (int)(hold >> 8);
+ }
+ if (state->flags & 0x0200) CRC2(state->check, hold);
+ INITBITS();
+ state->mode = EXLEN;
+ case EXLEN:
+ if (state->flags & 0x0400) {
+ NEEDBITS(16);
+ state->length = (unsigned)(hold);
+ if (state->head != Z_NULL)
+ state->head->extra_len = (unsigned)hold;
+ if (state->flags & 0x0200) CRC2(state->check, hold);
+ INITBITS();
+ }
+ else if (state->head != Z_NULL)
+ state->head->extra = Z_NULL;
+ state->mode = EXTRA;
+ case EXTRA:
+ if (state->flags & 0x0400) {
+ copy = state->length;
+ if (copy > have) copy = have;
+ if (copy) {
+ if (state->head != Z_NULL &&
+ state->head->extra != Z_NULL) {
+ len = state->head->extra_len - state->length;
+ zmemcpy(state->head->extra + len, next,
+ len + copy > state->head->extra_max ?
+ state->head->extra_max - len : copy);
+ }
+ if (state->flags & 0x0200)
+ state->check = crc32(state->check, next, copy);
+ have -= copy;
+ next += copy;
+ state->length -= copy;
+ }
+ if (state->length) goto inf_leave;
+ }
+ state->length = 0;
+ state->mode = NAME;
+ case NAME:
+ if (state->flags & 0x0800) {
+ if (have == 0) goto inf_leave;
+ copy = 0;
+ do {
+ len = (unsigned)(next[copy++]);
+ if (state->head != Z_NULL &&
+ state->head->name != Z_NULL &&
+ state->length < state->head->name_max)
+ state->head->name[state->length++] = len;
+ } while (len && copy < have);
+ if (state->flags & 0x0200)
+ state->check = crc32(state->check, next, copy);
+ have -= copy;
+ next += copy;
+ if (len) goto inf_leave;
+ }
+ else if (state->head != Z_NULL)
+ state->head->name = Z_NULL;
+ state->length = 0;
+ state->mode = COMMENT;
+ case COMMENT:
+ if (state->flags & 0x1000) {
+ if (have == 0) goto inf_leave;
+ copy = 0;
+ do {
+ len = (unsigned)(next[copy++]);
+ if (state->head != Z_NULL &&
+ state->head->comment != Z_NULL &&
+ state->length < state->head->comm_max)
+ state->head->comment[state->length++] = len;
+ } while (len && copy < have);
+ if (state->flags & 0x0200)
+ state->check = crc32(state->check, next, copy);
+ have -= copy;
+ next += copy;
+ if (len) goto inf_leave;
+ }
+ else if (state->head != Z_NULL)
+ state->head->comment = Z_NULL;
+ state->mode = HCRC;
+ case HCRC:
+ if (state->flags & 0x0200) {
+ NEEDBITS(16);
+ if (hold != (state->check & 0xffff)) {
+#ifdef SMALL
+ strm->msg = "error";
+#else
+ strm->msg = (char *)"header crc mismatch";
+#endif
+ state->mode = BAD;
+ break;
+ }
+ INITBITS();
+ }
+ if (state->head != Z_NULL) {
+ state->head->hcrc = (int)((state->flags >> 9) & 1);
+ state->head->done = 1;
+ }
+ strm->adler = state->check = crc32(0L, Z_NULL, 0);
+ state->mode = TYPE;
+ break;
+#endif
+ case DICTID:
+ NEEDBITS(32);
+ strm->adler = state->check = REVERSE(hold);
+ INITBITS();
+ state->mode = DICT;
+ case DICT:
+ if (state->havedict == 0) {
+ RESTORE();
+ return Z_NEED_DICT;
+ }
+ strm->adler = state->check = adler32(0L, Z_NULL, 0);
+ state->mode = TYPE;
+ case TYPE:
+ if (flush == Z_BLOCK) goto inf_leave;
+ case TYPEDO:
+ if (state->last) {
+ BYTEBITS();
+ state->mode = CHECK;
+ break;
+ }
+ NEEDBITS(3);
+ state->last = BITS(1);
+ DROPBITS(1);
+ switch (BITS(2)) {
+ case 0: /* stored block */
+ Tracev((stderr, "inflate: stored block%s\n",
+ state->last ? " (last)" : ""));
+ state->mode = STORED;
+ break;
+ case 1: /* fixed block */
+ fixedtables(state);
+ Tracev((stderr, "inflate: fixed codes block%s\n",
+ state->last ? " (last)" : ""));
+ state->mode = LEN; /* decode codes */
+ break;
+ case 2: /* dynamic block */
+ Tracev((stderr, "inflate: dynamic codes block%s\n",
+ state->last ? " (last)" : ""));
+ state->mode = TABLE;
+ break;
+ case 3:
+#ifdef SMALL
+ strm->msg = "error";
+#else
+ strm->msg = (char *)"invalid block type";
+#endif
+ state->mode = BAD;
+ }
+ DROPBITS(2);
+ break;
+ case STORED:
+ BYTEBITS(); /* go to byte boundary */
+ NEEDBITS(32);
+ if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
+#ifdef SMALL
+ strm->msg = "error";
+#else
+ strm->msg = (char *)"invalid stored block lengths";
+#endif
+ state->mode = BAD;
+ break;
+ }
+ state->length = (unsigned)hold & 0xffff;
+ Tracev((stderr, "inflate: stored length %u\n",
+ state->length));
+ INITBITS();
+ state->mode = COPY;
+ case COPY:
+ copy = state->length;
+ if (copy) {
+ if (copy > have) copy = have;
+ if (copy > left) copy = left;
+ if (copy == 0) goto inf_leave;
+ zmemcpy(put, next, copy);
+ have -= copy;
+ next += copy;
+ left -= copy;
+ put += copy;
+ state->length -= copy;
+ break;
+ }
+ Tracev((stderr, "inflate: stored end\n"));
+ state->mode = TYPE;
+ break;
+ case TABLE:
+ NEEDBITS(14);
+ state->nlen = BITS(5) + 257;
+ DROPBITS(5);
+ state->ndist = BITS(5) + 1;
+ DROPBITS(5);
+ state->ncode = BITS(4) + 4;
+ DROPBITS(4);
+#ifndef PKZIP_BUG_WORKAROUND
+ if (state->nlen > 286 || state->ndist > 30) {
+#ifdef SMALL
+ strm->msg = "error";
+#else
+ strm->msg = (char *)"too many length or distance symbols";
+#endif
+ state->mode = BAD;
+ break;
+ }
+#endif
+ Tracev((stderr, "inflate: table sizes ok\n"));
+ state->have = 0;
+ state->mode = LENLENS;
+ case LENLENS:
+ while (state->have < state->ncode) {
+ NEEDBITS(3);
+ state->lens[order[state->have++]] = (unsigned short)BITS(3);
+ DROPBITS(3);
+ }
+ while (state->have < 19)
+ state->lens[order[state->have++]] = 0;
+ state->next = state->codes;
+ state->lencode = (code const FAR *)(state->next);
+ state->lenbits = 7;
+ ret = inflate_table(CODES, state->lens, 19, &(state->next),
+ &(state->lenbits), state->work);
+ if (ret) {
+#ifdef SMALL
+ strm->msg = "error";
+#else
+ strm->msg = (char *)"invalid code lengths set";
+#endif
+ state->mode = BAD;
+ break;
+ }
+ Tracev((stderr, "inflate: code lengths ok\n"));
+ state->have = 0;
+ state->mode = CODELENS;
+ case CODELENS:
+ while (state->have < state->nlen + state->ndist) {
+ for (;;) {
+ this = state->lencode[BITS(state->lenbits)];
+ if ((unsigned)(this.bits) <= bits) break;
+ PULLBYTE();
+ }
+ if (this.val < 16) {
+ NEEDBITS(this.bits);
+ DROPBITS(this.bits);
+ state->lens[state->have++] = this.val;
+ }
+ else {
+ if (this.val == 16) {
+ NEEDBITS(this.bits + 2);
+ DROPBITS(this.bits);
+ if (state->have == 0) {
+#ifdef SMALL
+ strm->msg = "error";
+#else
+ strm->msg = (char *)"invalid bit length repeat";
+#endif
+ state->mode = BAD;
+ break;
+ }
+ len = state->lens[state->have - 1];
+ copy = 3 + BITS(2);
+ DROPBITS(2);
+ }
+ else if (this.val == 17) {
+ NEEDBITS(this.bits + 3);
+ DROPBITS(this.bits);
+ len = 0;
+ copy = 3 + BITS(3);
+ DROPBITS(3);
+ }
+ else {
+ NEEDBITS(this.bits + 7);
+ DROPBITS(this.bits);
+ len = 0;
+ copy = 11 + BITS(7);
+ DROPBITS(7);
+ }
+ if (state->have + copy > state->nlen + state->ndist) {
+#ifdef SMALL
+ strm->msg = "error";
+#else
+ strm->msg = (char *)"invalid bit length repeat";
+#endif
+ state->mode = BAD;
+ break;
+ }
+ while (copy--)
+ state->lens[state->have++] = (unsigned short)len;
+ }
+ }
+
+ /* handle error breaks in while */
+ if (state->mode == BAD) break;
+
+ /* build code tables */
+ state->next = state->codes;
+ state->lencode = (code const FAR *)(state->next);
+ state->lenbits = 9;
+ ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
+ &(state->lenbits), state->work);
+ if (ret) {
+#ifdef SMALL
+ strm->msg = "error";
+#else
+ strm->msg = (char *)"invalid literal/lengths set";
+#endif
+ state->mode = BAD;
+ break;
+ }
+ state->distcode = (code const FAR *)(state->next);
+ state->distbits = 6;
+ ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
+ &(state->next), &(state->distbits), state->work);
+ if (ret) {
+#ifdef SMALL
+ strm->msg = "error";
+#else
+ strm->msg = (char *)"invalid distances set";
+#endif
+ state->mode = BAD;
+ break;
+ }
+ Tracev((stderr, "inflate: codes ok\n"));
+ state->mode = LEN;
+ case LEN:
+#ifndef SLOW
+ if (have >= 6 && left >= 258) {
+ RESTORE();
+ inflate_fast(strm, out);
+ LOAD();
+ break;
+ }
+#endif
+ for (;;) {
+ this = state->lencode[BITS(state->lenbits)];
+ if ((unsigned)(this.bits) <= bits) break;
+ PULLBYTE();
+ }
+ if (this.op && (this.op & 0xf0) == 0) {
+ last = this;
+ for (;;) {
+ this = state->lencode[last.val +
+ (BITS(last.bits + last.op) >> last.bits)];
+ if ((unsigned)(last.bits + this.bits) <= bits) break;
+ PULLBYTE();
+ }
+ DROPBITS(last.bits);
+ }
+ DROPBITS(this.bits);
+ state->length = (unsigned)this.val;
+ if ((int)(this.op) == 0) {
+ Tracevv((stderr, this.val >= 0x20 && this.val < 0x7f ?
+ "inflate: literal '%c'\n" :
+ "inflate: literal 0x%02x\n", this.val));
+ state->mode = LIT;
+ break;
+ }
+ if (this.op & 32) {
+ Tracevv((stderr, "inflate: end of block\n"));
+ state->mode = TYPE;
+ break;
+ }
+ if (this.op & 64) {
+#ifdef SMALL
+ strm->msg = "error";
+#else
+ strm->msg = (char *)"invalid literal/length code";
+#endif
+ state->mode = BAD;
+ break;
+ }
+ state->extra = (unsigned)(this.op) & 15;
+ state->mode = LENEXT;
+ case LENEXT:
+ if (state->extra) {
+ NEEDBITS(state->extra);
+ state->length += BITS(state->extra);
+ DROPBITS(state->extra);
+ }
+ Tracevv((stderr, "inflate: length %u\n", state->length));
+ state->mode = DIST;
+ case DIST:
+ for (;;) {
+ this = state->distcode[BITS(state->distbits)];
+ if ((unsigned)(this.bits) <= bits) break;
+ PULLBYTE();
+ }
+ if ((this.op & 0xf0) == 0) {
+ last = this;
+ for (;;) {
+ this = state->distcode[last.val +
+ (BITS(last.bits + last.op) >> last.bits)];
+ if ((unsigned)(last.bits + this.bits) <= bits) break;
+ PULLBYTE();
+ }
+ DROPBITS(last.bits);
+ }
+ DROPBITS(this.bits);
+ if (this.op & 64) {
+#ifdef SMALL
+ strm->msg = "error";
+#else
+ strm->msg = (char *)"invalid distance code";
+#endif
+ state->mode = BAD;
+ break;
+ }
+ state->offset = (unsigned)this.val;
+ state->extra = (unsigned)(this.op) & 15;
+ state->mode = DISTEXT;
+ case DISTEXT:
+ if (state->extra) {
+ NEEDBITS(state->extra);
+ state->offset += BITS(state->extra);
+ DROPBITS(state->extra);
+ }
+#ifdef INFLATE_STRICT
+ if (state->offset > state->dmax) {
+ strm->msg = (char *)"invalid distance too far back";
+ state->mode = BAD;
+ break;
+ }
+#endif
+ if (state->offset > state->whave + out - left) {
+#ifdef SMALL
+ strm->msg = "error";
+#else
+ strm->msg = (char *)"invalid distance too far back";
+#endif
+ state->mode = BAD;
+ break;
+ }
+ Tracevv((stderr, "inflate: distance %u\n", state->offset));
+ state->mode = MATCH;
+ case MATCH:
+ if (left == 0) goto inf_leave;
+ copy = out - left;
+ if (state->offset > copy) { /* copy from window */
+ copy = state->offset - copy;
+ if (copy > state->write) {
+ copy -= state->write;
+ from = state->window + (state->wsize - copy);
+ }
+ else
+ from = state->window + (state->write - copy);
+ if (copy > state->length) copy = state->length;
+ }
+ else { /* copy from output */
+ from = put - state->offset;
+ copy = state->length;
+ }
+ if (copy > left) copy = left;
+ left -= copy;
+ state->length -= copy;
+ do {
+ *put++ = *from++;
+ } while (--copy);
+ if (state->length == 0) state->mode = LEN;
+ break;
+ case LIT:
+ if (left == 0) goto inf_leave;
+ *put++ = (unsigned char)(state->length);
+ left--;
+ state->mode = LEN;
+ break;
+ case CHECK:
+ if (state->wrap) {
+ NEEDBITS(32);
+ out -= left;
+ strm->total_out += out;
+ state->total += out;
+ if (out)
+ strm->adler = state->check =
+ UPDATE(state->check, put - out, out);
+ out = left;
+ if ((
+#ifdef GUNZIP
+ state->flags ? hold :
+#endif
+ REVERSE(hold)) != state->check) {
+#ifdef SMALL
+ strm->msg = "error";
+#else
+ strm->msg = (char *)"incorrect data check";
+#endif
+ state->mode = BAD;
+ break;
+ }
+ INITBITS();
+ Tracev((stderr, "inflate: check matches trailer\n"));
+ }
+#ifdef GUNZIP
+ state->mode = LENGTH;
+ case LENGTH:
+ if (state->wrap && state->flags) {
+ NEEDBITS(32);
+ if (hold != (state->total & 0xffffffffUL)) {
+#ifdef SMALL
+ strm->msg = "error";
+#else
+ strm->msg = (char *)"incorrect length check";
+#endif
+ state->mode = BAD;
+ break;
+ }
+ INITBITS();
+ Tracev((stderr, "inflate: length matches trailer\n"));
+ }
+#endif
+ state->mode = DONE;
+ case DONE:
+ ret = Z_STREAM_END;
+ goto inf_leave;
+ case BAD:
+ ret = Z_DATA_ERROR;
+ goto inf_leave;
+ case MEM:
+ return Z_MEM_ERROR;
+ case SYNC:
+ default:
+ return Z_STREAM_ERROR;
+ }
+
+ /*
+ Return from inflate(), updating the total counts and the check value.
+ If there was no progress during the inflate() call, return a buffer
+ error. Call updatewindow() to create and/or update the window state.
+ Note: a memory error from inflate() is non-recoverable.
+ */
+ inf_leave:
+ RESTORE();
+ if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
+ if (updatewindow(strm, out)) {
+ state->mode = MEM;
+ return Z_MEM_ERROR;
+ }
+ in -= strm->avail_in;
+ out -= strm->avail_out;
+ strm->total_in += in;
+ strm->total_out += out;
+ state->total += out;
+ if (state->wrap && out)
+ strm->adler = state->check =
+ UPDATE(state->check, strm->next_out - out, out);
+ strm->data_type = state->bits + (state->last ? 64 : 0) +
+ (state->mode == TYPE ? 128 : 0);
+ if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
+ ret = Z_BUF_ERROR;
+ return ret;
+}
+
+int ZEXPORT inflateEnd(strm)
+z_streamp strm;
+{
+ struct inflate_state FAR *state;
+ if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
+ return Z_STREAM_ERROR;
+ state = (struct inflate_state FAR *)strm->state;
+ if (state->window != Z_NULL) ZFREE(strm, state->window);
+ ZFREE(strm, strm->state);
+ strm->state = Z_NULL;
+ Tracev((stderr, "inflate: end\n"));
+ return Z_OK;
+}
+
+int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength)
+z_streamp strm;
+const Bytef *dictionary;
+uInt dictLength;
+{
+ struct inflate_state FAR *state;
+ unsigned long id;
+
+ /* check state */
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ state = (struct inflate_state FAR *)strm->state;
+ if (state->wrap != 0 && state->mode != DICT)
+ return Z_STREAM_ERROR;
+
+ /* check for correct dictionary id */
+ if (state->mode == DICT) {
+ id = adler32(0L, Z_NULL, 0);
+ id = adler32(id, dictionary, dictLength);
+ if (id != state->check)
+ return Z_DATA_ERROR;
+ }
+
+ /* copy dictionary to window */
+ if (updatewindow(strm, strm->avail_out)) {
+ state->mode = MEM;
+ return Z_MEM_ERROR;
+ }
+ if (dictLength > state->wsize) {
+ zmemcpy(state->window, dictionary + dictLength - state->wsize,
+ state->wsize);
+ state->whave = state->wsize;
+ }
+ else {
+ zmemcpy(state->window + state->wsize - dictLength, dictionary,
+ dictLength);
+ state->whave = dictLength;
+ }
+ state->havedict = 1;
+ Tracev((stderr, "inflate: dictionary set\n"));
+ return Z_OK;
+}
+
+int ZEXPORT inflateGetHeader(strm, head)
+z_streamp strm;
+gz_headerp head;
+{
+ struct inflate_state FAR *state;
+
+ /* check state */
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ state = (struct inflate_state FAR *)strm->state;
+ if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
+
+ /* save header structure */
+ state->head = head;
+ head->done = 0;
+ return Z_OK;
+}
+
+/*
+ Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff. Return when found
+ or when out of input. When called, *have is the number of pattern bytes
+ found in order so far, in 0..3. On return *have is updated to the new
+ state. If on return *have equals four, then the pattern was found and the
+ return value is how many bytes were read including the last byte of the
+ pattern. If *have is less than four, then the pattern has not been found
+ yet and the return value is len. In the latter case, syncsearch() can be
+ called again with more data and the *have state. *have is initialized to
+ zero for the first call.
+ */
+local unsigned syncsearch(have, buf, len)
+unsigned FAR *have;
+z_const unsigned char FAR *buf;
+unsigned len;
+{
+ unsigned got;
+ unsigned next;
+
+ got = *have;
+ next = 0;
+ while (next < len && got < 4) {
+ if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
+ got++;
+ else if (buf[next])
+ got = 0;
+ else
+ got = 4 - got;
+ next++;
+ }
+ *have = got;
+ return next;
+}
+
+int ZEXPORT inflateSync(strm)
+z_streamp strm;
+{
+ unsigned len; /* number of bytes to look at or looked at */
+ unsigned long in, out; /* temporary to save total_in and total_out */
+ unsigned char buf[4]; /* to restore bit buffer to byte string */
+ struct inflate_state FAR *state;
+
+ /* check parameters */
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ state = (struct inflate_state FAR *)strm->state;
+ if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
+
+ /* if first time, start search in bit buffer */
+ if (state->mode != SYNC) {
+ state->mode = SYNC;
+ state->hold <<= state->bits & 7;
+ state->bits -= state->bits & 7;
+ len = 0;
+ while (state->bits >= 8) {
+ buf[len++] = (unsigned char)(state->hold);
+ state->hold >>= 8;
+ state->bits -= 8;
+ }
+ state->have = 0;
+ syncsearch(&(state->have), buf, len);
+ }
+
+ /* search available input */
+ len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
+ strm->avail_in -= len;
+ strm->next_in += len;
+ strm->total_in += len;
+
+ /* return no joy or set up to restart inflate() on a new block */
+ if (state->have != 4) return Z_DATA_ERROR;
+ in = strm->total_in; out = strm->total_out;
+ inflateReset(strm);
+ strm->total_in = in; strm->total_out = out;
+ state->mode = TYPE;
+ return Z_OK;
+}
+
+/*
+ Returns true if inflate is currently at the end of a block generated by
+ Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP
+ implementation to provide an additional safety check. PPP uses
+ Z_SYNC_FLUSH but removes the length bytes of the resulting empty stored
+ block. When decompressing, PPP checks that at the end of input packet,
+ inflate is waiting for these length bytes.
+ */
+int ZEXPORT inflateSyncPoint(strm)
+z_streamp strm;
+{
+ struct inflate_state FAR *state;
+
+ if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
+ state = (struct inflate_state FAR *)strm->state;
+ return state->mode == STORED && state->bits == 0;
+}
+
+int ZEXPORT inflateCopy(dest, source)
+z_streamp dest;
+z_streamp source;
+{
+ struct inflate_state FAR *state;
+ struct inflate_state FAR *copy;
+ unsigned char FAR *window;
+ unsigned wsize;
+
+ /* check input */
+ if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
+ source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
+ return Z_STREAM_ERROR;
+ state = (struct inflate_state FAR *)source->state;
+
+ /* allocate space */
+ copy = (struct inflate_state FAR *)
+ ZALLOC(source, 1, sizeof(struct inflate_state));
+ if (copy == Z_NULL) return Z_MEM_ERROR;
+ window = Z_NULL;
+ if (state->window != Z_NULL) {
+ window = (unsigned char FAR *)
+ ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
+ if (window == Z_NULL) {
+ ZFREE(source, copy);
+ return Z_MEM_ERROR;
+ }
+ }
+
+ /* copy state */
+ zmemcpy(dest, source, sizeof(z_stream));
+ zmemcpy(copy, state, sizeof(struct inflate_state));
+ if (state->lencode >= state->codes &&
+ state->lencode <= state->codes + ENOUGH - 1) {
+ copy->lencode = copy->codes + (state->lencode - state->codes);
+ copy->distcode = copy->codes + (state->distcode - state->codes);
+ }
+ copy->next = copy->codes + (state->next - state->codes);
+ if (window != Z_NULL) {
+ wsize = 1U << state->wbits;
+ zmemcpy(window, state->window, wsize);
+ }
+ copy->window = window;
+ dest->state = (struct internal_state FAR *)copy;
+ return Z_OK;
+}
diff --git a/lib/libz/inflate.h b/lib/libz/inflate.h
new file mode 100644
index 0000000..07bd3e7
--- /dev/null
+++ b/lib/libz/inflate.h
@@ -0,0 +1,115 @@
+/* inflate.h -- internal inflate state definition
+ * Copyright (C) 1995-2004 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+ part of the implementation of the compression library and is
+ subject to change. Applications should only use zlib.h.
+ */
+
+/* define NO_GZIP when compiling if you want to disable gzip header and
+ trailer decoding by inflate(). NO_GZIP would be used to avoid linking in
+ the crc code when it is not needed. For shared libraries, gzip decoding
+ should be left enabled. */
+#ifndef NO_GZIP
+# define GUNZIP
+#endif
+
+/* Possible inflate modes between inflate() calls */
+typedef enum {
+ HEAD, /* i: waiting for magic header */
+ FLAGS, /* i: waiting for method and flags (gzip) */
+ TIME, /* i: waiting for modification time (gzip) */
+ OS, /* i: waiting for extra flags and operating system (gzip) */
+ EXLEN, /* i: waiting for extra length (gzip) */
+ EXTRA, /* i: waiting for extra bytes (gzip) */
+ NAME, /* i: waiting for end of file name (gzip) */
+ COMMENT, /* i: waiting for end of comment (gzip) */
+ HCRC, /* i: waiting for header crc (gzip) */
+ DICTID, /* i: waiting for dictionary check value */
+ DICT, /* waiting for inflateSetDictionary() call */
+ TYPE, /* i: waiting for type bits, including last-flag bit */
+ TYPEDO, /* i: same, but skip check to exit inflate on new block */
+ STORED, /* i: waiting for stored size (length and complement) */
+ COPY, /* i/o: waiting for input or output to copy stored block */
+ TABLE, /* i: waiting for dynamic block table lengths */
+ LENLENS, /* i: waiting for code length code lengths */
+ CODELENS, /* i: waiting for length/lit and distance code lengths */
+ LEN, /* i: waiting for length/lit code */
+ LENEXT, /* i: waiting for length extra bits */
+ DIST, /* i: waiting for distance code */
+ DISTEXT, /* i: waiting for distance extra bits */
+ MATCH, /* o: waiting for output space to copy string */
+ LIT, /* o: waiting for output space to write literal */
+ CHECK, /* i: waiting for 32-bit check value */
+ LENGTH, /* i: waiting for 32-bit length (gzip) */
+ DONE, /* finished check, done -- remain here until reset */
+ BAD, /* got a data error -- remain here until reset */
+ MEM, /* got an inflate() memory error -- remain here until reset */
+ SYNC /* looking for synchronization bytes to restart inflate() */
+} inflate_mode;
+
+/*
+ State transitions between above modes -
+
+ (most modes can go to the BAD or MEM mode -- not shown for clarity)
+
+ Process header:
+ HEAD -> (gzip) or (zlib)
+ (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME
+ NAME -> COMMENT -> HCRC -> TYPE
+ (zlib) -> DICTID or TYPE
+ DICTID -> DICT -> TYPE
+ Read deflate blocks:
+ TYPE -> STORED or TABLE or LEN or CHECK
+ STORED -> COPY -> TYPE
+ TABLE -> LENLENS -> CODELENS -> LEN
+ Read deflate codes:
+ LEN -> LENEXT or LIT or TYPE
+ LENEXT -> DIST -> DISTEXT -> MATCH -> LEN
+ LIT -> LEN
+ Process trailer:
+ CHECK -> LENGTH -> DONE
+ */
+
+/* state maintained between inflate() calls. Approximately 7K bytes. */
+struct inflate_state {
+ inflate_mode mode; /* current inflate mode */
+ int last; /* true if processing last block */
+ int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
+ int havedict; /* true if dictionary provided */
+ int flags; /* gzip header method and flags (0 if zlib) */
+ unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
+ unsigned long check; /* protected copy of check value */
+ unsigned long total; /* protected copy of output count */
+ gz_headerp head; /* where to save gzip header information */
+ /* sliding window */
+ unsigned wbits; /* log base 2 of requested window size */
+ unsigned wsize; /* window size or zero if not using window */
+ unsigned whave; /* valid bytes in the window */
+ unsigned write; /* window write index */
+ unsigned char FAR *window; /* allocated sliding window, if needed */
+ /* bit accumulator */
+ unsigned long hold; /* input bit accumulator */
+ unsigned bits; /* number of bits in "in" */
+ /* for string and stored block copying */
+ unsigned length; /* literal or length of data to copy */
+ unsigned offset; /* distance back to copy string from */
+ /* for table and code decoding */
+ unsigned extra; /* extra bits needed */
+ /* fixed and dynamic code tables */
+ code const FAR *lencode; /* starting table for length/literal codes */
+ code const FAR *distcode; /* starting table for distance codes */
+ unsigned lenbits; /* index bits for lencode */
+ unsigned distbits; /* index bits for distcode */
+ /* dynamic table building */
+ unsigned ncode; /* number of code length code lengths */
+ unsigned nlen; /* number of length code lengths */
+ unsigned ndist; /* number of distance code lengths */
+ unsigned have; /* number of code lengths in lens[] */
+ code FAR *next; /* next available space in codes[] */
+ unsigned short lens[320]; /* temporary storage for code lengths */
+ unsigned short work[288]; /* work area for code table building */
+ code codes[ENOUGH]; /* space for code tables */
+};
diff --git a/lib/libz/inftrees.c b/lib/libz/inftrees.c
new file mode 100644
index 0000000..0b879cd
--- /dev/null
+++ b/lib/libz/inftrees.c
@@ -0,0 +1,328 @@
+/* $OpenBSD: inftrees.c,v 1.9 2009/10/27 23:59:31 deraadt Exp $ */
+/* inftrees.c -- generate Huffman trees for efficient decoding
+ * Copyright (C) 1995-2005 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+#include "zutil.h"
+#include "inftrees.h"
+
+#define MAXBITS 15
+
+/*
+ If you use the zlib library in a product, an acknowledgment is welcome
+ in the documentation of your product. If for some reason you cannot
+ include such an acknowledgment, I would appreciate that you keep this
+ copyright string in the executable of your product.
+ */
+
+/*
+ Build a set of tables to decode the provided canonical Huffman code.
+ The code lengths are lens[0..codes-1]. The result starts at *table,
+ whose indices are 0..2^bits-1. work is a writable array of at least
+ lens shorts, which is used as a work area. type is the type of code
+ to be generated, CODES, LENS, or DISTS. On return, zero is success,
+ -1 is an invalid code, and +1 means that ENOUGH isn't enough. table
+ on return points to the next available entry's address. bits is the
+ requested root table index bits, and on return it is the actual root
+ table index bits. It will differ if the request is greater than the
+ longest code or if it is less than the shortest code.
+ */
+int inflate_table(type, lens, codes, table, bits, work)
+codetype type;
+unsigned short FAR *lens;
+unsigned codes;
+code FAR * FAR *table;
+unsigned FAR *bits;
+unsigned short FAR *work;
+{
+ unsigned len; /* a code's length in bits */
+ unsigned sym; /* index of code symbols */
+ unsigned min, max; /* minimum and maximum code lengths */
+ unsigned root; /* number of index bits for root table */
+ unsigned curr; /* number of index bits for current table */
+ unsigned drop; /* code bits to drop for sub-table */
+ int left; /* number of prefix codes available */
+ unsigned used; /* code entries in table used */
+ unsigned huff; /* Huffman code */
+ unsigned incr; /* for incrementing code, index */
+ unsigned fill; /* index for replicating entries */
+ unsigned low; /* low bits for current root entry */
+ unsigned mask; /* mask for low root bits */
+ code this; /* table entry for duplication */
+ code FAR *next; /* next available space in table */
+ const unsigned short FAR *base; /* base value table to use */
+ const unsigned short FAR *extra; /* extra bits table to use */
+ int end; /* use base and extra for symbol > end */
+ unsigned short count[MAXBITS+1]; /* number of codes of each length */
+ unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
+ static const unsigned short lbase[31] = { /* Length codes 257..285 base */
+ 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
+ 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
+ static const unsigned short lext[31] = { /* Length codes 257..285 extra */
+ 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
+ 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
+ static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
+ 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
+ 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
+ 8193, 12289, 16385, 24577, 0, 0};
+ static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
+ 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
+ 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
+ 28, 28, 29, 29, 64, 64};
+
+ /*
+ Process a set of code lengths to create a canonical Huffman code. The
+ code lengths are lens[0..codes-1]. Each length corresponds to the
+ symbols 0..codes-1. The Huffman code is generated by first sorting the
+ symbols by length from short to long, and retaining the symbol order
+ for codes with equal lengths. Then the code starts with all zero bits
+ for the first code of the shortest length, and the codes are integer
+ increments for the same length, and zeros are appended as the length
+ increases. For the deflate format, these bits are stored backwards
+ from their more natural integer increment ordering, and so when the
+ decoding tables are built in the large loop below, the integer codes
+ are incremented backwards.
+
+ This routine assumes, but does not check, that all of the entries in
+ lens[] are in the range 0..MAXBITS. The caller must assure this.
+ 1..MAXBITS is interpreted as that code length. zero means that that
+ symbol does not occur in this code.
+
+ The codes are sorted by computing a count of codes for each length,
+ creating from that a table of starting indices for each length in the
+ sorted table, and then entering the symbols in order in the sorted
+ table. The sorted table is work[], with that space being provided by
+ the caller.
+
+ The length counts are used for other purposes as well, i.e. finding
+ the minimum and maximum length codes, determining if there are any
+ codes at all, checking for a valid set of lengths, and looking ahead
+ at length counts to determine sub-table sizes when building the
+ decoding tables.
+ */
+
+ /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */
+ for (len = 0; len <= MAXBITS; len++)
+ count[len] = 0;
+ for (sym = 0; sym < codes; sym++)
+ count[lens[sym]]++;
+
+ /* bound code lengths, force root to be within code lengths */
+ root = *bits;
+ for (max = MAXBITS; max >= 1; max--)
+ if (count[max] != 0) break;
+ if (root > max) root = max;
+ if (max == 0) { /* no symbols to code at all */
+ this.op = (unsigned char)64; /* invalid code marker */
+ this.bits = (unsigned char)1;
+ this.val = (unsigned short)0;
+ *(*table)++ = this; /* make a table to force an error */
+ *(*table)++ = this;
+ *bits = 1;
+ return 0; /* no symbols, but wait for decoding to report error */
+ }
+ for (min = 1; min <= MAXBITS; min++)
+ if (count[min] != 0) break;
+ if (root < min) root = min;
+
+ /* check for an over-subscribed or incomplete set of lengths */
+ left = 1;
+ for (len = 1; len <= MAXBITS; len++) {
+ left <<= 1;
+ left -= count[len];
+ if (left < 0) return -1; /* over-subscribed */
+ }
+ if (left > 0 && (type == CODES || max != 1))
+ return -1; /* incomplete set */
+
+ /* generate offsets into symbol table for each length for sorting */
+ offs[1] = 0;
+ for (len = 1; len < MAXBITS; len++)
+ offs[len + 1] = offs[len] + count[len];
+
+ /* sort symbols by length, by symbol order within each length */
+ for (sym = 0; sym < codes; sym++)
+ if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
+
+ /*
+ Create and fill in decoding tables. In this loop, the table being
+ filled is at next and has curr index bits. The code being used is huff
+ with length len. That code is converted to an index by dropping drop
+ bits off of the bottom. For codes where len is less than drop + curr,
+ those top drop + curr - len bits are incremented through all values to
+ fill the table with replicated entries.
+
+ root is the number of index bits for the root table. When len exceeds
+ root, sub-tables are created pointed to by the root entry with an index
+ of the low root bits of huff. This is saved in low to check for when a
+ new sub-table should be started. drop is zero when the root table is
+ being filled, and drop is root when sub-tables are being filled.
+
+ When a new sub-table is needed, it is necessary to look ahead in the
+ code lengths to determine what size sub-table is needed. The length
+ counts are used for this, and so count[] is decremented as codes are
+ entered in the tables.
+
+ used keeps track of how many table entries have been allocated from the
+ provided *table space. It is checked when a LENS table is being made
+ against the space in *table, ENOUGH, minus the maximum space needed by
+ the worst case distance code, MAXD. This should never happen, but the
+ sufficiency of ENOUGH has not been proven exhaustively, hence the check.
+ This assumes that when type == LENS, bits == 9.
+
+ sym increments through all symbols, and the loop terminates when
+ all codes of length max, i.e. all codes, have been processed. This
+ routine permits incomplete codes, so another loop after this one fills
+ in the rest of the decoding tables with invalid code markers.
+ */
+
+ /* set up for code type */
+ switch (type) {
+ case CODES:
+ base = extra = work; /* dummy value--not used */
+ end = 19;
+ break;
+ case LENS:
+ base = lbase;
+ base -= 257;
+ extra = lext;
+ extra -= 257;
+ end = 256;
+ break;
+ default: /* DISTS */
+ base = dbase;
+ extra = dext;
+ end = -1;
+ }
+
+ /* initialize state for loop */
+ huff = 0; /* starting code */
+ sym = 0; /* starting code symbol */
+ len = min; /* starting code length */
+ next = *table; /* current table to fill in */
+ curr = root; /* current table index bits */
+ drop = 0; /* current bits to drop from code for index */
+ low = (unsigned)(-1); /* trigger new sub-table when len > root */
+ used = 1U << root; /* use root table entries */
+ mask = used - 1; /* mask for comparing low */
+
+ /* check available table space */
+ if (type == LENS && used >= ENOUGH - MAXD)
+ return 1;
+
+ /* process all codes and make table entries */
+ for (;;) {
+ /* create table entry */
+ this.bits = (unsigned char)(len - drop);
+ if ((int)(work[sym]) < end) {
+ this.op = (unsigned char)0;
+ this.val = work[sym];
+ }
+ else if ((int)(work[sym]) > end) {
+ this.op = (unsigned char)(extra[work[sym]]);
+ this.val = base[work[sym]];
+ }
+ else {
+ this.op = (unsigned char)(32 + 64); /* end of block */
+ this.val = 0;
+ }
+
+ /* replicate for those indices with low len bits equal to huff */
+ incr = 1U << (len - drop);
+ fill = 1U << curr;
+ min = fill; /* save offset to next table */
+ do {
+ fill -= incr;
+ next[(huff >> drop) + fill] = this;
+ } while (fill != 0);
+
+ /* backwards increment the len-bit code huff */
+ incr = 1U << (len - 1);
+ while (huff & incr)
+ incr >>= 1;
+ if (incr != 0) {
+ huff &= incr - 1;
+ huff += incr;
+ }
+ else
+ huff = 0;
+
+ /* go to next symbol, update count, len */
+ sym++;
+ if (--(count[len]) == 0) {
+ if (len == max) break;
+ len = lens[work[sym]];
+ }
+
+ /* create new sub-table if needed */
+ if (len > root && (huff & mask) != low) {
+ /* if first time, transition to sub-tables */
+ if (drop == 0)
+ drop = root;
+
+ /* increment past last table */
+ next += min; /* here min is 1 << curr */
+
+ /* determine length of next table */
+ curr = len - drop;
+ left = (int)(1 << curr);
+ while (curr + drop < max) {
+ left -= count[curr + drop];
+ if (left <= 0) break;
+ curr++;
+ left <<= 1;
+ }
+
+ /* check for enough space */
+ used += 1U << curr;
+ if (type == LENS && used >= ENOUGH - MAXD)
+ return 1;
+
+ /* point entry in root table to sub-table */
+ low = huff & mask;
+ (*table)[low].op = (unsigned char)curr;
+ (*table)[low].bits = (unsigned char)root;
+ (*table)[low].val = (unsigned short)(next - *table);
+ }
+ }
+
+ /*
+ Fill in rest of table for incomplete codes. This loop is similar to the
+ loop above in incrementing huff for table indices. It is assumed that
+ len is equal to curr + drop, so there is no loop needed to increment
+ through high index bits. When the current sub-table is filled, the loop
+ drops back to the root table to fill in any remaining entries there.
+ */
+ this.op = (unsigned char)64; /* invalid code marker */
+ this.bits = (unsigned char)(len - drop);
+ this.val = (unsigned short)0;
+ while (huff != 0) {
+ /* when done with sub-table, drop back to root table */
+ if (drop != 0 && (huff & mask) != low) {
+ drop = 0;
+ len = root;
+ next = *table;
+ this.bits = (unsigned char)len;
+ }
+
+ /* put invalid code marker in table */
+ next[huff >> drop] = this;
+
+ /* backwards increment the len-bit code huff */
+ incr = 1U << (len - 1);
+ while (huff & incr)
+ incr >>= 1;
+ if (incr != 0) {
+ huff &= incr - 1;
+ huff += incr;
+ }
+ else
+ huff = 0;
+ }
+
+ /* set return parameters */
+ *table += used;
+ *bits = root;
+ return 0;
+}
diff --git a/lib/libz/inftrees.h b/lib/libz/inftrees.h
new file mode 100644
index 0000000..e032c6b
--- /dev/null
+++ b/lib/libz/inftrees.h
@@ -0,0 +1,56 @@
+/* $OpenBSD: inftrees.h,v 1.5 2005/07/20 15:56:41 millert Exp $ */
+/* inftrees.h -- header to use inftrees.c
+ * Copyright (C) 1995-2005 Mark Adler
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+ part of the implementation of the compression library and is
+ subject to change. Applications should only use zlib.h.
+ */
+
+/* Structure for decoding tables. Each entry provides either the
+ information needed to do the operation requested by the code that
+ indexed that table entry, or it provides a pointer to another
+ table that indexes more bits of the code. op indicates whether
+ the entry is a pointer to another table, a literal, a length or
+ distance, an end-of-block, or an invalid code. For a table
+ pointer, the low four bits of op is the number of index bits of
+ that table. For a length or distance, the low four bits of op
+ is the number of extra bits to get after the code. bits is
+ the number of bits in this code or part of the code to drop off
+ of the bit buffer. val is the actual byte to output in the case
+ of a literal, the base length or distance, or the offset from
+ the current table to the next table. Each entry is four bytes. */
+typedef struct {
+ unsigned char op; /* operation, extra bits, table bits */
+ unsigned char bits; /* bits in this part of the code */
+ unsigned short val; /* offset in table or code value */
+} code;
+
+/* op values as set by inflate_table():
+ 00000000 - literal
+ 0000tttt - table link, tttt != 0 is the number of table index bits
+ 0001eeee - length or distance, eeee is the number of extra bits
+ 01100000 - end of block
+ 01000000 - invalid code
+ */
+
+/* Maximum size of dynamic tree. The maximum found in a long but non-
+ exhaustive search was 1444 code structures (852 for length/literals
+ and 592 for distances, the latter actually the result of an
+ exhaustive search). The true maximum is not known, but the value
+ below is more than safe. */
+#define ENOUGH 2048
+#define MAXD 592
+
+/* Type of code to build for inftable() */
+typedef enum {
+ CODES,
+ LENS,
+ DISTS
+} codetype;
+
+extern int inflate_table OF((codetype type, unsigned short FAR *lens,
+ unsigned codes, code FAR * FAR *table,
+ unsigned FAR *bits, unsigned short FAR *work));
diff --git a/lib/libz/shlib_version b/lib/libz/shlib_version
new file mode 100644
index 0000000..3066b97
--- /dev/null
+++ b/lib/libz/shlib_version
@@ -0,0 +1,2 @@
+major=5
+minor=0
diff --git a/lib/libz/trees.c b/lib/libz/trees.c
new file mode 100644
index 0000000..c163626
--- /dev/null
+++ b/lib/libz/trees.c
@@ -0,0 +1,1219 @@
+/* $OpenBSD: trees.c,v 1.8 2005/07/20 15:56:41 millert Exp $ */
+/* trees.c -- output deflated data using Huffman coding
+ * Copyright (C) 1995-2005 Jean-loup Gailly
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/*
+ * ALGORITHM
+ *
+ * The "deflation" process uses several Huffman trees. The more
+ * common source values are represented by shorter bit sequences.
+ *
+ * Each code tree is stored in a compressed form which is itself
+ * a Huffman encoding of the lengths of all the code strings (in
+ * ascending order by source values). The actual code strings are
+ * reconstructed from the lengths in the inflate process, as described
+ * in the deflate specification.
+ *
+ * REFERENCES
+ *
+ * Deutsch, L.P.,"'Deflate' Compressed Data Format Specification".
+ * Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc
+ *
+ * Storer, James A.
+ * Data Compression: Methods and Theory, pp. 49-50.
+ * Computer Science Press, 1988. ISBN 0-7167-8156-5.
+ *
+ * Sedgewick, R.
+ * Algorithms, p290.
+ * Addison-Wesley, 1983. ISBN 0-201-06672-6.
+ */
+
+
+/* #define GEN_TREES_H */
+
+#include "deflate.h"
+
+#ifdef DEBUG
+# include <ctype.h>
+#endif
+
+/* ===========================================================================
+ * Constants
+ */
+
+#define MAX_BL_BITS 7
+/* Bit length codes must not exceed MAX_BL_BITS bits */
+
+#define END_BLOCK 256
+/* end of block literal code */
+
+#define REP_3_6 16
+/* repeat previous bit length 3-6 times (2 bits of repeat count) */
+
+#define REPZ_3_10 17
+/* repeat a zero length 3-10 times (3 bits of repeat count) */
+
+#define REPZ_11_138 18
+/* repeat a zero length 11-138 times (7 bits of repeat count) */
+
+local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
+ = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0};
+
+local const int extra_dbits[D_CODES] /* extra bits for each distance code */
+ = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13};
+
+local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
+ = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
+
+local const uch bl_order[BL_CODES]
+ = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
+/* The lengths of the bit length codes are sent in order of decreasing
+ * probability, to avoid transmitting the lengths for unused bit length codes.
+ */
+
+#define Buf_size (8 * 2*sizeof(char))
+/* Number of bits used within bi_buf. (bi_buf might be implemented on
+ * more than 16 bits on some systems.)
+ */
+
+/* ===========================================================================
+ * Local data. These are initialized only once.
+ */
+
+#define DIST_CODE_LEN 512 /* see definition of array dist_code below */
+
+#if defined(GEN_TREES_H) || !defined(STDC)
+/* non ANSI compilers may not accept trees.h */
+
+local ct_data static_ltree[L_CODES+2];
+/* The static literal tree. Since the bit lengths are imposed, there is no
+ * need for the L_CODES extra codes used during heap construction. However
+ * The codes 286 and 287 are needed to build a canonical tree (see _tr_init
+ * below).
+ */
+
+local ct_data static_dtree[D_CODES];
+/* The static distance tree. (Actually a trivial tree since all codes use
+ * 5 bits.)
+ */
+
+uch _dist_code[DIST_CODE_LEN];
+/* Distance codes. The first 256 values correspond to the distances
+ * 3 .. 258, the last 256 values correspond to the top 8 bits of
+ * the 15 bit distances.
+ */
+
+uch _length_code[MAX_MATCH-MIN_MATCH+1];
+/* length code for each normalized match length (0 == MIN_MATCH) */
+
+local int base_length[LENGTH_CODES];
+/* First normalized length for each code (0 = MIN_MATCH) */
+
+local int base_dist[D_CODES];
+/* First normalized distance for each code (0 = distance of 1) */
+
+#else
+# include "trees.h"
+#endif /* GEN_TREES_H */
+
+struct static_tree_desc_s {
+ const ct_data *static_tree; /* static tree or NULL */
+ const intf *extra_bits; /* extra bits for each code or NULL */
+ int extra_base; /* base index for extra_bits */
+ int elems; /* max number of elements in the tree */
+ int max_length; /* max bit length for the codes */
+};
+
+local static_tree_desc static_l_desc =
+{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
+
+local static_tree_desc static_d_desc =
+{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
+
+local static_tree_desc static_bl_desc =
+{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
+
+/* ===========================================================================
+ * Local (static) routines in this file.
+ */
+
+local void tr_static_init OF((void));
+local void init_block OF((deflate_state *s));
+local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
+local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
+local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
+local void build_tree OF((deflate_state *s, tree_desc *desc));
+local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
+local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
+local int build_bl_tree OF((deflate_state *s));
+local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
+ int blcodes));
+local void compress_block OF((deflate_state *s, ct_data *ltree,
+ ct_data *dtree));
+local void set_data_type OF((deflate_state *s));
+local unsigned bi_reverse OF((unsigned value, int length));
+local void bi_windup OF((deflate_state *s));
+local void bi_flush OF((deflate_state *s));
+local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
+ int header));
+
+#ifdef GEN_TREES_H
+local void gen_trees_header OF((void));
+#endif
+
+#ifndef DEBUG
+# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
+ /* Send a code of the given tree. c and tree must not have side effects */
+
+#else /* DEBUG */
+# define send_code(s, c, tree) \
+ { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
+ send_bits(s, tree[c].Code, tree[c].Len); }
+#endif
+
+/* ===========================================================================
+ * Output a short LSB first on the stream.
+ * IN assertion: there is enough room in pendingBuf.
+ */
+#define put_short(s, w) { \
+ put_byte(s, (uch)((w) & 0xff)); \
+ put_byte(s, (uch)((ush)(w) >> 8)); \
+}
+
+/* ===========================================================================
+ * Send a value on a given number of bits.
+ * IN assertion: length <= 16 and value fits in length bits.
+ */
+#ifdef DEBUG
+local void send_bits OF((deflate_state *s, int value, int length));
+
+local void send_bits(s, value, length)
+ deflate_state *s;
+ int value; /* value to send */
+ int length; /* number of bits */
+{
+ Tracevv((stderr," l %2d v %4x ", length, value));
+ Assert(length > 0 && length <= 15, "invalid length");
+ s->bits_sent += (ulg)length;
+
+ /* If not enough room in bi_buf, use (valid) bits from bi_buf and
+ * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid))
+ * unused bits in value.
+ */
+ if (s->bi_valid > (int)Buf_size - length) {
+ s->bi_buf |= (value << s->bi_valid);
+ put_short(s, s->bi_buf);
+ s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
+ s->bi_valid += length - Buf_size;
+ } else {
+ s->bi_buf |= value << s->bi_valid;
+ s->bi_valid += length;
+ }
+}
+#else /* !DEBUG */
+
+#define send_bits(s, value, length) \
+{ int len = length;\
+ if (s->bi_valid > (int)Buf_size - len) {\
+ int val = value;\
+ s->bi_buf |= (val << s->bi_valid);\
+ put_short(s, s->bi_buf);\
+ s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
+ s->bi_valid += len - Buf_size;\
+ } else {\
+ s->bi_buf |= (value) << s->bi_valid;\
+ s->bi_valid += len;\
+ }\
+}
+#endif /* DEBUG */
+
+
+/* the arguments must not have side effects */
+
+/* ===========================================================================
+ * Initialize the various 'constant' tables.
+ */
+local void tr_static_init()
+{
+#if defined(GEN_TREES_H) || !defined(STDC)
+ static int static_init_done = 0;
+ int n; /* iterates over tree elements */
+ int bits; /* bit counter */
+ int length; /* length value */
+ int code; /* code value */
+ int dist; /* distance index */
+ ush bl_count[MAX_BITS+1];
+ /* number of codes at each bit length for an optimal tree */
+
+ if (static_init_done) return;
+
+ /* For some embedded targets, global variables are not initialized: */
+ static_l_desc.static_tree = static_ltree;
+ static_l_desc.extra_bits = extra_lbits;
+ static_d_desc.static_tree = static_dtree;
+ static_d_desc.extra_bits = extra_dbits;
+ static_bl_desc.extra_bits = extra_blbits;
+
+ /* Initialize the mapping length (0..255) -> length code (0..28) */
+ length = 0;
+ for (code = 0; code < LENGTH_CODES-1; code++) {
+ base_length[code] = length;
+ for (n = 0; n < (1<<extra_lbits[code]); n++) {
+ _length_code[length++] = (uch)code;
+ }
+ }
+ Assert (length == 256, "tr_static_init: length != 256");
+ /* Note that the length 255 (match length 258) can be represented
+ * in two different ways: code 284 + 5 bits or code 285, so we
+ * overwrite length_code[255] to use the best encoding:
+ */
+ _length_code[length-1] = (uch)code;
+
+ /* Initialize the mapping dist (0..32K) -> dist code (0..29) */
+ dist = 0;
+ for (code = 0 ; code < 16; code++) {
+ base_dist[code] = dist;
+ for (n = 0; n < (1<<extra_dbits[code]); n++) {
+ _dist_code[dist++] = (uch)code;
+ }
+ }
+ Assert (dist == 256, "tr_static_init: dist != 256");
+ dist >>= 7; /* from now on, all distances are divided by 128 */
+ for ( ; code < D_CODES; code++) {
+ base_dist[code] = dist << 7;
+ for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
+ _dist_code[256 + dist++] = (uch)code;
+ }
+ }
+ Assert (dist == 256, "tr_static_init: 256+dist != 512");
+
+ /* Construct the codes of the static literal tree */
+ for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
+ n = 0;
+ while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
+ while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
+ while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
+ while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
+ /* Codes 286 and 287 do not exist, but we must include them in the
+ * tree construction to get a canonical Huffman tree (longest code
+ * all ones)
+ */
+ gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
+
+ /* The static distance tree is trivial: */
+ for (n = 0; n < D_CODES; n++) {
+ static_dtree[n].Len = 5;
+ static_dtree[n].Code = bi_reverse((unsigned)n, 5);
+ }
+ static_init_done = 1;
+
+# ifdef GEN_TREES_H
+ gen_trees_header();
+# endif
+#endif /* defined(GEN_TREES_H) || !defined(STDC) */
+}
+
+/* ===========================================================================
+ * Genererate the file trees.h describing the static trees.
+ */
+#ifdef GEN_TREES_H
+# ifndef DEBUG
+# include <stdio.h>
+# endif
+
+# define SEPARATOR(i, last, width) \
+ ((i) == (last)? "\n};\n\n" : \
+ ((i) % (width) == (width)-1 ? ",\n" : ", "))
+
+void gen_trees_header()
+{
+ FILE *header = fopen("trees.h", "w");
+ int i;
+
+ Assert (header != NULL, "Can't open trees.h");
+ fprintf(header,
+ "/* header created automatically with -DGEN_TREES_H */\n\n");
+
+ fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
+ for (i = 0; i < L_CODES+2; i++) {
+ fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
+ static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
+ }
+
+ fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
+ for (i = 0; i < D_CODES; i++) {
+ fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
+ static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
+ }
+
+ fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
+ for (i = 0; i < DIST_CODE_LEN; i++) {
+ fprintf(header, "%2u%s", _dist_code[i],
+ SEPARATOR(i, DIST_CODE_LEN-1, 20));
+ }
+
+ fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
+ for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
+ fprintf(header, "%2u%s", _length_code[i],
+ SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
+ }
+
+ fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
+ for (i = 0; i < LENGTH_CODES; i++) {
+ fprintf(header, "%1u%s", base_length[i],
+ SEPARATOR(i, LENGTH_CODES-1, 20));
+ }
+
+ fprintf(header, "local const int base_dist[D_CODES] = {\n");
+ for (i = 0; i < D_CODES; i++) {
+ fprintf(header, "%5u%s", base_dist[i],
+ SEPARATOR(i, D_CODES-1, 10));
+ }
+
+ fclose(header);
+}
+#endif /* GEN_TREES_H */
+
+/* ===========================================================================
+ * Initialize the tree data structures for a new zlib stream.
+ */
+void _tr_init(s)
+ deflate_state *s;
+{
+ tr_static_init();
+
+ s->l_desc.dyn_tree = s->dyn_ltree;
+ s->l_desc.stat_desc = &static_l_desc;
+
+ s->d_desc.dyn_tree = s->dyn_dtree;
+ s->d_desc.stat_desc = &static_d_desc;
+
+ s->bl_desc.dyn_tree = s->bl_tree;
+ s->bl_desc.stat_desc = &static_bl_desc;
+
+ s->bi_buf = 0;
+ s->bi_valid = 0;
+ s->last_eob_len = 8; /* enough lookahead for inflate */
+#ifdef DEBUG
+ s->compressed_len = 0L;
+ s->bits_sent = 0L;
+#endif
+
+ /* Initialize the first block of the first file: */
+ init_block(s);
+}
+
+/* ===========================================================================
+ * Initialize a new block.
+ */
+local void init_block(s)
+ deflate_state *s;
+{
+ int n; /* iterates over tree elements */
+
+ /* Initialize the trees. */
+ for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
+ for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
+ for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
+
+ s->dyn_ltree[END_BLOCK].Freq = 1;
+ s->opt_len = s->static_len = 0L;
+ s->last_lit = s->matches = 0;
+}
+
+#define SMALLEST 1
+/* Index within the heap array of least frequent node in the Huffman tree */
+
+
+/* ===========================================================================
+ * Remove the smallest element from the heap and recreate the heap with
+ * one less element. Updates heap and heap_len.
+ */
+#define pqremove(s, tree, top) \
+{\
+ top = s->heap[SMALLEST]; \
+ s->heap[SMALLEST] = s->heap[s->heap_len--]; \
+ pqdownheap(s, tree, SMALLEST); \
+}
+
+/* ===========================================================================
+ * Compares to subtrees, using the tree depth as tie breaker when
+ * the subtrees have equal frequency. This minimizes the worst case length.
+ */
+#define smaller(tree, n, m, depth) \
+ (tree[n].Freq < tree[m].Freq || \
+ (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
+
+/* ===========================================================================
+ * Restore the heap property by moving down the tree starting at node k,
+ * exchanging a node with the smallest of its two sons if necessary, stopping
+ * when the heap property is re-established (each father smaller than its
+ * two sons).
+ */
+local void pqdownheap(s, tree, k)
+ deflate_state *s;
+ ct_data *tree; /* the tree to restore */
+ int k; /* node to move down */
+{
+ int v = s->heap[k];
+ int j = k << 1; /* left son of k */
+ while (j <= s->heap_len) {
+ /* Set j to the smallest of the two sons: */
+ if (j < s->heap_len &&
+ smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
+ j++;
+ }
+ /* Exit if v is smaller than both sons */
+ if (smaller(tree, v, s->heap[j], s->depth)) break;
+
+ /* Exchange v with the smallest son */
+ s->heap[k] = s->heap[j]; k = j;
+
+ /* And continue down the tree, setting j to the left son of k */
+ j <<= 1;
+ }
+ s->heap[k] = v;
+}
+
+/* ===========================================================================
+ * Compute the optimal bit lengths for a tree and update the total bit length
+ * for the current block.
+ * IN assertion: the fields freq and dad are set, heap[heap_max] and
+ * above are the tree nodes sorted by increasing frequency.
+ * OUT assertions: the field len is set to the optimal bit length, the
+ * array bl_count contains the frequencies for each bit length.
+ * The length opt_len is updated; static_len is also updated if stree is
+ * not null.
+ */
+local void gen_bitlen(s, desc)
+ deflate_state *s;
+ tree_desc *desc; /* the tree descriptor */
+{
+ ct_data *tree = desc->dyn_tree;
+ int max_code = desc->max_code;
+ const ct_data *stree = desc->stat_desc->static_tree;
+ const intf *extra = desc->stat_desc->extra_bits;
+ int base = desc->stat_desc->extra_base;
+ int max_length = desc->stat_desc->max_length;
+ int h; /* heap index */
+ int n, m; /* iterate over the tree elements */
+ int bits; /* bit length */
+ int xbits; /* extra bits */
+ ush f; /* frequency */
+ int overflow = 0; /* number of elements with bit length too large */
+
+ for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
+
+ /* In a first pass, compute the optimal bit lengths (which may
+ * overflow in the case of the bit length tree).
+ */
+ tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
+
+ for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
+ n = s->heap[h];
+ bits = tree[tree[n].Dad].Len + 1;
+ if (bits > max_length) bits = max_length, overflow++;
+ tree[n].Len = (ush)bits;
+ /* We overwrite tree[n].Dad which is no longer needed */
+
+ if (n > max_code) continue; /* not a leaf node */
+
+ s->bl_count[bits]++;
+ xbits = 0;
+ if (n >= base) xbits = extra[n-base];
+ f = tree[n].Freq;
+ s->opt_len += (ulg)f * (bits + xbits);
+ if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
+ }
+ if (overflow == 0) return;
+
+ Trace((stderr,"\nbit length overflow\n"));
+ /* This happens for example on obj2 and pic of the Calgary corpus */
+
+ /* Find the first bit length which could increase: */
+ do {
+ bits = max_length-1;
+ while (s->bl_count[bits] == 0) bits--;
+ s->bl_count[bits]--; /* move one leaf down the tree */
+ s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
+ s->bl_count[max_length]--;
+ /* The brother of the overflow item also moves one step up,
+ * but this does not affect bl_count[max_length]
+ */
+ overflow -= 2;
+ } while (overflow > 0);
+
+ /* Now recompute all bit lengths, scanning in increasing frequency.
+ * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all
+ * lengths instead of fixing only the wrong ones. This idea is taken
+ * from 'ar' written by Haruhiko Okumura.)
+ */
+ for (bits = max_length; bits != 0; bits--) {
+ n = s->bl_count[bits];
+ while (n != 0) {
+ m = s->heap[--h];
+ if (m > max_code) continue;
+ if ((unsigned) tree[m].Len != (unsigned) bits) {
+ Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
+ s->opt_len += ((long)bits - (long)tree[m].Len)
+ *(long)tree[m].Freq;
+ tree[m].Len = (ush)bits;
+ }
+ n--;
+ }
+ }
+}
+
+/* ===========================================================================
+ * Generate the codes for a given tree and bit counts (which need not be
+ * optimal).
+ * IN assertion: the array bl_count contains the bit length statistics for
+ * the given tree and the field len is set for all tree elements.
+ * OUT assertion: the field code is set for all tree elements of non
+ * zero code length.
+ */
+local void gen_codes (tree, max_code, bl_count)
+ ct_data *tree; /* the tree to decorate */
+ int max_code; /* largest code with non zero frequency */
+ ushf *bl_count; /* number of codes at each bit length */
+{
+ ush next_code[MAX_BITS+1]; /* next code value for each bit length */
+ ush code = 0; /* running code value */
+ int bits; /* bit index */
+ int n; /* code index */
+
+ /* The distribution counts are first used to generate the code values
+ * without bit reversal.
+ */
+ for (bits = 1; bits <= MAX_BITS; bits++) {
+ next_code[bits] = code = (code + bl_count[bits-1]) << 1;
+ }
+ /* Check that the bit counts in bl_count are consistent. The last code
+ * must be all ones.
+ */
+ Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
+ "inconsistent bit counts");
+ Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
+
+ for (n = 0; n <= max_code; n++) {
+ int len = tree[n].Len;
+ if (len == 0) continue;
+ /* Now reverse the bits */
+ tree[n].Code = bi_reverse(next_code[len]++, len);
+
+ Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
+ n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
+ }
+}
+
+/* ===========================================================================
+ * Construct one Huffman tree and assigns the code bit strings and lengths.
+ * Update the total bit length for the current block.
+ * IN assertion: the field freq is set for all tree elements.
+ * OUT assertions: the fields len and code are set to the optimal bit length
+ * and corresponding code. The length opt_len is updated; static_len is
+ * also updated if stree is not null. The field max_code is set.
+ */
+local void build_tree(s, desc)
+ deflate_state *s;
+ tree_desc *desc; /* the tree descriptor */
+{
+ ct_data *tree = desc->dyn_tree;
+ const ct_data *stree = desc->stat_desc->static_tree;
+ int elems = desc->stat_desc->elems;
+ int n, m; /* iterate over heap elements */
+ int max_code = -1; /* largest code with non zero frequency */
+ int node; /* new node being created */
+
+ /* Construct the initial heap, with least frequent element in
+ * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1].
+ * heap[0] is not used.
+ */
+ s->heap_len = 0, s->heap_max = HEAP_SIZE;
+
+ for (n = 0; n < elems; n++) {
+ if (tree[n].Freq != 0) {
+ s->heap[++(s->heap_len)] = max_code = n;
+ s->depth[n] = 0;
+ } else {
+ tree[n].Len = 0;
+ }
+ }
+
+ /* The pkzip format requires that at least one distance code exists,
+ * and that at least one bit should be sent even if there is only one
+ * possible code. So to avoid special checks later on we force at least
+ * two codes of non zero frequency.
+ */
+ while (s->heap_len < 2) {
+ node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
+ tree[node].Freq = 1;
+ s->depth[node] = 0;
+ s->opt_len--; if (stree) s->static_len -= stree[node].Len;
+ /* node is 0 or 1 so it does not have extra bits */
+ }
+ desc->max_code = max_code;
+
+ /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree,
+ * establish sub-heaps of increasing lengths:
+ */
+ for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
+
+ /* Construct the Huffman tree by repeatedly combining the least two
+ * frequent nodes.
+ */
+ node = elems; /* next internal node of the tree */
+ do {
+ pqremove(s, tree, n); /* n = node of least frequency */
+ m = s->heap[SMALLEST]; /* m = node of next least frequency */
+
+ s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
+ s->heap[--(s->heap_max)] = m;
+
+ /* Create a new node father of n and m */
+ tree[node].Freq = tree[n].Freq + tree[m].Freq;
+ s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
+ s->depth[n] : s->depth[m]) + 1);
+ tree[n].Dad = tree[m].Dad = (ush)node;
+#ifdef DUMP_BL_TREE
+ if (tree == s->bl_tree) {
+ fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
+ node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
+ }
+#endif
+ /* and insert the new node in the heap */
+ s->heap[SMALLEST] = node++;
+ pqdownheap(s, tree, SMALLEST);
+
+ } while (s->heap_len >= 2);
+
+ s->heap[--(s->heap_max)] = s->heap[SMALLEST];
+
+ /* At this point, the fields freq and dad are set. We can now
+ * generate the bit lengths.
+ */
+ gen_bitlen(s, (tree_desc *)desc);
+
+ /* The field len is now set, we can generate the bit codes */
+ gen_codes ((ct_data *)tree, max_code, s->bl_count);
+}
+
+/* ===========================================================================
+ * Scan a literal or distance tree to determine the frequencies of the codes
+ * in the bit length tree.
+ */
+local void scan_tree (s, tree, max_code)
+ deflate_state *s;
+ ct_data *tree; /* the tree to be scanned */
+ int max_code; /* and its largest code of non zero frequency */
+{
+ int n; /* iterates over all tree elements */
+ int prevlen = -1; /* last emitted length */
+ int curlen; /* length of current code */
+ int nextlen = tree[0].Len; /* length of next code */
+ int count = 0; /* repeat count of the current code */
+ int max_count = 7; /* max repeat count */
+ int min_count = 4; /* min repeat count */
+
+ if (nextlen == 0) max_count = 138, min_count = 3;
+ tree[max_code+1].Len = (ush)0xffff; /* guard */
+
+ for (n = 0; n <= max_code; n++) {
+ curlen = nextlen; nextlen = tree[n+1].Len;
+ if (++count < max_count && curlen == nextlen) {
+ continue;
+ } else if (count < min_count) {
+ s->bl_tree[curlen].Freq += count;
+ } else if (curlen != 0) {
+ if (curlen != prevlen) s->bl_tree[curlen].Freq++;
+ s->bl_tree[REP_3_6].Freq++;
+ } else if (count <= 10) {
+ s->bl_tree[REPZ_3_10].Freq++;
+ } else {
+ s->bl_tree[REPZ_11_138].Freq++;
+ }
+ count = 0; prevlen = curlen;
+ if (nextlen == 0) {
+ max_count = 138, min_count = 3;
+ } else if (curlen == nextlen) {
+ max_count = 6, min_count = 3;
+ } else {
+ max_count = 7, min_count = 4;
+ }
+ }
+}
+
+/* ===========================================================================
+ * Send a literal or distance tree in compressed form, using the codes in
+ * bl_tree.
+ */
+local void send_tree (s, tree, max_code)
+ deflate_state *s;
+ ct_data *tree; /* the tree to be scanned */
+ int max_code; /* and its largest code of non zero frequency */
+{
+ int n; /* iterates over all tree elements */
+ int prevlen = -1; /* last emitted length */
+ int curlen; /* length of current code */
+ int nextlen = tree[0].Len; /* length of next code */
+ int count = 0; /* repeat count of the current code */
+ int max_count = 7; /* max repeat count */
+ int min_count = 4; /* min repeat count */
+
+ /* tree[max_code+1].Len = -1; */ /* guard already set */
+ if (nextlen == 0) max_count = 138, min_count = 3;
+
+ for (n = 0; n <= max_code; n++) {
+ curlen = nextlen; nextlen = tree[n+1].Len;
+ if (++count < max_count && curlen == nextlen) {
+ continue;
+ } else if (count < min_count) {
+ do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
+
+ } else if (curlen != 0) {
+ if (curlen != prevlen) {
+ send_code(s, curlen, s->bl_tree); count--;
+ }
+ Assert(count >= 3 && count <= 6, " 3_6?");
+ send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
+
+ } else if (count <= 10) {
+ send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
+
+ } else {
+ send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
+ }
+ count = 0; prevlen = curlen;
+ if (nextlen == 0) {
+ max_count = 138, min_count = 3;
+ } else if (curlen == nextlen) {
+ max_count = 6, min_count = 3;
+ } else {
+ max_count = 7, min_count = 4;
+ }
+ }
+}
+
+/* ===========================================================================
+ * Construct the Huffman tree for the bit lengths and return the index in
+ * bl_order of the last bit length code to send.
+ */
+local int build_bl_tree(s)
+ deflate_state *s;
+{
+ int max_blindex; /* index of last bit length code of non zero freq */
+
+ /* Determine the bit length frequencies for literal and distance trees */
+ scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
+ scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
+
+ /* Build the bit length tree: */
+ build_tree(s, (tree_desc *)(&(s->bl_desc)));
+ /* opt_len now includes the length of the tree representations, except
+ * the lengths of the bit lengths codes and the 5+5+4 bits for the counts.
+ */
+
+ /* Determine the number of bit length codes to send. The pkzip format
+ * requires that at least 4 bit length codes be sent. (appnote.txt says
+ * 3 but the actual value used is 4.)
+ */
+ for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
+ if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
+ }
+ /* Update opt_len to include the bit length tree and counts */
+ s->opt_len += 3*(max_blindex+1) + 5+5+4;
+ Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
+ s->opt_len, s->static_len));
+
+ return max_blindex;
+}
+
+/* ===========================================================================
+ * Send the header for a block using dynamic Huffman trees: the counts, the
+ * lengths of the bit length codes, the literal tree and the distance tree.
+ * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4.
+ */
+local void send_all_trees(s, lcodes, dcodes, blcodes)
+ deflate_state *s;
+ int lcodes, dcodes, blcodes; /* number of codes for each tree */
+{
+ int rank; /* index in bl_order */
+
+ Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
+ Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
+ "too many codes");
+ Tracev((stderr, "\nbl counts: "));
+ send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
+ send_bits(s, dcodes-1, 5);
+ send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
+ for (rank = 0; rank < blcodes; rank++) {
+ Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
+ send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
+ }
+ Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
+
+ send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
+ Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
+
+ send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
+ Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
+}
+
+/* ===========================================================================
+ * Send a stored block
+ */
+void _tr_stored_block(s, buf, stored_len, eof)
+ deflate_state *s;
+ charf *buf; /* input block */
+ ulg stored_len; /* length of input block */
+ int eof; /* true if this is the last block for a file */
+{
+ send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
+#ifdef DEBUG
+ s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
+ s->compressed_len += (stored_len + 4) << 3;
+#endif
+ copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
+}
+
+/* ===========================================================================
+ * Send one empty static block to give enough lookahead for inflate.
+ * This takes 10 bits, of which 7 may remain in the bit buffer.
+ * The current inflate code requires 9 bits of lookahead. If the
+ * last two codes for the previous block (real code plus EOB) were coded
+ * on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode
+ * the last real code. In this case we send two empty static blocks instead
+ * of one. (There are no problems if the previous block is stored or fixed.)
+ * To simplify the code, we assume the worst case of last real code encoded
+ * on one bit only.
+ */
+void _tr_align(s)
+ deflate_state *s;
+{
+ send_bits(s, STATIC_TREES<<1, 3);
+ send_code(s, END_BLOCK, static_ltree);
+#ifdef DEBUG
+ s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
+#endif
+ bi_flush(s);
+ /* Of the 10 bits for the empty block, we have already sent
+ * (10 - bi_valid) bits. The lookahead for the last real code (before
+ * the EOB of the previous block) was thus at least one plus the length
+ * of the EOB plus what we have just sent of the empty static block.
+ */
+ if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
+ send_bits(s, STATIC_TREES<<1, 3);
+ send_code(s, END_BLOCK, static_ltree);
+#ifdef DEBUG
+ s->compressed_len += 10L;
+#endif
+ bi_flush(s);
+ }
+ s->last_eob_len = 7;
+}
+
+/* ===========================================================================
+ * Determine the best encoding for the current block: dynamic trees, static
+ * trees or store, and output the encoded block to the zip file.
+ */
+void _tr_flush_block(s, buf, stored_len, eof)
+ deflate_state *s;
+ charf *buf; /* input block, or NULL if too old */
+ ulg stored_len; /* length of input block */
+ int eof; /* true if this is the last block for a file */
+{
+ ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
+ int max_blindex = 0; /* index of last bit length code of non zero freq */
+
+ /* Build the Huffman trees unless a stored block is forced */
+ if (s->level > 0) {
+
+ /* Check if the file is binary or text */
+ if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
+ set_data_type(s);
+
+ /* Construct the literal and distance trees */
+ build_tree(s, (tree_desc *)(&(s->l_desc)));
+ Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
+ s->static_len));
+
+ build_tree(s, (tree_desc *)(&(s->d_desc)));
+ Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
+ s->static_len));
+ /* At this point, opt_len and static_len are the total bit lengths of
+ * the compressed block data, excluding the tree representations.
+ */
+
+ /* Build the bit length tree for the above two trees, and get the index
+ * in bl_order of the last bit length code to send.
+ */
+ max_blindex = build_bl_tree(s);
+
+ /* Determine the best encoding. Compute the block lengths in bytes. */
+ opt_lenb = (s->opt_len+3+7)>>3;
+ static_lenb = (s->static_len+3+7)>>3;
+
+ Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
+ opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
+ s->last_lit));
+
+ if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
+
+ } else {
+ Assert(buf != (char*)0, "lost buf");
+ opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
+ }
+
+#ifdef FORCE_STORED
+ if (buf != (char*)0) { /* force stored block */
+#else
+ if (stored_len+4 <= opt_lenb && buf != (char*)0) {
+ /* 4: two words for the lengths */
+#endif
+ /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE.
+ * Otherwise we can't have processed more than WSIZE input bytes since
+ * the last block flush, because compression would have been
+ * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to
+ * transform a block into a stored block.
+ */
+ _tr_stored_block(s, buf, stored_len, eof);
+
+#ifdef FORCE_STATIC
+ } else if (static_lenb >= 0) { /* force static trees */
+#else
+ } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
+#endif
+ send_bits(s, (STATIC_TREES<<1)+eof, 3);
+ compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
+#ifdef DEBUG
+ s->compressed_len += 3 + s->static_len;
+#endif
+ } else {
+ send_bits(s, (DYN_TREES<<1)+eof, 3);
+ send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
+ max_blindex+1);
+ compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
+#ifdef DEBUG
+ s->compressed_len += 3 + s->opt_len;
+#endif
+ }
+ Assert (s->compressed_len == s->bits_sent, "bad compressed size");
+ /* The above check is made mod 2^32, for files larger than 512 MB
+ * and uLong implemented on 32 bits.
+ */
+ init_block(s);
+
+ if (eof) {
+ bi_windup(s);
+#ifdef DEBUG
+ s->compressed_len += 7; /* align on byte boundary */
+#endif
+ }
+ Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
+ s->compressed_len-7*eof));
+}
+
+/* ===========================================================================
+ * Save the match info and tally the frequency counts. Return true if
+ * the current block must be flushed.
+ */
+int _tr_tally (s, dist, lc)
+ deflate_state *s;
+ unsigned dist; /* distance of matched string */
+ unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */
+{
+ s->d_buf[s->last_lit] = (ush)dist;
+ s->l_buf[s->last_lit++] = (uch)lc;
+ if (dist == 0) {
+ /* lc is the unmatched char */
+ s->dyn_ltree[lc].Freq++;
+ } else {
+ s->matches++;
+ /* Here, lc is the match length - MIN_MATCH */
+ dist--; /* dist = match distance - 1 */
+ Assert((ush)dist < (ush)MAX_DIST(s) &&
+ (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
+ (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
+
+ s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
+ s->dyn_dtree[d_code(dist)].Freq++;
+ }
+
+#ifdef TRUNCATE_BLOCK
+ /* Try to guess if it is profitable to stop the current block here */
+ if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
+ /* Compute an upper bound for the compressed length */
+ ulg out_length = (ulg)s->last_lit*8L;
+ ulg in_length = (ulg)((long)s->strstart - s->block_start);
+ int dcode;
+ for (dcode = 0; dcode < D_CODES; dcode++) {
+ out_length += (ulg)s->dyn_dtree[dcode].Freq *
+ (5L+extra_dbits[dcode]);
+ }
+ out_length >>= 3;
+ Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
+ s->last_lit, in_length, out_length,
+ 100L - out_length*100L/in_length));
+ if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
+ }
+#endif
+ return (s->last_lit == s->lit_bufsize-1);
+ /* We avoid equality with lit_bufsize because of wraparound at 64K
+ * on 16 bit machines and because stored blocks are restricted to
+ * 64K-1 bytes.
+ */
+}
+
+/* ===========================================================================
+ * Send the block data compressed using the given Huffman trees
+ */
+local void compress_block(s, ltree, dtree)
+ deflate_state *s;
+ ct_data *ltree; /* literal tree */
+ ct_data *dtree; /* distance tree */
+{
+ unsigned dist; /* distance of matched string */
+ int lc; /* match length or unmatched char (if dist == 0) */
+ unsigned lx = 0; /* running index in l_buf */
+ unsigned code; /* the code to send */
+ int extra; /* number of extra bits to send */
+
+ if (s->last_lit != 0) do {
+ dist = s->d_buf[lx];
+ lc = s->l_buf[lx++];
+ if (dist == 0) {
+ send_code(s, lc, ltree); /* send a literal byte */
+ Tracecv(isgraph(lc), (stderr," '%c' ", lc));
+ } else {
+ /* Here, lc is the match length - MIN_MATCH */
+ code = _length_code[lc];
+ send_code(s, code+LITERALS+1, ltree); /* send the length code */
+ extra = extra_lbits[code];
+ if (extra != 0) {
+ lc -= base_length[code];
+ send_bits(s, lc, extra); /* send the extra length bits */
+ }
+ dist--; /* dist is now the match distance - 1 */
+ code = d_code(dist);
+ Assert (code < D_CODES, "bad d_code");
+
+ send_code(s, code, dtree); /* send the distance code */
+ extra = extra_dbits[code];
+ if (extra != 0) {
+ dist -= base_dist[code];
+ send_bits(s, dist, extra); /* send the extra distance bits */
+ }
+ } /* literal or match pair ? */
+
+ /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */
+ Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
+ "pendingBuf overflow");
+
+ } while (lx < s->last_lit);
+
+ send_code(s, END_BLOCK, ltree);
+ s->last_eob_len = ltree[END_BLOCK].Len;
+}
+
+/* ===========================================================================
+ * Set the data type to BINARY or TEXT, using a crude approximation:
+ * set it to Z_TEXT if all symbols are either printable characters (33 to 255)
+ * or white spaces (9 to 13, or 32); or set it to Z_BINARY otherwise.
+ * IN assertion: the fields Freq of dyn_ltree are set.
+ */
+local void set_data_type(s)
+ deflate_state *s;
+{
+ int n;
+
+ for (n = 0; n < 9; n++)
+ if (s->dyn_ltree[n].Freq != 0)
+ break;
+ if (n == 9)
+ for (n = 14; n < 32; n++)
+ if (s->dyn_ltree[n].Freq != 0)
+ break;
+ s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
+}
+
+/* ===========================================================================
+ * Reverse the first len bits of a code, using straightforward code (a faster
+ * method would use a table)
+ * IN assertion: 1 <= len <= 15
+ */
+local unsigned bi_reverse(code, len)
+ unsigned code; /* the value to invert */
+ int len; /* its bit length */
+{
+ register unsigned res = 0;
+ do {
+ res |= code & 1;
+ code >>= 1, res <<= 1;
+ } while (--len > 0);
+ return res >> 1;
+}
+
+/* ===========================================================================
+ * Flush the bit buffer, keeping at most 7 bits in it.
+ */
+local void bi_flush(s)
+ deflate_state *s;
+{
+ if (s->bi_valid == 16) {
+ put_short(s, s->bi_buf);
+ s->bi_buf = 0;
+ s->bi_valid = 0;
+ } else if (s->bi_valid >= 8) {
+ put_byte(s, (Byte)s->bi_buf);
+ s->bi_buf >>= 8;
+ s->bi_valid -= 8;
+ }
+}
+
+/* ===========================================================================
+ * Flush the bit buffer and align the output on a byte boundary
+ */
+local void bi_windup(s)
+ deflate_state *s;
+{
+ if (s->bi_valid > 8) {
+ put_short(s, s->bi_buf);
+ } else if (s->bi_valid > 0) {
+ put_byte(s, (Byte)s->bi_buf);
+ }
+ s->bi_buf = 0;
+ s->bi_valid = 0;
+#ifdef DEBUG
+ s->bits_sent = (s->bits_sent+7) & ~7;
+#endif
+}
+
+/* ===========================================================================
+ * Copy a stored block, storing first the length and its
+ * one's complement if requested.
+ */
+local void copy_block(s, buf, len, header)
+ deflate_state *s;
+ charf *buf; /* the input data */
+ unsigned len; /* its length */
+ int header; /* true if block header must be written */
+{
+ bi_windup(s); /* align on byte boundary */
+ s->last_eob_len = 8; /* enough lookahead for inflate */
+
+ if (header) {
+ put_short(s, (ush)len);
+ put_short(s, (ush)~len);
+#ifdef DEBUG
+ s->bits_sent += 2*16;
+#endif
+ }
+#ifdef DEBUG
+ s->bits_sent += (ulg)len<<3;
+#endif
+ while (len--) {
+ put_byte(s, *buf++);
+ }
+}
diff --git a/lib/libz/trees.h b/lib/libz/trees.h
new file mode 100644
index 0000000..ca79189
--- /dev/null
+++ b/lib/libz/trees.h
@@ -0,0 +1,129 @@
+/* $OpenBSD: trees.h,v 1.2 2002/03/12 00:25:57 millert Exp $ */
+/* header created automatically with -DGEN_TREES_H */
+
+local const ct_data static_ltree[L_CODES+2] = {
+{{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
+{{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
+{{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
+{{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
+{{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
+{{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
+{{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
+{{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
+{{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
+{{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
+{{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
+{{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
+{{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
+{{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
+{{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
+{{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
+{{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
+{{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
+{{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
+{{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
+{{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
+{{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
+{{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
+{{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
+{{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
+{{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
+{{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
+{{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
+{{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
+{{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
+{{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
+{{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
+{{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
+{{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
+{{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
+{{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
+{{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
+{{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
+{{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
+{{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
+{{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
+{{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
+{{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
+{{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
+{{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
+{{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
+{{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
+{{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
+{{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
+{{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
+{{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
+{{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
+{{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
+{{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
+{{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
+{{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
+{{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
+{{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
+};
+
+local const ct_data static_dtree[D_CODES] = {
+{{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
+{{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
+{{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
+{{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
+{{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
+{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
+};
+
+const uch _dist_code[DIST_CODE_LEN] = {
+ 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
+ 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
+10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
+12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
+13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
+13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
+14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
+15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
+15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
+18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
+23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
+26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
+27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
+27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
+28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
+29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
+};
+
+const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
+13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
+17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
+19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
+21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
+22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
+23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
+25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
+25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
+26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
+26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
+27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
+};
+
+local const int base_length[LENGTH_CODES] = {
+0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
+64, 80, 96, 112, 128, 160, 192, 224, 0
+};
+
+local const int base_dist[D_CODES] = {
+ 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
+ 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
+ 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
+};
+
diff --git a/lib/libz/uncompr.c b/lib/libz/uncompr.c
new file mode 100644
index 0000000..2b50fa3
--- /dev/null
+++ b/lib/libz/uncompr.c
@@ -0,0 +1,61 @@
+/* $OpenBSD: uncompr.c,v 1.5 2003/12/16 22:33:02 henning Exp $ */
+/* uncompr.c -- decompress a memory buffer
+ * Copyright (C) 1995-2003 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+
+#define ZLIB_INTERNAL
+#include "zlib.h"
+
+/* ===========================================================================
+ Decompresses the source buffer into the destination buffer. sourceLen is
+ the byte length of the source buffer. Upon entry, destLen is the total
+ size of the destination buffer, which must be large enough to hold the
+ entire uncompressed data. (The size of the uncompressed data must have
+ been saved previously by the compressor and transmitted to the decompressor
+ by some mechanism outside the scope of this compression library.)
+ Upon exit, destLen is the actual size of the compressed buffer.
+ This function can be used to decompress a whole file at once if the
+ input file is mmap'ed.
+
+ uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_BUF_ERROR if there was not enough room in the output
+ buffer, or Z_DATA_ERROR if the input data was corrupted.
+*/
+int ZEXPORT uncompress (dest, destLen, source, sourceLen)
+ Bytef *dest;
+ uLongf *destLen;
+ const Bytef *source;
+ uLong sourceLen;
+{
+ z_stream stream;
+ int err;
+
+ stream.next_in = (Bytef*)source;
+ stream.avail_in = (uInt)sourceLen;
+ /* Check for source > 64K on 16-bit machine: */
+ if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
+
+ stream.next_out = dest;
+ stream.avail_out = (uInt)*destLen;
+ if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
+
+ stream.zalloc = (alloc_func)0;
+ stream.zfree = (free_func)0;
+
+ err = inflateInit(&stream);
+ if (err != Z_OK) return err;
+
+ err = inflate(&stream, Z_FINISH);
+ if (err != Z_STREAM_END) {
+ inflateEnd(&stream);
+ if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
+ return Z_DATA_ERROR;
+ return err;
+ }
+ *destLen = stream.total_out;
+
+ err = inflateEnd(&stream);
+ return err;
+}
diff --git a/lib/libz/zconf.h b/lib/libz/zconf.h
new file mode 100644
index 0000000..7ac5b7b
--- /dev/null
+++ b/lib/libz/zconf.h
@@ -0,0 +1,330 @@
+/* $OpenBSD: zconf.h,v 1.8 2019/05/12 15:56:56 jca Exp $ */
+/* zconf.h -- configuration of the zlib compression library
+ * Copyright (C) 1995-2005 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+
+#ifndef ZCONF_H
+#define ZCONF_H
+
+/*
+ * If you *really* need a unique prefix for all types and library functions,
+ * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
+ */
+#ifdef Z_PREFIX
+# define deflateInit_ z_deflateInit_
+# define deflate z_deflate
+# define deflateEnd z_deflateEnd
+# define inflateInit_ z_inflateInit_
+# define inflate z_inflate
+# define inflateEnd z_inflateEnd
+# define deflateInit2_ z_deflateInit2_
+# define deflateSetDictionary z_deflateSetDictionary
+# define deflateCopy z_deflateCopy
+# define deflateReset z_deflateReset
+# define deflateParams z_deflateParams
+# define deflateBound z_deflateBound
+# define deflatePrime z_deflatePrime
+# define inflateInit2_ z_inflateInit2_
+# define inflateSetDictionary z_inflateSetDictionary
+# define inflateSync z_inflateSync
+# define inflateSyncPoint z_inflateSyncPoint
+# define inflateCopy z_inflateCopy
+# define inflateReset z_inflateReset
+# define inflateBack z_inflateBack
+# define inflateBackEnd z_inflateBackEnd
+# define compress z_compress
+# define compress2 z_compress2
+# define compressBound z_compressBound
+# define uncompress z_uncompress
+# define adler32 z_adler32
+# define crc32 z_crc32
+# define get_crc_table z_get_crc_table
+# define zError z_zError
+
+# define alloc_func z_alloc_func
+# define free_func z_free_func
+# define in_func z_in_func
+# define out_func z_out_func
+# define Byte z_Byte
+# define uInt z_uInt
+# define uLong z_uLong
+# define Bytef z_Bytef
+# define charf z_charf
+# define intf z_intf
+# define uIntf z_uIntf
+# define uLongf z_uLongf
+# define voidpf z_voidpf
+# define voidp z_voidp
+#endif
+
+#if defined(__MSDOS__) && !defined(MSDOS)
+# define MSDOS
+#endif
+#if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
+# define OS2
+#endif
+#if defined(_WINDOWS) && !defined(WINDOWS)
+# define WINDOWS
+#endif
+#if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
+# ifndef WIN32
+# define WIN32
+# endif
+#endif
+#if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
+# if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
+# ifndef SYS16BIT
+# define SYS16BIT
+# endif
+# endif
+#endif
+
+/*
+ * Compile with -DMAXSEG_64K if the alloc function cannot allocate more
+ * than 64k bytes at a time (needed on systems with 16-bit int).
+ */
+#ifdef SYS16BIT
+# define MAXSEG_64K
+#endif
+#ifdef MSDOS
+# define UNALIGNED_OK
+#endif
+
+#ifdef __STDC_VERSION__
+# ifndef STDC
+# define STDC
+# endif
+# if __STDC_VERSION__ >= 199901L
+# ifndef STDC99
+# define STDC99
+# endif
+# endif
+#endif
+#if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
+# define STDC
+#endif
+#if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
+# define STDC
+#endif
+#if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
+# define STDC
+#endif
+#if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
+# define STDC
+#endif
+
+#if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
+# define STDC
+#endif
+
+#ifndef STDC
+# ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
+# define const /* note: need a more gentle solution here */
+# endif
+#endif
+
+#if defined(ZLIB_CONST) && !defined(z_const)
+# define z_const const
+#else
+# define z_const
+#endif
+
+/* Some Mac compilers merge all .h files incorrectly: */
+#if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
+# define NO_DUMMY_DECL
+#endif
+
+/* Maximum value for memLevel in deflateInit2 */
+#ifndef MAX_MEM_LEVEL
+# ifdef MAXSEG_64K
+# define MAX_MEM_LEVEL 8
+# else
+# define MAX_MEM_LEVEL 9
+# endif
+#endif
+
+/* Maximum value for windowBits in deflateInit2 and inflateInit2.
+ * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
+ * created by gzip. (Files created by minigzip can still be extracted by
+ * gzip.)
+ */
+#ifndef MAX_WBITS
+# define MAX_WBITS 15 /* 32K LZ77 window */
+#endif
+
+/* The memory requirements for deflate are (in bytes):
+ (1 << (windowBits+2)) + (1 << (memLevel+9))
+ that is: 128K for windowBits=15 + 128K for memLevel = 8 (default values)
+ plus a few kilobytes for small objects. For example, if you want to reduce
+ the default memory requirements from 256K to 128K, compile with
+ make CFLAGS="-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7"
+ Of course this will generally degrade compression (there's no free lunch).
+
+ The memory requirements for inflate are (in bytes) 1 << windowBits
+ that is, 32K for windowBits=15 (default value) plus a few kilobytes
+ for small objects.
+*/
+
+ /* Type declarations */
+
+#ifndef OF /* function prototypes */
+# ifdef STDC
+# define OF(args) args
+# else
+# define OF(args) ()
+# endif
+#endif
+
+/* The following definitions for FAR are needed only for MSDOS mixed
+ * model programming (small or medium model with some far allocations).
+ * This was tested only with MSC; for other MSDOS compilers you may have
+ * to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
+ * just define FAR to be empty.
+ */
+#ifdef SYS16BIT
+# if defined(M_I86SM) || defined(M_I86MM)
+ /* MSC small or medium model */
+# define SMALL_MEDIUM
+# ifdef _MSC_VER
+# define FAR _far
+# else
+# define FAR far
+# endif
+# endif
+# if (defined(__SMALL__) || defined(__MEDIUM__))
+ /* Turbo C small or medium model */
+# define SMALL_MEDIUM
+# ifdef __BORLANDC__
+# define FAR _far
+# else
+# define FAR far
+# endif
+# endif
+#endif
+
+#if defined(WINDOWS) || defined(WIN32)
+ /* If building or using zlib as a DLL, define ZLIB_DLL.
+ * This is not mandatory, but it offers a little performance increase.
+ */
+# ifdef ZLIB_DLL
+# if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
+# ifdef ZLIB_INTERNAL
+# define ZEXTERN extern __declspec(dllexport)
+# else
+# define ZEXTERN extern __declspec(dllimport)
+# endif
+# endif
+# endif /* ZLIB_DLL */
+ /* If building or using zlib with the WINAPI/WINAPIV calling convention,
+ * define ZLIB_WINAPI.
+ * Caution: the standard ZLIB1.DLL is NOT compiled using ZLIB_WINAPI.
+ */
+# ifdef ZLIB_WINAPI
+# ifdef FAR
+# undef FAR
+# endif
+# include <windows.h>
+ /* No need for _export, use ZLIB.DEF instead. */
+ /* For complete Windows compatibility, use WINAPI, not __stdcall. */
+# define ZEXPORT WINAPI
+# ifdef WIN32
+# define ZEXPORTVA WINAPIV
+# else
+# define ZEXPORTVA FAR CDECL
+# endif
+# endif
+#endif
+
+#if defined (__BEOS__)
+# ifdef ZLIB_DLL
+# ifdef ZLIB_INTERNAL
+# define ZEXPORT __declspec(dllexport)
+# define ZEXPORTVA __declspec(dllexport)
+# else
+# define ZEXPORT __declspec(dllimport)
+# define ZEXPORTVA __declspec(dllimport)
+# endif
+# endif
+#endif
+
+#ifndef ZEXTERN
+# define ZEXTERN extern
+#endif
+#ifndef ZEXPORT
+# define ZEXPORT
+#endif
+#ifndef ZEXPORTVA
+# define ZEXPORTVA
+#endif
+
+#ifndef FAR
+# define FAR
+#endif
+
+#if !defined(__MACTYPES__)
+typedef unsigned char Byte; /* 8 bits */
+#endif
+typedef unsigned int uInt; /* 16 bits or more */
+typedef unsigned long uLong; /* 32 bits or more */
+
+#ifdef SMALL_MEDIUM
+ /* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
+# define Bytef Byte FAR
+#else
+ typedef Byte FAR Bytef;
+#endif
+typedef char FAR charf;
+typedef int FAR intf;
+typedef uInt FAR uIntf;
+typedef uLong FAR uLongf;
+
+#ifdef STDC
+ typedef void const *voidpc;
+ typedef void FAR *voidpf;
+ typedef void *voidp;
+#else
+ typedef Byte const *voidpc;
+ typedef Byte FAR *voidpf;
+ typedef Byte *voidp;
+#endif
+
+#include <sys/types.h> /* for off_t */
+#include <unistd.h> /* for SEEK_* and off_t */
+#define z_off_t off_t
+#ifndef SEEK_SET
+# define SEEK_SET 0 /* Seek from beginning of file. */
+# define SEEK_CUR 1 /* Seek from current position. */
+# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
+#endif
+
+#if defined(__OS400__)
+#define NO_vsnprintf
+#endif
+
+#if defined(__MVS__)
+# define NO_vsnprintf
+# ifdef FAR
+# undef FAR
+# endif
+#endif
+
+/* MVS linker does not support external names larger than 8 bytes */
+#if defined(__MVS__)
+# pragma map(deflateInit_,"DEIN")
+# pragma map(deflateInit2_,"DEIN2")
+# pragma map(deflateEnd,"DEEND")
+# pragma map(deflateBound,"DEBND")
+# pragma map(inflateInit_,"ININ")
+# pragma map(inflateInit2_,"ININ2")
+# pragma map(inflateEnd,"INEND")
+# pragma map(inflateSync,"INSY")
+# pragma map(inflateSetDictionary,"INSEDI")
+# pragma map(compressBound,"CMBND")
+# pragma map(inflate_table,"INTABL")
+# pragma map(inflate_fast,"INFA")
+# pragma map(inflate_copyright,"INCOPY")
+#endif
+
+#endif /* ZCONF_H */
diff --git a/lib/libz/zlib.h b/lib/libz/zlib.h
new file mode 100644
index 0000000..a2c23f0
--- /dev/null
+++ b/lib/libz/zlib.h
@@ -0,0 +1,1359 @@
+/* $OpenBSD: zlib.h,v 1.11 2019/05/12 15:56:56 jca Exp $ */
+/* zlib.h -- interface of the 'zlib' general purpose compression library
+ version 1.2.3, July 18th, 2005
+
+ Copyright (C) 1995-2005 Jean-loup Gailly and Mark Adler
+
+ This software is provided 'as-is', without any express or implied
+ warranty. In no event will the authors be held liable for any damages
+ arising from the use of this software.
+
+ Permission is granted to anyone to use this software for any purpose,
+ including commercial applications, and to alter it and redistribute it
+ freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not
+ claim that you wrote the original software. If you use this software
+ in a product, an acknowledgment in the product documentation would be
+ appreciated but is not required.
+ 2. Altered source versions must be plainly marked as such, and must not be
+ misrepresented as being the original software.
+ 3. This notice may not be removed or altered from any source distribution.
+
+ Jean-loup Gailly Mark Adler
+ jloup@gzip.org madler@alumni.caltech.edu
+
+
+ The data format used by the zlib library is described by RFCs (Request for
+ Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt
+ (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
+*/
+
+#ifndef ZLIB_H
+#define ZLIB_H
+
+#include "zconf.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define ZLIB_VERSION "1.2.3"
+#define ZLIB_VERNUM 0x1230
+
+/*
+ The 'zlib' compression library provides in-memory compression and
+ decompression functions, including integrity checks of the uncompressed
+ data. This version of the library supports only one compression method
+ (deflation) but other algorithms will be added later and will have the same
+ stream interface.
+
+ Compression can be done in a single step if the buffers are large
+ enough (for example if an input file is mmap'ed), or can be done by
+ repeated calls of the compression function. In the latter case, the
+ application must provide more input and/or consume the output
+ (providing more output space) before each call.
+
+ The compressed data format used by default by the in-memory functions is
+ the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped
+ around a deflate stream, which is itself documented in RFC 1951.
+
+ The library also supports reading and writing files in gzip (.gz) format
+ with an interface similar to that of stdio using the functions that start
+ with "gz". The gzip format is different from the zlib format. gzip is a
+ gzip wrapper, documented in RFC 1952, wrapped around a deflate stream.
+
+ This library can optionally read and write gzip streams in memory as well.
+
+ The zlib format was designed to be compact and fast for use in memory
+ and on communications channels. The gzip format was designed for single-
+ file compression on file systems, has a larger header than zlib to maintain
+ directory information, and uses a different, slower check method than zlib.
+
+ The library does not install any signal handler. The decoder checks
+ the consistency of the compressed data, so the library should never
+ crash even in case of corrupted input.
+*/
+
+typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
+typedef void (*free_func) OF((voidpf opaque, voidpf address));
+
+struct internal_state;
+
+typedef struct z_stream_s {
+ z_const Bytef *next_in; /* next input byte */
+ uInt avail_in; /* number of bytes available at next_in */
+ z_off_t total_in; /* total nb of input bytes read so far */
+
+ Bytef *next_out; /* next output byte should be put there */
+ uInt avail_out; /* remaining free space at next_out */
+ z_off_t total_out; /* total nb of bytes output so far */
+
+ z_const char *msg; /* last error message, NULL if no error */
+ struct internal_state FAR *state; /* not visible by applications */
+
+ alloc_func zalloc; /* used to allocate the internal state */
+ free_func zfree; /* used to free the internal state */
+ voidpf opaque; /* private data object passed to zalloc and zfree */
+
+ int data_type; /* best guess about the data type: binary or text */
+ uLong adler; /* adler32 value of the uncompressed data */
+ uLong reserved; /* reserved for future use */
+} z_stream;
+
+typedef z_stream FAR *z_streamp;
+
+/*
+ gzip header information passed to and from zlib routines. See RFC 1952
+ for more details on the meanings of these fields.
+*/
+typedef struct gz_header_s {
+ int text; /* true if compressed data believed to be text */
+ uLong time; /* modification time */
+ int xflags; /* extra flags (not used when writing a gzip file) */
+ int os; /* operating system */
+ Bytef *extra; /* pointer to extra field or Z_NULL if none */
+ uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
+ uInt extra_max; /* space at extra (only when reading header) */
+ Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
+ uInt name_max; /* space at name (only when reading header) */
+ Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
+ uInt comm_max; /* space at comment (only when reading header) */
+ int hcrc; /* true if there was or will be a header crc */
+ int done; /* true when done reading gzip header (not used
+ when writing a gzip file) */
+} gz_header;
+
+typedef gz_header FAR *gz_headerp;
+
+/*
+ The application must update next_in and avail_in when avail_in has
+ dropped to zero. It must update next_out and avail_out when avail_out
+ has dropped to zero. The application must initialize zalloc, zfree and
+ opaque before calling the init function. All other fields are set by the
+ compression library and must not be updated by the application.
+
+ The opaque value provided by the application will be passed as the first
+ parameter for calls of zalloc and zfree. This can be useful for custom
+ memory management. The compression library attaches no meaning to the
+ opaque value.
+
+ zalloc must return Z_NULL if there is not enough memory for the object.
+ If zlib is used in a multi-threaded application, zalloc and zfree must be
+ thread safe.
+
+ On 16-bit systems, the functions zalloc and zfree must be able to allocate
+ exactly 65536 bytes, but will not be required to allocate more than this
+ if the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS,
+ pointers returned by zalloc for objects of exactly 65536 bytes *must*
+ have their offset normalized to zero. The default allocation function
+ provided by this library ensures this (see zutil.c). To reduce memory
+ requirements and avoid any allocation of 64K objects, at the expense of
+ compression ratio, compile the library with -DMAX_WBITS=14 (see zconf.h).
+
+ The fields total_in and total_out can be used for statistics or
+ progress reports. After compression, total_in holds the total size of
+ the uncompressed data and may be saved for use in the decompressor
+ (particularly if the decompressor wants to decompress everything in
+ a single step).
+*/
+
+ /* constants */
+
+#define Z_NO_FLUSH 0
+#define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
+#define Z_SYNC_FLUSH 2
+#define Z_FULL_FLUSH 3
+#define Z_FINISH 4
+#define Z_BLOCK 5
+/* Allowed flush values; see deflate() and inflate() below for details */
+
+#define Z_OK 0
+#define Z_STREAM_END 1
+#define Z_NEED_DICT 2
+#define Z_ERRNO (-1)
+#define Z_STREAM_ERROR (-2)
+#define Z_DATA_ERROR (-3)
+#define Z_MEM_ERROR (-4)
+#define Z_BUF_ERROR (-5)
+#define Z_VERSION_ERROR (-6)
+/* Return codes for the compression/decompression functions. Negative
+ * values are errors, positive values are used for special but normal events.
+ */
+
+#define Z_NO_COMPRESSION 0
+#define Z_BEST_SPEED 1
+#define Z_BEST_COMPRESSION 9
+#define Z_DEFAULT_COMPRESSION (-1)
+/* compression levels */
+
+#define Z_FILTERED 1
+#define Z_HUFFMAN_ONLY 2
+#define Z_RLE 3
+#define Z_FIXED 4
+#define Z_DEFAULT_STRATEGY 0
+/* compression strategy; see deflateInit2() below for details */
+
+#define Z_BINARY 0
+#define Z_TEXT 1
+#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
+#define Z_UNKNOWN 2
+/* Possible values of the data_type field (though see inflate()) */
+
+#define Z_DEFLATED 8
+/* The deflate compression method (the only one supported in this version) */
+
+#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
+
+#define zlib_version zlibVersion()
+/* for compatibility with versions < 1.0.2 */
+
+ /* basic functions */
+
+ZEXTERN const char * ZEXPORT zlibVersion OF((void));
+/* The application can compare zlibVersion and ZLIB_VERSION for consistency.
+ If the first character differs, the library code actually used is
+ not compatible with the zlib.h header file used by the application.
+ This check is automatically made by deflateInit and inflateInit.
+ */
+
+/*
+ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
+
+ Initializes the internal stream state for compression. The fields
+ zalloc, zfree and opaque must be initialized before by the caller.
+ If zalloc and zfree are set to Z_NULL, deflateInit updates them to
+ use default allocation functions.
+
+ The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9:
+ 1 gives best speed, 9 gives best compression, 0 gives no compression at
+ all (the input data is simply copied a block at a time).
+ Z_DEFAULT_COMPRESSION requests a default compromise between speed and
+ compression (currently equivalent to level 6).
+
+ deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_STREAM_ERROR if level is not a valid compression level,
+ Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible
+ with the version assumed by the caller (ZLIB_VERSION).
+ msg is set to null if there is no error message. deflateInit does not
+ perform any compression: this will be done by deflate().
+*/
+
+
+ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
+/*
+ deflate compresses as much data as possible, and stops when the input
+ buffer becomes empty or the output buffer becomes full. It may introduce some
+ output latency (reading input without producing any output) except when
+ forced to flush.
+
+ The detailed semantics are as follows. deflate performs one or both of the
+ following actions:
+
+ - Compress more input starting at next_in and update next_in and avail_in
+ accordingly. If not all input can be processed (because there is not
+ enough room in the output buffer), next_in and avail_in are updated and
+ processing will resume at this point for the next call of deflate().
+
+ - Provide more output starting at next_out and update next_out and avail_out
+ accordingly. This action is forced if the parameter flush is non zero.
+ Forcing flush frequently degrades the compression ratio, so this parameter
+ should be set only when necessary (in interactive applications).
+ Some output may be provided even if flush is not set.
+
+ Before the call of deflate(), the application should ensure that at least
+ one of the actions is possible, by providing more input and/or consuming
+ more output, and updating avail_in or avail_out accordingly; avail_out
+ should never be zero before the call. The application can consume the
+ compressed output when it wants, for example when the output buffer is full
+ (avail_out == 0), or after each call of deflate(). If deflate returns Z_OK
+ and with zero avail_out, it must be called again after making room in the
+ output buffer because there might be more output pending.
+
+ Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to
+ decide how much data to accumulate before producing output, in order to
+ maximize compression.
+
+ If the parameter flush is set to Z_SYNC_FLUSH, all pending output is
+ flushed to the output buffer and the output is aligned on a byte boundary, so
+ that the decompressor can get all input data available so far. (In particular
+ avail_in is zero after the call if enough output space has been provided
+ before the call.) Flushing may degrade compression for some compression
+ algorithms and so it should be used only when necessary.
+
+ If flush is set to Z_FULL_FLUSH, all output is flushed as with
+ Z_SYNC_FLUSH, and the compression state is reset so that decompression can
+ restart from this point if previous compressed data has been damaged or if
+ random access is desired. Using Z_FULL_FLUSH too often can seriously degrade
+ compression.
+
+ If deflate returns with avail_out == 0, this function must be called again
+ with the same value of the flush parameter and more output space (updated
+ avail_out), until the flush is complete (deflate returns with non-zero
+ avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that
+ avail_out is greater than six to avoid repeated flush markers due to
+ avail_out == 0 on return.
+
+ If the parameter flush is set to Z_FINISH, pending input is processed,
+ pending output is flushed and deflate returns with Z_STREAM_END if there
+ was enough output space; if deflate returns with Z_OK, this function must be
+ called again with Z_FINISH and more output space (updated avail_out) but no
+ more input data, until it returns with Z_STREAM_END or an error. After
+ deflate has returned Z_STREAM_END, the only possible operations on the
+ stream are deflateReset or deflateEnd.
+
+ Z_FINISH can be used immediately after deflateInit if all the compression
+ is to be done in a single step. In this case, avail_out must be at least
+ the value returned by deflateBound (see below). If deflate does not return
+ Z_STREAM_END, then it must be called again as described above.
+
+ deflate() sets strm->adler to the adler32 checksum of all input read
+ so far (that is, total_in bytes).
+
+ deflate() may update strm->data_type if it can make a good guess about
+ the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered
+ binary. This field is only for information purposes and does not affect
+ the compression algorithm in any manner.
+
+ deflate() returns Z_OK if some progress has been made (more input
+ processed or more output produced), Z_STREAM_END if all input has been
+ consumed and all output has been produced (only when flush is set to
+ Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example
+ if next_in or next_out was NULL), Z_BUF_ERROR if no progress is possible
+ (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not
+ fatal, and deflate() can be called again with more input and more output
+ space to continue compressing.
+*/
+
+
+ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
+/*
+ All dynamically allocated data structures for this stream are freed.
+ This function discards any unprocessed input and does not flush any
+ pending output.
+
+ deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the
+ stream state was inconsistent, Z_DATA_ERROR if the stream was freed
+ prematurely (some input or output was discarded). In the error case,
+ msg may be set but then points to a static string (which must not be
+ deallocated).
+*/
+
+
+/*
+ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
+
+ Initializes the internal stream state for decompression. The fields
+ next_in, avail_in, zalloc, zfree and opaque must be initialized before by
+ the caller. If next_in is not Z_NULL and avail_in is large enough (the exact
+ value depends on the compression method), inflateInit determines the
+ compression method from the zlib header and allocates all data structures
+ accordingly; otherwise the allocation will be deferred to the first call of
+ inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to
+ use default allocation functions.
+
+ inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_VERSION_ERROR if the zlib library version is incompatible with the
+ version assumed by the caller. msg is set to null if there is no error
+ message. inflateInit does not perform any decompression apart from reading
+ the zlib header if present: this will be done by inflate(). (So next_in and
+ avail_in may be modified, but next_out and avail_out are unchanged.)
+*/
+
+
+ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
+/*
+ inflate decompresses as much data as possible, and stops when the input
+ buffer becomes empty or the output buffer becomes full. It may introduce
+ some output latency (reading input without producing any output) except when
+ forced to flush.
+
+ The detailed semantics are as follows. inflate performs one or both of the
+ following actions:
+
+ - Decompress more input starting at next_in and update next_in and avail_in
+ accordingly. If not all input can be processed (because there is not
+ enough room in the output buffer), next_in is updated and processing
+ will resume at this point for the next call of inflate().
+
+ - Provide more output starting at next_out and update next_out and avail_out
+ accordingly. inflate() provides as much output as possible, until there
+ is no more input data or no more space in the output buffer (see below
+ about the flush parameter).
+
+ Before the call of inflate(), the application should ensure that at least
+ one of the actions is possible, by providing more input and/or consuming
+ more output, and updating the next_* and avail_* values accordingly.
+ The application can consume the uncompressed output when it wants, for
+ example when the output buffer is full (avail_out == 0), or after each
+ call of inflate(). If inflate returns Z_OK and with zero avail_out, it
+ must be called again after making room in the output buffer because there
+ might be more output pending.
+
+ The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH,
+ Z_FINISH, or Z_BLOCK. Z_SYNC_FLUSH requests that inflate() flush as much
+ output as possible to the output buffer. Z_BLOCK requests that inflate() stop
+ if and when it gets to the next deflate block boundary. When decoding the
+ zlib or gzip format, this will cause inflate() to return immediately after
+ the header and before the first block. When doing a raw inflate, inflate()
+ will go ahead and process the first block, and will return when it gets to
+ the end of that block, or when it runs out of data.
+
+ The Z_BLOCK option assists in appending to or combining deflate streams.
+ Also to assist in this, on return inflate() will set strm->data_type to the
+ number of unused bits in the last byte taken from strm->next_in, plus 64
+ if inflate() is currently decoding the last block in the deflate stream,
+ plus 128 if inflate() returned immediately after decoding an end-of-block
+ code or decoding the complete header up to just before the first byte of the
+ deflate stream. The end-of-block will not be indicated until all of the
+ uncompressed data from that block has been written to strm->next_out. The
+ number of unused bits may in general be greater than seven, except when
+ bit 7 of data_type is set, in which case the number of unused bits will be
+ less than eight.
+
+ inflate() should normally be called until it returns Z_STREAM_END or an
+ error. However if all decompression is to be performed in a single step
+ (a single call of inflate), the parameter flush should be set to
+ Z_FINISH. In this case all pending input is processed and all pending
+ output is flushed; avail_out must be large enough to hold all the
+ uncompressed data. (The size of the uncompressed data may have been saved
+ by the compressor for this purpose.) The next operation on this stream must
+ be inflateEnd to deallocate the decompression state. The use of Z_FINISH
+ is never required, but can be used to inform inflate that a faster approach
+ may be used for the single inflate() call.
+
+ In this implementation, inflate() always flushes as much output as
+ possible to the output buffer, and always uses the faster approach on the
+ first call. So the only effect of the flush parameter in this implementation
+ is on the return value of inflate(), as noted below, or when it returns early
+ because Z_BLOCK is used.
+
+ If a preset dictionary is needed after this call (see inflateSetDictionary
+ below), inflate sets strm->adler to the adler32 checksum of the dictionary
+ chosen by the compressor and returns Z_NEED_DICT; otherwise it sets
+ strm->adler to the adler32 checksum of all output produced so far (that is,
+ total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described
+ below. At the end of the stream, inflate() checks that its computed adler32
+ checksum is equal to that saved by the compressor and returns Z_STREAM_END
+ only if the checksum is correct.
+
+ inflate() will decompress and check either zlib-wrapped or gzip-wrapped
+ deflate data. The header type is detected automatically. Any information
+ contained in the gzip header is not retained, so applications that need that
+ information should instead use raw inflate, see inflateInit2() below, or
+ inflateBack() and perform their own processing of the gzip header and
+ trailer.
+
+ inflate() returns Z_OK if some progress has been made (more input processed
+ or more output produced), Z_STREAM_END if the end of the compressed data has
+ been reached and all uncompressed output has been produced, Z_NEED_DICT if a
+ preset dictionary is needed at this point, Z_DATA_ERROR if the input data was
+ corrupted (input stream not conforming to the zlib format or incorrect check
+ value), Z_STREAM_ERROR if the stream structure was inconsistent (for example
+ if next_in or next_out was NULL), Z_MEM_ERROR if there was not enough memory,
+ Z_BUF_ERROR if no progress is possible or if there was not enough room in the
+ output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and
+ inflate() can be called again with more input and more output space to
+ continue decompressing. If Z_DATA_ERROR is returned, the application may then
+ call inflateSync() to look for a good compression block if a partial recovery
+ of the data is desired.
+*/
+
+
+ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
+/*
+ All dynamically allocated data structures for this stream are freed.
+ This function discards any unprocessed input and does not flush any
+ pending output.
+
+ inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state
+ was inconsistent. In the error case, msg may be set but then points to a
+ static string (which must not be deallocated).
+*/
+
+ /* Advanced functions */
+
+/*
+ The following functions are needed only in some special applications.
+*/
+
+/*
+ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
+ int level,
+ int method,
+ int windowBits,
+ int memLevel,
+ int strategy));
+
+ This is another version of deflateInit with more compression options. The
+ fields next_in, zalloc, zfree and opaque must be initialized before by
+ the caller.
+
+ The method parameter is the compression method. It must be Z_DEFLATED in
+ this version of the library.
+
+ The windowBits parameter is the base two logarithm of the window size
+ (the size of the history buffer). It should be in the range 8..15 for this
+ version of the library. Larger values of this parameter result in better
+ compression at the expense of memory usage. The default value is 15 if
+ deflateInit is used instead.
+
+ windowBits can also be -8..-15 for raw deflate. In this case, -windowBits
+ determines the window size. deflate() will then generate raw deflate data
+ with no zlib header or trailer, and will not compute an adler32 check value.
+
+ windowBits can also be greater than 15 for optional gzip encoding. Add
+ 16 to windowBits to write a simple gzip header and trailer around the
+ compressed data instead of a zlib wrapper. The gzip header will have no
+ file name, no extra data, no comment, no modification time (set to zero),
+ no header crc, and the operating system will be set to 255 (unknown). If a
+ gzip stream is being written, strm->adler is a crc32 instead of an adler32.
+
+ The memLevel parameter specifies how much memory should be allocated
+ for the internal compression state. memLevel=1 uses minimum memory but
+ is slow and reduces compression ratio; memLevel=9 uses maximum memory
+ for optimal speed. The default value is 8. See zconf.h for total memory
+ usage as a function of windowBits and memLevel.
+
+ The strategy parameter is used to tune the compression algorithm. Use the
+ value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
+ filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no
+ string match), or Z_RLE to limit match distances to one (run-length
+ encoding). Filtered data consists mostly of small values with a somewhat
+ random distribution. In this case, the compression algorithm is tuned to
+ compress them better. The effect of Z_FILTERED is to force more Huffman
+ coding and less string matching; it is somewhat intermediate between
+ Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as
+ Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy
+ parameter only affects the compression ratio but not the correctness of the
+ compressed output even if it is not set appropriately. Z_FIXED prevents the
+ use of dynamic Huffman codes, allowing for a simpler decoder for special
+ applications.
+
+ deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_STREAM_ERROR if a parameter is invalid (such as an invalid
+ method). msg is set to null if there is no error message. deflateInit2 does
+ not perform any compression: this will be done by deflate().
+*/
+
+ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
+ const Bytef *dictionary,
+ uInt dictLength));
+/*
+ Initializes the compression dictionary from the given byte sequence
+ without producing any compressed output. This function must be called
+ immediately after deflateInit, deflateInit2 or deflateReset, before any
+ call of deflate. The compressor and decompressor must use exactly the same
+ dictionary (see inflateSetDictionary).
+
+ The dictionary should consist of strings (byte sequences) that are likely
+ to be encountered later in the data to be compressed, with the most commonly
+ used strings preferably put towards the end of the dictionary. Using a
+ dictionary is most useful when the data to be compressed is short and can be
+ predicted with good accuracy; the data can then be compressed better than
+ with the default empty dictionary.
+
+ Depending on the size of the compression data structures selected by
+ deflateInit or deflateInit2, a part of the dictionary may in effect be
+ discarded, for example if the dictionary is larger than the window size in
+ deflate or deflate2. Thus the strings most likely to be useful should be
+ put at the end of the dictionary, not at the front. In addition, the
+ current implementation of deflate will use at most the window size minus
+ 262 bytes of the provided dictionary.
+
+ Upon return of this function, strm->adler is set to the adler32 value
+ of the dictionary; the decompressor may later use this value to determine
+ which dictionary has been used by the compressor. (The adler32 value
+ applies to the whole dictionary even if only a subset of the dictionary is
+ actually used by the compressor.) If a raw deflate was requested, then the
+ adler32 value is not computed and strm->adler is not set.
+
+ deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a
+ parameter is invalid (such as NULL dictionary) or the stream state is
+ inconsistent (for example if deflate has already been called for this stream
+ or if the compression method is bsort). deflateSetDictionary does not
+ perform any compression: this will be done by deflate().
+*/
+
+ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
+ z_streamp source));
+/*
+ Sets the destination stream as a complete copy of the source stream.
+
+ This function can be useful when several compression strategies will be
+ tried, for example when there are several ways of pre-processing the input
+ data with a filter. The streams that will be discarded should then be freed
+ by calling deflateEnd. Note that deflateCopy duplicates the internal
+ compression state which can be quite large, so this strategy is slow and
+ can consume lots of memory.
+
+ deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
+ (such as zalloc being NULL). msg is left unchanged in both source and
+ destination.
+*/
+
+ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
+/*
+ This function is equivalent to deflateEnd followed by deflateInit,
+ but does not free and reallocate all the internal compression state.
+ The stream will keep the same compression level and any other attributes
+ that may have been set by deflateInit2.
+
+ deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent (such as zalloc or state being NULL).
+*/
+
+ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
+ int level,
+ int strategy));
+/*
+ Dynamically update the compression level and compression strategy. The
+ interpretation of level and strategy is as in deflateInit2. This can be
+ used to switch between compression and straight copy of the input data, or
+ to switch to a different kind of input data requiring a different
+ strategy. If the compression level is changed, the input available so far
+ is compressed with the old level (and may be flushed); the new level will
+ take effect only at the next call of deflate().
+
+ Before the call of deflateParams, the stream state must be set as for
+ a call of deflate(), since the currently available input may have to
+ be compressed and flushed. In particular, strm->avail_out must be non-zero.
+
+ deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source
+ stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR
+ if strm->avail_out was zero.
+*/
+
+ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
+ int good_length,
+ int max_lazy,
+ int nice_length,
+ int max_chain));
+/*
+ Fine tune deflate's internal compression parameters. This should only be
+ used by someone who understands the algorithm used by zlib's deflate for
+ searching for the best matching string, and even then only by the most
+ fanatic optimizer trying to squeeze out the last compressed bit for their
+ specific input data. Read the deflate.c source code for the meaning of the
+ max_lazy, good_length, nice_length, and max_chain parameters.
+
+ deflateTune() can be called after deflateInit() or deflateInit2(), and
+ returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream.
+ */
+
+ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
+ uLong sourceLen));
+/*
+ deflateBound() returns an upper bound on the compressed size after
+ deflation of sourceLen bytes. It must be called after deflateInit()
+ or deflateInit2(). This would be used to allocate an output buffer
+ for deflation in a single pass, and so would be called before deflate().
+*/
+
+ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
+ int bits,
+ int value));
+/*
+ deflatePrime() inserts bits in the deflate output stream. The intent
+ is that this function is used to start off the deflate output with the
+ bits leftover from a previous deflate stream when appending to it. As such,
+ this function can only be used for raw deflate, and must be used before the
+ first deflate() call after a deflateInit2() or deflateReset(). bits must be
+ less than or equal to 16, and that many of the least significant bits of
+ value will be inserted in the output.
+
+ deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent.
+*/
+
+ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
+ gz_headerp head));
+/*
+ deflateSetHeader() provides gzip header information for when a gzip
+ stream is requested by deflateInit2(). deflateSetHeader() may be called
+ after deflateInit2() or deflateReset() and before the first call of
+ deflate(). The text, time, os, extra field, name, and comment information
+ in the provided gz_header structure are written to the gzip header (xflag is
+ ignored -- the extra flags are set according to the compression level). The
+ caller must assure that, if not Z_NULL, name and comment are terminated with
+ a zero byte, and that if extra is not Z_NULL, that extra_len bytes are
+ available there. If hcrc is true, a gzip header crc is included. Note that
+ the current versions of the command-line version of gzip (up through version
+ 1.3.x) do not support header crc's, and will report that it is a "multi-part
+ gzip file" and give up.
+
+ If deflateSetHeader is not used, the default gzip header has text false,
+ the time set to zero, and os set to 255, with no extra, name, or comment
+ fields. The gzip header is returned to the default state by deflateReset().
+
+ deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent.
+*/
+
+/*
+ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
+ int windowBits));
+
+ This is another version of inflateInit with an extra parameter. The
+ fields next_in, avail_in, zalloc, zfree and opaque must be initialized
+ before by the caller.
+
+ The windowBits parameter is the base two logarithm of the maximum window
+ size (the size of the history buffer). It should be in the range 8..15 for
+ this version of the library. The default value is 15 if inflateInit is used
+ instead. windowBits must be greater than or equal to the windowBits value
+ provided to deflateInit2() while compressing, or it must be equal to 15 if
+ deflateInit2() was not used. If a compressed stream with a larger window
+ size is given as input, inflate() will return with the error code
+ Z_DATA_ERROR instead of trying to allocate a larger window.
+
+ windowBits can also be -8..-15 for raw inflate. In this case, -windowBits
+ determines the window size. inflate() will then process raw deflate data,
+ not looking for a zlib or gzip header, not generating a check value, and not
+ looking for any check values for comparison at the end of the stream. This
+ is for use with other formats that use the deflate compressed data format
+ such as zip. Those formats provide their own check values. If a custom
+ format is developed using the raw deflate format for compressed data, it is
+ recommended that a check value such as an adler32 or a crc32 be applied to
+ the uncompressed data as is done in the zlib, gzip, and zip formats. For
+ most applications, the zlib format should be used as is. Note that comments
+ above on the use in deflateInit2() applies to the magnitude of windowBits.
+
+ windowBits can also be greater than 15 for optional gzip decoding. Add
+ 32 to windowBits to enable zlib and gzip decoding with automatic header
+ detection, or add 16 to decode only the gzip format (the zlib format will
+ return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is
+ a crc32 instead of an adler32.
+
+ inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_STREAM_ERROR if a parameter is invalid (such as a null strm). msg
+ is set to null if there is no error message. inflateInit2 does not perform
+ any decompression apart from reading the zlib header if present: this will
+ be done by inflate(). (So next_in and avail_in may be modified, but next_out
+ and avail_out are unchanged.)
+*/
+
+ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
+ const Bytef *dictionary,
+ uInt dictLength));
+/*
+ Initializes the decompression dictionary from the given uncompressed byte
+ sequence. This function must be called immediately after a call of inflate,
+ if that call returned Z_NEED_DICT. The dictionary chosen by the compressor
+ can be determined from the adler32 value returned by that call of inflate.
+ The compressor and decompressor must use exactly the same dictionary (see
+ deflateSetDictionary). For raw inflate, this function can be called
+ immediately after inflateInit2() or inflateReset() and before any call of
+ inflate() to set the dictionary. The application must insure that the
+ dictionary that was used for compression is provided.
+
+ inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a
+ parameter is invalid (such as NULL dictionary) or the stream state is
+ inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the
+ expected one (incorrect adler32 value). inflateSetDictionary does not
+ perform any decompression: this will be done by subsequent calls of
+ inflate().
+*/
+
+ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
+/*
+ Skips invalid compressed data until a full flush point (see above the
+ description of deflate with Z_FULL_FLUSH) can be found, or until all
+ available input is skipped. No output is provided.
+
+ inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR
+ if no more input was provided, Z_DATA_ERROR if no flush point has been found,
+ or Z_STREAM_ERROR if the stream structure was inconsistent. In the success
+ case, the application may save the current current value of total_in which
+ indicates where valid compressed data was found. In the error case, the
+ application may repeatedly call inflateSync, providing more input each time,
+ until success or end of the input data.
+*/
+
+ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
+ z_streamp source));
+/*
+ Sets the destination stream as a complete copy of the source stream.
+
+ This function can be useful when randomly accessing a large stream. The
+ first pass through the stream can periodically record the inflate state,
+ allowing restarting inflate at those points when randomly accessing the
+ stream.
+
+ inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_STREAM_ERROR if the source stream state was inconsistent
+ (such as zalloc being NULL). msg is left unchanged in both source and
+ destination.
+*/
+
+ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
+/*
+ This function is equivalent to inflateEnd followed by inflateInit,
+ but does not free and reallocate all the internal decompression state.
+ The stream will keep attributes that may have been set by inflateInit2.
+
+ inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent (such as zalloc or state being NULL).
+*/
+
+ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
+ int bits,
+ int value));
+/*
+ This function inserts bits in the inflate input stream. The intent is
+ that this function is used to start inflating at a bit position in the
+ middle of a byte. The provided bits will be used before any bytes are used
+ from next_in. This function should only be used with raw inflate, and
+ should be used before the first inflate() call after inflateInit2() or
+ inflateReset(). bits must be less than or equal to 16, and that many of the
+ least significant bits of value will be inserted in the input.
+
+ inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent.
+*/
+
+ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
+ gz_headerp head));
+/*
+ inflateGetHeader() requests that gzip header information be stored in the
+ provided gz_header structure. inflateGetHeader() may be called after
+ inflateInit2() or inflateReset(), and before the first call of inflate().
+ As inflate() processes the gzip stream, head->done is zero until the header
+ is completed, at which time head->done is set to one. If a zlib stream is
+ being decoded, then head->done is set to -1 to indicate that there will be
+ no gzip header information forthcoming. Note that Z_BLOCK can be used to
+ force inflate() to return immediately after header processing is complete
+ and before any actual data is decompressed.
+
+ The text, time, xflags, and os fields are filled in with the gzip header
+ contents. hcrc is set to true if there is a header CRC. (The header CRC
+ was valid if done is set to one.) If extra is not Z_NULL, then extra_max
+ contains the maximum number of bytes to write to extra. Once done is true,
+ extra_len contains the actual extra field length, and extra contains the
+ extra field, or that field truncated if extra_max is less than extra_len.
+ If name is not Z_NULL, then up to name_max characters are written there,
+ terminated with a zero unless the length is greater than name_max. If
+ comment is not Z_NULL, then up to comm_max characters are written there,
+ terminated with a zero unless the length is greater than comm_max. When
+ any of extra, name, or comment are not Z_NULL and the respective field is
+ not present in the header, then that field is set to Z_NULL to signal its
+ absence. This allows the use of deflateSetHeader() with the returned
+ structure to duplicate the header. However if those fields are set to
+ allocated memory, then the application will need to save those pointers
+ elsewhere so that they can be eventually freed.
+
+ If inflateGetHeader is not used, then the header information is simply
+ discarded. The header is always checked for validity, including the header
+ CRC if present. inflateReset() will reset the process to discard the header
+ information. The application would need to call inflateGetHeader() again to
+ retrieve the header from the next gzip stream.
+
+ inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source
+ stream state was inconsistent.
+*/
+
+/*
+ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
+ unsigned char FAR *window));
+
+ Initialize the internal stream state for decompression using inflateBack()
+ calls. The fields zalloc, zfree and opaque in strm must be initialized
+ before the call. If zalloc and zfree are Z_NULL, then the default library-
+ derived memory allocation routines are used. windowBits is the base two
+ logarithm of the window size, in the range 8..15. window is a caller
+ supplied buffer of that size. Except for special applications where it is
+ assured that deflate was used with small window sizes, windowBits must be 15
+ and a 32K byte window must be supplied to be able to decompress general
+ deflate streams.
+
+ See inflateBack() for the usage of these routines.
+
+ inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of
+ the parameters are invalid, Z_MEM_ERROR if the internal state could not
+ be allocated, or Z_VERSION_ERROR if the version of the library does not
+ match the version of the header file.
+*/
+
+typedef unsigned (*in_func) OF((void FAR *,
+ z_const unsigned char FAR * FAR *));
+typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
+
+ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
+ in_func in, void FAR *in_desc,
+ out_func out, void FAR *out_desc));
+/*
+ inflateBack() does a raw inflate with a single call using a call-back
+ interface for input and output. This is more efficient than inflate() for
+ file i/o applications in that it avoids copying between the output and the
+ sliding window by simply making the window itself the output buffer. This
+ function trusts the application to not change the output buffer passed by
+ the output function, at least until inflateBack() returns.
+
+ inflateBackInit() must be called first to allocate the internal state
+ and to initialize the state with the user-provided window buffer.
+ inflateBack() may then be used multiple times to inflate a complete, raw
+ deflate stream with each call. inflateBackEnd() is then called to free
+ the allocated state.
+
+ A raw deflate stream is one with no zlib or gzip header or trailer.
+ This routine would normally be used in a utility that reads zip or gzip
+ files and writes out uncompressed files. The utility would decode the
+ header and process the trailer on its own, hence this routine expects
+ only the raw deflate stream to decompress. This is different from the
+ normal behavior of inflate(), which expects either a zlib or gzip header and
+ trailer around the deflate stream.
+
+ inflateBack() uses two subroutines supplied by the caller that are then
+ called by inflateBack() for input and output. inflateBack() calls those
+ routines until it reads a complete deflate stream and writes out all of the
+ uncompressed data, or until it encounters an error. The function's
+ parameters and return types are defined above in the in_func and out_func
+ typedefs. inflateBack() will call in(in_desc, &buf) which should return the
+ number of bytes of provided input, and a pointer to that input in buf. If
+ there is no input available, in() must return zero--buf is ignored in that
+ case--and inflateBack() will return a buffer error. inflateBack() will call
+ out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out()
+ should return zero on success, or non-zero on failure. If out() returns
+ non-zero, inflateBack() will return with an error. Neither in() nor out()
+ are permitted to change the contents of the window provided to
+ inflateBackInit(), which is also the buffer that out() uses to write from.
+ The length written by out() will be at most the window size. Any non-zero
+ amount of input may be provided by in().
+
+ For convenience, inflateBack() can be provided input on the first call by
+ setting strm->next_in and strm->avail_in. If that input is exhausted, then
+ in() will be called. Therefore strm->next_in must be initialized before
+ calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called
+ immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in
+ must also be initialized, and then if strm->avail_in is not zero, input will
+ initially be taken from strm->next_in[0 .. strm->avail_in - 1].
+
+ The in_desc and out_desc parameters of inflateBack() is passed as the
+ first parameter of in() and out() respectively when they are called. These
+ descriptors can be optionally used to pass any information that the caller-
+ supplied in() and out() functions need to do their job.
+
+ On return, inflateBack() will set strm->next_in and strm->avail_in to
+ pass back any unused input that was provided by the last in() call. The
+ return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR
+ if in() or out() returned an error, Z_DATA_ERROR if there was a format
+ error in the deflate stream (in which case strm->msg is set to indicate the
+ nature of the error), or Z_STREAM_ERROR if the stream was not properly
+ initialized. In the case of Z_BUF_ERROR, an input or output error can be
+ distinguished using strm->next_in which will be Z_NULL only if in() returned
+ an error. If strm->next is not Z_NULL, then the Z_BUF_ERROR was due to
+ out() returning non-zero. (in() will always be called before out(), so
+ strm->next_in is assured to be defined if out() returns non-zero.) Note
+ that inflateBack() cannot return Z_OK.
+*/
+
+ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
+/*
+ All memory allocated by inflateBackInit() is freed.
+
+ inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream
+ state was inconsistent.
+*/
+
+ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
+/* Return flags indicating compile-time options.
+
+ Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other:
+ 1.0: size of uInt
+ 3.2: size of uLong
+ 5.4: size of voidpf (pointer)
+ 7.6: size of z_off_t
+
+ Compiler, assembler, and debug options:
+ 8: DEBUG
+ 9: ASMV or ASMINF -- use ASM code
+ 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention
+ 11: 0 (reserved)
+
+ One-time table building (smaller code, but not thread-safe if true):
+ 12: BUILDFIXED -- build static block decoding tables when needed
+ 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed
+ 14,15: 0 (reserved)
+
+ Library content (indicates missing functionality):
+ 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking
+ deflate code when not needed)
+ 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect
+ and decode gzip streams (to avoid linking crc code)
+ 18-19: 0 (reserved)
+
+ Operation variations (changes in library functionality):
+ 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate
+ 21: FASTEST -- deflate algorithm with only one, lowest compression level
+ 22,23: 0 (reserved)
+
+ The sprintf variant used by gzprintf (zero is best):
+ 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format
+ 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure!
+ 26: 0 = returns value, 1 = void -- 1 means inferred string length returned
+
+ Remainder:
+ 27-31: 0 (reserved)
+ */
+
+
+ /* utility functions */
+
+/*
+ The following utility functions are implemented on top of the
+ basic stream-oriented functions. To simplify the interface, some
+ default options are assumed (compression level and memory usage,
+ standard memory allocation functions). The source code of these
+ utility functions can easily be modified if you need special options.
+*/
+
+ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
+ const Bytef *source, uLong sourceLen));
+/*
+ Compresses the source buffer into the destination buffer. sourceLen is
+ the byte length of the source buffer. Upon entry, destLen is the total
+ size of the destination buffer, which must be at least the value returned
+ by compressBound(sourceLen). Upon exit, destLen is the actual size of the
+ compressed buffer.
+ This function can be used to compress a whole file at once if the
+ input file is mmap'ed.
+ compress returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_BUF_ERROR if there was not enough room in the output
+ buffer.
+*/
+
+ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
+ const Bytef *source, uLong sourceLen,
+ int level));
+/*
+ Compresses the source buffer into the destination buffer. The level
+ parameter has the same meaning as in deflateInit. sourceLen is the byte
+ length of the source buffer. Upon entry, destLen is the total size of the
+ destination buffer, which must be at least the value returned by
+ compressBound(sourceLen). Upon exit, destLen is the actual size of the
+ compressed buffer.
+
+ compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
+ memory, Z_BUF_ERROR if there was not enough room in the output buffer,
+ Z_STREAM_ERROR if the level parameter is invalid.
+*/
+
+ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
+/*
+ compressBound() returns an upper bound on the compressed size after
+ compress() or compress2() on sourceLen bytes. It would be used before
+ a compress() or compress2() call to allocate the destination buffer.
+*/
+
+ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
+ const Bytef *source, uLong sourceLen));
+/*
+ Decompresses the source buffer into the destination buffer. sourceLen is
+ the byte length of the source buffer. Upon entry, destLen is the total
+ size of the destination buffer, which must be large enough to hold the
+ entire uncompressed data. (The size of the uncompressed data must have
+ been saved previously by the compressor and transmitted to the decompressor
+ by some mechanism outside the scope of this compression library.)
+ Upon exit, destLen is the actual size of the compressed buffer.
+ This function can be used to decompress a whole file at once if the
+ input file is mmap'ed.
+
+ uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
+ enough memory, Z_BUF_ERROR if there was not enough room in the output
+ buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete.
+*/
+
+
+typedef voidp gzFile;
+
+ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
+/*
+ Opens a gzip (.gz) file for reading or writing. The mode parameter
+ is as in fopen ("rb" or "wb") but can also include a compression level
+ ("wb9") or a strategy: 'f' for filtered data as in "wb6f", 'h' for
+ Huffman only compression as in "wb1h", or 'R' for run-length encoding
+ as in "wb1R". (See the description of deflateInit2 for more information
+ about the strategy parameter.)
+
+ gzopen can be used to read a file which is not in gzip format; in this
+ case gzread will directly read from the file without decompression.
+
+ gzopen returns NULL if the file could not be opened or if there was
+ insufficient memory to allocate the (de)compression state; errno
+ can be checked to distinguish the two cases (if errno is zero, the
+ zlib error is Z_MEM_ERROR). */
+
+ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
+/*
+ gzdopen() associates a gzFile with the file descriptor fd. File
+ descriptors are obtained from calls like open, dup, creat, pipe or
+ fileno (in the file has been previously opened with fopen).
+ The mode parameter is as in gzopen.
+ The next call of gzclose on the returned gzFile will also close the
+ file descriptor fd, just like fclose(fdopen(fd), mode) closes the file
+ descriptor fd. If you want to keep fd open, use gzdopen(dup(fd), mode).
+ gzdopen returns NULL if there was insufficient memory to allocate
+ the (de)compression state.
+*/
+
+ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
+/*
+ Dynamically update the compression level or strategy. See the description
+ of deflateInit2 for the meaning of these parameters.
+ gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not
+ opened for writing.
+*/
+
+ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
+/*
+ Reads the given number of uncompressed bytes from the compressed file.
+ If the input file was not in gzip format, gzread copies the given number
+ of bytes into the buffer.
+ gzread returns the number of uncompressed bytes actually read (0 for
+ end of file, -1 for error). */
+
+ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
+ voidpc buf, unsigned len));
+/*
+ Writes the given number of uncompressed bytes into the compressed file.
+ gzwrite returns the number of uncompressed bytes actually written
+ (0 in case of error).
+*/
+
+ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
+/*
+ Converts, formats, and writes the args to the compressed file under
+ control of the format string, as in fprintf. gzprintf returns the number of
+ uncompressed bytes actually written (0 in case of error). The number of
+ uncompressed bytes written is limited to 4095. The caller should assure that
+ this limit is not exceeded. If it is exceeded, then gzprintf() will return
+ return an error (0) with nothing written. In this case, there may also be a
+ buffer overflow with unpredictable consequences, which is possible only if
+ zlib was compiled with the insecure functions sprintf() or vsprintf()
+ because the secure snprintf() or vsnprintf() functions were not available.
+*/
+
+ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
+/*
+ Writes the given null-terminated string to the compressed file, excluding
+ the terminating null character.
+ gzputs returns the number of characters written, or -1 in case of error.
+*/
+
+ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
+/*
+ Reads bytes from the compressed file until len-1 characters are read, or
+ a newline character is read and transferred to buf, or an end-of-file
+ condition is encountered. The string is then terminated with a null
+ character.
+ gzgets returns buf, or Z_NULL in case of error.
+*/
+
+ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
+/*
+ Writes c, converted to an unsigned char, into the compressed file.
+ gzputc returns the value that was written, or -1 in case of error.
+*/
+
+ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
+/*
+ Reads one byte from the compressed file. gzgetc returns this byte
+ or -1 in case of end of file or error.
+*/
+
+ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
+/*
+ Push one character back onto the stream to be read again later.
+ Only one character of push-back is allowed. gzungetc() returns the
+ character pushed, or -1 on failure. gzungetc() will fail if a
+ character has been pushed but not read yet, or if c is -1. The pushed
+ character will be discarded if the stream is repositioned with gzseek()
+ or gzrewind().
+*/
+
+ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
+/*
+ Flushes all pending output into the compressed file. The parameter
+ flush is as in the deflate() function. The return value is the zlib
+ error number (see function gzerror below). gzflush returns Z_OK if
+ the flush parameter is Z_FINISH and all output could be flushed.
+ gzflush should be called only when strictly necessary because it can
+ degrade compression.
+*/
+
+ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
+ z_off_t offset, int whence));
+/*
+ Sets the starting position for the next gzread or gzwrite on the
+ given compressed file. The offset represents a number of bytes in the
+ uncompressed data stream. The whence parameter is defined as in lseek(2);
+ the value SEEK_END is not supported.
+ If the file is opened for reading, this function is emulated but can be
+ extremely slow. If the file is opened for writing, only forward seeks are
+ supported; gzseek then compresses a sequence of zeroes up to the new
+ starting position.
+
+ gzseek returns the resulting offset location as measured in bytes from
+ the beginning of the uncompressed stream, or -1 in case of error, in
+ particular if the file is opened for writing and the new starting position
+ would be before the current position.
+*/
+
+ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
+/*
+ Rewinds the given file. This function is supported only for reading.
+
+ gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
+*/
+
+ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
+/*
+ Returns the starting position for the next gzread or gzwrite on the
+ given compressed file. This position represents a number of bytes in the
+ uncompressed data stream.
+
+ gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR)
+*/
+
+ZEXTERN int ZEXPORT gzeof OF((gzFile file));
+/*
+ Returns 1 when EOF has previously been detected reading the given
+ input stream, otherwise zero.
+*/
+
+ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
+/*
+ Returns 1 if file is being read directly without decompression, otherwise
+ zero.
+*/
+
+ZEXTERN int ZEXPORT gzclose OF((gzFile file));
+/*
+ Flushes all pending output if necessary, closes the compressed file
+ and deallocates all the (de)compression state. The return value is the zlib
+ error number (see function gzerror below).
+*/
+
+ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
+/*
+ Returns the error message for the last error which occurred on the
+ given compressed file. errnum is set to zlib error number. If an
+ error occurred in the file system and not in the compression library,
+ errnum is set to Z_ERRNO and the application may consult errno
+ to get the exact error code.
+*/
+
+ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
+/*
+ Clears the error and end-of-file flags for file. This is analogous to the
+ clearerr() function in stdio. This is useful for continuing to read a gzip
+ file that is being written concurrently.
+*/
+
+ /* checksum functions */
+
+/*
+ These functions are not related to compression but are exported
+ anyway because they might be useful in applications using the
+ compression library.
+*/
+
+ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
+/*
+ Update a running Adler-32 checksum with the bytes buf[0..len-1] and
+ return the updated checksum. If buf is NULL, this function returns
+ the required initial value for the checksum.
+ An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
+ much faster. Usage example:
+
+ uLong adler = adler32(0L, Z_NULL, 0);
+
+ while (read_buffer(buffer, length) != EOF) {
+ adler = adler32(adler, buffer, length);
+ }
+ if (adler != original_adler) error();
+*/
+
+ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
+ z_off_t len2));
+/*
+ Combine two Adler-32 checksums into one. For two sequences of bytes, seq1
+ and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for
+ each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of
+ seq1 and seq2 concatenated, requiring only adler1, adler2, and len2.
+*/
+
+ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
+/*
+ Update a running CRC-32 with the bytes buf[0..len-1] and return the
+ updated CRC-32. If buf is NULL, this function returns the required initial
+ value for the for the crc. Pre- and post-conditioning (one's complement) is
+ performed within this function so it shouldn't be done by the application.
+ Usage example:
+
+ uLong crc = crc32(0L, Z_NULL, 0);
+
+ while (read_buffer(buffer, length) != EOF) {
+ crc = crc32(crc, buffer, length);
+ }
+ if (crc != original_crc) error();
+*/
+
+ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
+
+/*
+ Combine two CRC-32 check values into one. For two sequences of bytes,
+ seq1 and seq2 with lengths len1 and len2, CRC-32 check values were
+ calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32
+ check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and
+ len2.
+*/
+
+
+ /* various hacks, don't look :) */
+
+/* deflateInit and inflateInit are macros to allow checking the zlib version
+ * and the compiler's view of z_stream:
+ */
+ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
+ const char *version, int stream_size));
+ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
+ const char *version, int stream_size));
+ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
+ int windowBits, int memLevel,
+ int strategy, const char *version,
+ int stream_size));
+ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
+ const char *version, int stream_size));
+ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
+ unsigned char FAR *window,
+ const char *version,
+ int stream_size));
+#define deflateInit(strm, level) \
+ deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
+#define inflateInit(strm) \
+ inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
+#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
+ deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
+ (strategy), ZLIB_VERSION, sizeof(z_stream))
+#define inflateInit2(strm, windowBits) \
+ inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
+#define inflateBackInit(strm, windowBits, window) \
+ inflateBackInit_((strm), (windowBits), (window), \
+ ZLIB_VERSION, sizeof(z_stream))
+
+
+#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
+ struct internal_state {int dummy;}; /* hack for buggy compilers */
+#endif
+
+ZEXTERN const char * ZEXPORT zError OF((int));
+ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
+ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* ZLIB_H */
diff --git a/lib/libz/zutil.c b/lib/libz/zutil.c
new file mode 100644
index 0000000..42813db
--- /dev/null
+++ b/lib/libz/zutil.c
@@ -0,0 +1,319 @@
+/* $OpenBSD: zutil.c,v 1.9 2015/08/21 23:30:59 deraadt Exp $ */
+/* zutil.c -- target dependent utility functions for the compression library
+ * Copyright (C) 1995-2005 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+
+#include "zutil.h"
+
+#ifndef NO_DUMMY_DECL
+struct internal_state {int dummy;}; /* for buggy compilers */
+#endif
+
+const char * const z_errmsg[10] = {
+"need dictionary", /* Z_NEED_DICT 2 */
+"stream end", /* Z_STREAM_END 1 */
+"", /* Z_OK 0 */
+"file error", /* Z_ERRNO (-1) */
+"stream error", /* Z_STREAM_ERROR (-2) */
+"data error", /* Z_DATA_ERROR (-3) */
+"insufficient memory", /* Z_MEM_ERROR (-4) */
+"buffer error", /* Z_BUF_ERROR (-5) */
+"incompatible version",/* Z_VERSION_ERROR (-6) */
+""};
+
+
+const char * ZEXPORT zlibVersion()
+{
+ return ZLIB_VERSION;
+}
+
+uLong ZEXPORT zlibCompileFlags()
+{
+ uLong flags;
+
+ flags = 0;
+ switch (sizeof(uInt)) {
+ case 2: break;
+ case 4: flags += 1; break;
+ case 8: flags += 2; break;
+ default: flags += 3;
+ }
+ switch (sizeof(uLong)) {
+ case 2: break;
+ case 4: flags += 1 << 2; break;
+ case 8: flags += 2 << 2; break;
+ default: flags += 3 << 2;
+ }
+ switch (sizeof(voidpf)) {
+ case 2: break;
+ case 4: flags += 1 << 4; break;
+ case 8: flags += 2 << 4; break;
+ default: flags += 3 << 4;
+ }
+ switch (sizeof(z_off_t)) {
+ case 2: break;
+ case 4: flags += 1 << 6; break;
+ case 8: flags += 2 << 6; break;
+ default: flags += 3 << 6;
+ }
+#ifdef DEBUG
+ flags += 1 << 8;
+#endif
+#if defined(ASMV) || defined(ASMINF)
+ flags += 1 << 9;
+#endif
+#ifdef ZLIB_WINAPI
+ flags += 1 << 10;
+#endif
+#ifdef BUILDFIXED
+ flags += 1 << 12;
+#endif
+#ifdef DYNAMIC_CRC_TABLE
+ flags += 1 << 13;
+#endif
+#ifdef NO_GZCOMPRESS
+ flags += 1L << 16;
+#endif
+#ifdef NO_GZIP
+ flags += 1L << 17;
+#endif
+#ifdef PKZIP_BUG_WORKAROUND
+ flags += 1L << 20;
+#endif
+#ifdef FASTEST
+ flags += 1L << 21;
+#endif
+#ifdef STDC
+# ifdef NO_vsnprintf
+ flags += 1L << 25;
+# ifdef HAS_vsprintf_void
+ flags += 1L << 26;
+# endif
+# else
+# ifdef HAS_vsnprintf_void
+ flags += 1L << 26;
+# endif
+# endif
+#else
+ flags += 1L << 24;
+# ifdef NO_snprintf
+ flags += 1L << 25;
+# ifdef HAS_sprintf_void
+ flags += 1L << 26;
+# endif
+# else
+# ifdef HAS_snprintf_void
+ flags += 1L << 26;
+# endif
+# endif
+#endif
+ return flags;
+}
+
+#ifdef DEBUG
+
+# ifndef verbose
+# define verbose 0
+# endif
+int z_verbose = verbose;
+
+void z_error (m)
+ char *m;
+{
+ fprintf(stderr, "%s\n", m);
+ exit(1);
+}
+#endif
+
+/* exported to allow conversion of error code to string for compress() and
+ * uncompress()
+ */
+const char * ZEXPORT zError(err)
+ int err;
+{
+ return ERR_MSG(err);
+}
+
+#if defined(_WIN32_WCE)
+ /* The Microsoft C Run-Time Library for Windows CE doesn't have
+ * errno. We define it as a global variable to simplify porting.
+ * Its value is always 0 and should not be used.
+ */
+ int errno = 0;
+#endif
+
+#ifndef HAVE_MEMCPY
+
+void zmemcpy(dest, source, len)
+ Bytef* dest;
+ const Bytef* source;
+ uInt len;
+{
+ if (len == 0) return;
+ do {
+ *dest++ = *source++; /* ??? to be unrolled */
+ } while (--len != 0);
+}
+
+int zmemcmp(s1, s2, len)
+ const Bytef* s1;
+ const Bytef* s2;
+ uInt len;
+{
+ uInt j;
+
+ for (j = 0; j < len; j++) {
+ if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
+ }
+ return 0;
+}
+
+void zmemzero(dest, len)
+ Bytef* dest;
+ uInt len;
+{
+ if (len == 0) return;
+ do {
+ *dest++ = 0; /* ??? to be unrolled */
+ } while (--len != 0);
+}
+#endif
+
+
+#ifdef SYS16BIT
+
+#ifdef __TURBOC__
+/* Turbo C in 16-bit mode */
+
+# define MY_ZCALLOC
+
+/* Turbo C malloc() does not allow dynamic allocation of 64K bytes
+ * and farmalloc(64K) returns a pointer with an offset of 8, so we
+ * must fix the pointer. Warning: the pointer must be put back to its
+ * original form in order to free it, use zcfree().
+ */
+
+#define MAX_PTR 10
+/* 10*64K = 640K */
+
+local int next_ptr = 0;
+
+typedef struct ptr_table_s {
+ voidpf org_ptr;
+ voidpf new_ptr;
+} ptr_table;
+
+local ptr_table table[MAX_PTR];
+/* This table is used to remember the original form of pointers
+ * to large buffers (64K). Such pointers are normalized with a zero offset.
+ * Since MSDOS is not a preemptive multitasking OS, this table is not
+ * protected from concurrent access. This hack doesn't work anyway on
+ * a protected system like OS/2. Use Microsoft C instead.
+ */
+
+voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
+{
+ voidpf buf = opaque; /* just to make some compilers happy */
+ ulg bsize = (ulg)items*size;
+
+ /* If we allocate less than 65520 bytes, we assume that farmalloc
+ * will return a usable pointer which doesn't have to be normalized.
+ */
+ if (bsize < 65520L) {
+ buf = farmalloc(bsize);
+ if (*(ush*)&buf != 0) return buf;
+ } else {
+ buf = farmalloc(bsize + 16L);
+ }
+ if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
+ table[next_ptr].org_ptr = buf;
+
+ /* Normalize the pointer to seg:0 */
+ *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
+ *(ush*)&buf = 0;
+ table[next_ptr++].new_ptr = buf;
+ return buf;
+}
+
+void zcfree (voidpf opaque, voidpf ptr)
+{
+ int n;
+ if (*(ush*)&ptr != 0) { /* object < 64K */
+ farfree(ptr);
+ return;
+ }
+ /* Find the original pointer */
+ for (n = 0; n < next_ptr; n++) {
+ if (ptr != table[n].new_ptr) continue;
+
+ farfree(table[n].org_ptr);
+ while (++n < next_ptr) {
+ table[n-1] = table[n];
+ }
+ next_ptr--;
+ return;
+ }
+ ptr = opaque; /* just to make some compilers happy */
+ Assert(0, "zcfree: ptr not found");
+}
+
+#endif /* __TURBOC__ */
+
+
+#ifdef M_I86
+/* Microsoft C in 16-bit mode */
+
+# define MY_ZCALLOC
+
+#if (!defined(_MSC_VER) || (_MSC_VER <= 600))
+# define _halloc halloc
+# define _hfree hfree
+#endif
+
+voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
+{
+ if (opaque) opaque = 0; /* to make compiler happy */
+ return _halloc((long)items, size);
+}
+
+void zcfree (voidpf opaque, voidpf ptr)
+{
+ if (opaque) opaque = 0; /* to make compiler happy */
+ _hfree(ptr);
+}
+
+#endif /* M_I86 */
+
+#endif /* SYS16BIT */
+
+
+#ifndef MY_ZCALLOC /* Any system without a special alloc function */
+
+#ifndef STDC
+extern voidp malloc OF((uInt size));
+extern voidp calloc OF((uInt items, uInt size));
+extern void free OF((voidpf ptr));
+#endif
+
+voidpf zcalloc (opaque, items, size)
+ voidpf opaque;
+ unsigned items;
+ unsigned size;
+{
+ if (opaque) items += size - size; /* make compiler happy */
+ if (items == 0 || size == 0)
+ return (NULL);
+ return reallocarray(NULL, items, size);
+}
+
+void zcfree (opaque, ptr)
+ voidpf opaque;
+ voidpf ptr;
+{
+ free(ptr);
+ if (opaque) return; /* make compiler happy */
+}
+
+#endif /* MY_ZCALLOC */
diff --git a/lib/libz/zutil.h b/lib/libz/zutil.h
new file mode 100644
index 0000000..5726e18
--- /dev/null
+++ b/lib/libz/zutil.h
@@ -0,0 +1,273 @@
+/* $OpenBSD: zutil.h,v 1.9 2005/07/20 15:56:42 millert Exp $ */
+/* zutil.h -- internal interface and configuration of the compression library
+ * Copyright (C) 1995-2005 Jean-loup Gailly.
+ * For conditions of distribution and use, see copyright notice in zlib.h
+ */
+
+/* WARNING: this file should *not* be used by applications. It is
+ part of the implementation of the compression library and is
+ subject to change. Applications should only use zlib.h.
+ */
+
+
+#ifndef ZUTIL_H
+#define ZUTIL_H
+
+#define ZLIB_INTERNAL
+#include "zlib.h"
+
+#ifdef _STANDALONE
+#include <stand.h>
+#else
+#ifdef STDC
+# ifndef _WIN32_WCE
+# include <stddef.h>
+# endif
+# include <string.h>
+# include <stdlib.h>
+#endif
+#ifdef NO_ERRNO_H
+# ifdef _WIN32_WCE
+ /* The Microsoft C Run-Time Library for Windows CE doesn't have
+ * errno. We define it as a global variable to simplify porting.
+ * Its value is always 0 and should not be used. We rename it to
+ * avoid conflict with other libraries that use the same workaround.
+ */
+# define errno z_errno
+# endif
+ extern int errno;
+#else
+# ifndef _WIN32_WCE
+# include <errno.h>
+# endif
+#endif
+#endif
+
+#ifndef local
+# define local static
+#endif
+/* compile with -Dlocal if your debugger can't find static symbols */
+
+typedef unsigned char uch;
+typedef uch FAR uchf;
+typedef unsigned short ush;
+typedef ush FAR ushf;
+typedef unsigned long ulg;
+
+extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
+/* (size given to avoid silly warnings with Visual C++) */
+
+#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
+
+#define ERR_RETURN(strm,err) \
+ return (strm->msg = (char*)ERR_MSG(err), (err))
+/* To be used only when the state is known to be valid */
+
+ /* common constants */
+
+#ifndef DEF_WBITS
+# define DEF_WBITS MAX_WBITS
+#endif
+/* default windowBits for decompression. MAX_WBITS is for compression only */
+
+#if MAX_MEM_LEVEL >= 8
+# define DEF_MEM_LEVEL 8
+#else
+# define DEF_MEM_LEVEL MAX_MEM_LEVEL
+#endif
+/* default memLevel */
+
+#define STORED_BLOCK 0
+#define STATIC_TREES 1
+#define DYN_TREES 2
+/* The three kinds of block type */
+
+#define MIN_MATCH 3
+#define MAX_MATCH 258
+/* The minimum and maximum match lengths */
+
+#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
+
+ /* target dependencies */
+
+#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
+# define OS_CODE 0x00
+# if defined(__TURBOC__) || defined(__BORLANDC__)
+# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
+ /* Allow compilation with ANSI keywords only enabled */
+ void _Cdecl farfree( void *block );
+ void *_Cdecl farmalloc( unsigned long nbytes );
+# else
+# include <alloc.h>
+# endif
+# else /* MSC or DJGPP */
+# include <malloc.h>
+# endif
+#endif
+
+#ifdef AMIGA
+# define OS_CODE 0x01
+#endif
+
+#if defined(VAXC) || defined(VMS)
+# define OS_CODE 0x02
+# define F_OPEN(name, mode) \
+ fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
+#endif
+
+#if defined(ATARI) || defined(atarist)
+# define OS_CODE 0x05
+#endif
+
+#ifdef OS2
+# define OS_CODE 0x06
+# ifdef M_I86
+ #include <malloc.h>
+# endif
+#endif
+
+#if defined(MACOS) || defined(TARGET_OS_MAC)
+# define OS_CODE 0x07
+# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
+# include <unix.h> /* for fdopen */
+# else
+# ifndef fdopen
+# define fdopen(fd,mode) NULL /* No fdopen() */
+# endif
+# endif
+#endif
+
+#ifdef TOPS20
+# define OS_CODE 0x0a
+#endif
+
+#ifdef WIN32
+# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
+# define OS_CODE 0x0b
+# endif
+#endif
+
+#ifdef __50SERIES /* Prime/PRIMOS */
+# define OS_CODE 0x0f
+#endif
+
+#if defined(_BEOS_) || defined(RISCOS)
+# define fdopen(fd,mode) NULL /* No fdopen() */
+#endif
+
+#if (defined(_MSC_VER) && (_MSC_VER > 600))
+# if defined(_WIN32_WCE)
+# define fdopen(fd,mode) NULL /* No fdopen() */
+# ifndef _PTRDIFF_T_DEFINED
+ typedef int ptrdiff_t;
+# define _PTRDIFF_T_DEFINED
+# endif
+# else
+# define fdopen(fd,type) _fdopen(fd,type)
+# endif
+#endif
+
+ /* common defaults */
+
+#ifndef OS_CODE
+# define OS_CODE 0x03 /* assume Unix */
+#endif
+
+#ifndef F_OPEN
+# define F_OPEN(name, mode) fopen((name), (mode))
+#endif
+
+ /* functions */
+
+#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
+# ifndef HAVE_VSNPRINTF
+# define HAVE_VSNPRINTF
+# endif
+#endif
+#if defined(__CYGWIN__)
+# ifndef HAVE_VSNPRINTF
+# define HAVE_VSNPRINTF
+# endif
+#endif
+#ifndef HAVE_VSNPRINTF
+# ifdef MSDOS
+ /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
+ but for now we just assume it doesn't. */
+# define NO_vsnprintf
+# endif
+# ifdef __TURBOC__
+# define NO_vsnprintf
+# endif
+# ifdef WIN32
+ /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
+# if !defined(vsnprintf) && !defined(NO_vsnprintf)
+# define vsnprintf _vsnprintf
+# endif
+# endif
+# ifdef __SASC
+# define NO_vsnprintf
+# endif
+#endif
+#ifdef VMS
+# define NO_vsnprintf
+#endif
+
+#if defined(pyr)
+# define NO_MEMCPY
+#endif
+#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
+ /* Use our own functions for small and medium model with MSC <= 5.0.
+ * You may have to use the same strategy for Borland C (untested).
+ * The __SC__ check is for Symantec.
+ */
+# define NO_MEMCPY
+#endif
+#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
+# define HAVE_MEMCPY
+#endif
+#ifdef HAVE_MEMCPY
+# ifdef SMALL_MEDIUM /* MSDOS small or medium model */
+# define zmemcpy _fmemcpy
+# define zmemcmp _fmemcmp
+# define zmemzero(dest, len) _fmemset(dest, 0, len)
+# else
+# define zmemcpy memcpy
+# define zmemcmp memcmp
+# define zmemzero(dest, len) memset(dest, 0, len)
+# endif
+#else
+ extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
+ extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
+ extern void zmemzero OF((Bytef* dest, uInt len));
+#endif
+
+/* Diagnostic functions */
+#ifdef DEBUG
+# include <stdio.h>
+ extern int z_verbose;
+ extern void z_error OF((char *m));
+# define Assert(cond,msg) {if(!(cond)) z_error(msg);}
+# define Trace(x) {if (z_verbose>=0) fprintf x ;}
+# define Tracev(x) {if (z_verbose>0) fprintf x ;}
+# define Tracevv(x) {if (z_verbose>1) fprintf x ;}
+# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
+# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
+#else
+# define Assert(cond,msg)
+# define Trace(x)
+# define Tracev(x)
+# define Tracevv(x)
+# define Tracec(c,x)
+# define Tracecv(c,x)
+#endif
+
+
+voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
+void zcfree OF((voidpf opaque, voidpf ptr));
+
+#define ZALLOC(strm, items, size) \
+ (*((strm)->zalloc))((strm)->opaque, (items), (size))
+#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
+#define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
+
+#endif /* ZUTIL_H */
diff --git a/patches/0001-fts-Avoid-d_namlen.patch b/patches/0001-fts-Avoid-d_namlen.patch
new file mode 100644
index 0000000..acf95b9
--- /dev/null
+++ b/patches/0001-fts-Avoid-d_namlen.patch
@@ -0,0 +1,49 @@
+From b546a0ae0beb2323143aed00d05e2fdf4fef5239 Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Sun, 17 Apr 2016 23:50:15 -0700
+Subject: [PATCH] fts: Avoid d_namlen
+
+---
+ lib/libc/gen/fts.c | 10 ++++++----
+ 1 file changed, 6 insertions(+), 4 deletions(-)
+
+diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c
+index 98b3a0a39..c186b7af2 100644
+--- a/lib/libc/gen/fts.c
++++ b/lib/libc/gen/fts.c
+@@ -555,6 +555,7 @@ fts_build(FTS *sp, int type)
+ int nitems, cderrno, descend, level, nlinks, nostat, doadjust;
+ int saved_errno;
+ char *cp;
++ size_t namlen;
+
+ /* Set current node pointer. */
+ cur = sp->fts_cur;
+@@ -653,11 +654,12 @@ fts_build(FTS *sp, int type)
+ if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
+ continue;
+
+- if (!(p = fts_alloc(sp, dp->d_name, dp->d_namlen)))
++ namlen = strlen(dp->d_name);
++ if (!(p = fts_alloc(sp, dp->d_name, namlen)))
+ goto mem1;
+- if (dp->d_namlen >= maxlen) { /* include space for NUL */
++ if (namlen >= maxlen) { /* include space for NUL */
+ oldaddr = sp->fts_path;
+- if (fts_palloc(sp, dp->d_namlen +len + 1)) {
++ if (fts_palloc(sp, namlen +len + 1)) {
+ /*
+ * No more memory for path or structures. Save
+ * errno, free up the current structure and the
+@@ -683,7 +685,7 @@ mem1: saved_errno = errno;
+
+ p->fts_level = level;
+ p->fts_parent = sp->fts_cur;
+- p->fts_pathlen = len + dp->d_namlen;
++ p->fts_pathlen = len + namlen;
+ if (p->fts_pathlen < len) {
+ /*
+ * If we wrap, free up the current structure and
+--
+2.12.2
+
diff --git a/patches/0002-fts-Add-some-includes.patch b/patches/0002-fts-Add-some-includes.patch
new file mode 100644
index 0000000..81a3eeb
--- /dev/null
+++ b/patches/0002-fts-Add-some-includes.patch
@@ -0,0 +1,46 @@
+From e73065515ec3b6c03e45ee7c8c10543ff44a407c Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Mon, 18 Apr 2016 01:25:29 -0700
+Subject: [PATCH] fts: Add some includes
+
+---
+ include/fts.h | 2 ++
+ lib/libc/gen/fts.c | 2 ++
+ 2 files changed, 4 insertions(+)
+
+diff --git a/include/fts.h b/include/fts.h
+index eaf6be07c..a5b3aff91 100644
+--- a/include/fts.h
++++ b/include/fts.h
+@@ -35,6 +35,8 @@
+ #ifndef _FTS_H_
+ #define _FTS_H_
+
++#include <sys/cdefs.h>
++
+ typedef struct {
+ struct _ftsent *fts_cur; /* current node */
+ struct _ftsent *fts_child; /* linked list of children */
+diff --git a/lib/libc/gen/fts.c b/lib/libc/gen/fts.c
+index c186b7af2..f41254c71 100644
+--- a/lib/libc/gen/fts.c
++++ b/lib/libc/gen/fts.c
+@@ -31,6 +31,7 @@
+
+ #include <sys/param.h> /* ALIGN */
+ #include <sys/stat.h>
++#include <sys/types.h>
+
+ #include <dirent.h>
+ #include <errno.h>
+@@ -39,6 +40,7 @@
+ #include <limits.h>
+ #include <stdlib.h>
+ #include <string.h>
++#include <time.h>
+ #include <unistd.h>
+
+ #define MAXIMUM(a, b) (((a) > (b)) ? (a) : (b))
+--
+2.12.2
+
diff --git a/patches/0003-pax-Set-listf-to-stderr-in-main.patch b/patches/0003-pax-Set-listf-to-stderr-in-main.patch
new file mode 100644
index 0000000..7a8ec25
--- /dev/null
+++ b/patches/0003-pax-Set-listf-to-stderr-in-main.patch
@@ -0,0 +1,34 @@
+From e2ca2e2a530e61e8af65dca829aa1fcad5c59a7d Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Mon, 18 Apr 2016 00:13:51 -0700
+Subject: [PATCH] pax: Set listf to stderr in main
+
+---
+ bin/pax/pax.c | 4 +++-
+ 1 file changed, 3 insertions(+), 1 deletion(-)
+
+diff --git a/bin/pax/pax.c b/bin/pax/pax.c
+index f6b3634369a..3d50e051075 100644
+--- a/bin/pax/pax.c
++++ b/bin/pax/pax.c
+@@ -93,7 +93,7 @@ char *dirptr; /* destination dir in a copy */
+ char *argv0; /* root of argv[0] */
+ enum op_mode op_mode; /* what program are we acting as? */
+ sigset_t s_mask; /* signal mask for cleanup critical sect */
+-FILE *listf = stderr; /* file pointer to print file list to */
++FILE *listf; /* file pointer to print file list to */
+ int listfd = STDERR_FILENO; /* fd matching listf, for sighandler output */
+ char *tempfile; /* tempfile to use for mkstemp(3) */
+ char *tempbase; /* basename of tempfile to use for mkstemp(3) */
+@@ -224,6 +224,8 @@ main(int argc, char **argv)
+ char *tmpdir;
+ size_t tdlen;
+
++ listf = stderr;
++
+ /*
+ * Keep a reference to cwd, so we can always come back home.
+ */
+--
+2.19.0
+
diff --git a/patches/0004-pax-Add-some-includes.patch b/patches/0004-pax-Add-some-includes.patch
new file mode 100644
index 0000000..cc029d5
--- /dev/null
+++ b/patches/0004-pax-Add-some-includes.patch
@@ -0,0 +1,86 @@
+From fbf6dc8783f31408cc090cf42cf92008d4f2a455 Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Mon, 18 Apr 2016 01:27:29 -0700
+Subject: [PATCH] pax: Add some includes
+
+---
+ bin/pax/ar_subs.c | 3 ++-
+ bin/pax/buf_subs.c | 1 +
+ bin/pax/file_subs.c | 2 ++
+ bin/pax/sel_subs.c | 1 +
+ bin/pax/tables.c | 1 +
+ 5 files changed, 7 insertions(+), 1 deletion(-)
+
+diff --git a/bin/pax/ar_subs.c b/bin/pax/ar_subs.c
+index 51dd6e085..f70ec4ed0 100644
+--- a/bin/pax/ar_subs.c
++++ b/bin/pax/ar_subs.c
+@@ -36,14 +36,15 @@
+
+ #include <sys/types.h>
+ #include <sys/stat.h>
++#include <sys/time.h>
+ #include <errno.h>
+ #include <fcntl.h>
+ #include <signal.h>
+ #include <stdio.h>
++#include <stdlib.h>
+ #include <string.h>
+ #include <time.h>
+ #include <unistd.h>
+-
+ #include "pax.h"
+ #include "extern.h"
+
+diff --git a/bin/pax/buf_subs.c b/bin/pax/buf_subs.c
+index 41f06ae31..30be3dc46 100644
+--- a/bin/pax/buf_subs.c
++++ b/bin/pax/buf_subs.c
+@@ -36,6 +36,7 @@
+
+ #include <sys/types.h>
+ #include <sys/stat.h>
++#include <sys/time.h>
+ #include <stdio.h>
+ #include <errno.h>
+ #include <unistd.h>
+diff --git a/bin/pax/file_subs.c b/bin/pax/file_subs.c
+index 9f834bf17..57ebdb490 100644
+--- a/bin/pax/file_subs.c
++++ b/bin/pax/file_subs.c
+@@ -35,6 +35,8 @@
+ */
+
+ #include <sys/stat.h>
++#include <sys/time.h>
++#include <sys/types.h>
+ #include <err.h>
+ #include <errno.h>
+ #include <fcntl.h>
+diff --git a/bin/pax/sel_subs.c b/bin/pax/sel_subs.c
+index 17200b5a4..136f87c5d 100644
+--- a/bin/pax/sel_subs.c
++++ b/bin/pax/sel_subs.c
+@@ -43,6 +43,7 @@
+ #include <stdlib.h>
+ #include <string.h>
+ #include <time.h>
++#include <unistd.h>
+
+ #include "pax.h"
+ #include "extern.h"
+diff --git a/bin/pax/tables.c b/bin/pax/tables.c
+index b700f1649..99790f986 100644
+--- a/bin/pax/tables.c
++++ b/bin/pax/tables.c
+@@ -36,6 +36,7 @@
+
+ #include <sys/types.h>
+ #include <sys/stat.h>
++#include <sys/time.h>
+ #include <errno.h>
+ #include <fcntl.h>
+ #include <limits.h>
+--
+2.12.2
+
diff --git a/patches/0005-tar-Default-to-stdin.patch b/patches/0005-tar-Default-to-stdin.patch
new file mode 100644
index 0000000..6c4e946
--- /dev/null
+++ b/patches/0005-tar-Default-to-stdin.patch
@@ -0,0 +1,25 @@
+From 901940cdf7fc13516ff55e81df0b546eb7c74595 Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Mon, 18 Apr 2016 01:16:12 -0700
+Subject: [PATCH] tar: Default to stdin
+
+---
+ bin/pax/options.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/bin/pax/options.c b/bin/pax/options.c
+index 5db0948858c..dbb4b816c37 100644
+--- a/bin/pax/options.c
++++ b/bin/pax/options.c
+@@ -937,7 +937,7 @@ tar_options(int argc, char **argv)
+ if ((arcname == NULL) || (*arcname == '\0')) {
+ arcname = getenv("TAPE");
+ if ((arcname == NULL) || (*arcname == '\0'))
+- arcname = _PATH_DEFTAPE;
++ arcname = "-";
+ }
+ if ((arcname[0] == '-') && (arcname[1]== '\0'))
+ arcname = NULL;
+--
+2.25.0
+
diff --git a/patches/0006-yacc-Add-some-includes.patch b/patches/0006-yacc-Add-some-includes.patch
new file mode 100644
index 0000000..d449874
--- /dev/null
+++ b/patches/0006-yacc-Add-some-includes.patch
@@ -0,0 +1,24 @@
+From f926c3a15c772a7d54561e01682dea486c2a2833 Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Mon, 18 Apr 2016 17:34:01 -0700
+Subject: [PATCH] yacc: Add some includes
+
+---
+ usr.bin/yacc/defs.h | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/usr.bin/yacc/defs.h b/usr.bin/yacc/defs.h
+index 7300caec2..fab6e1266 100644
+--- a/usr.bin/yacc/defs.h
++++ b/usr.bin/yacc/defs.h
+@@ -35,6 +35,7 @@
+ * @(#)defs.h 5.6 (Berkeley) 5/24/93
+ */
+
++#include <sys/cdefs.h>
+ #include <assert.h>
+ #include <ctype.h>
+ #include <stdio.h>
+--
+2.12.2
+
diff --git a/patches/0007-diff-Add-missing-includes.patch b/patches/0007-diff-Add-missing-includes.patch
new file mode 100644
index 0000000..643a6da
--- /dev/null
+++ b/patches/0007-diff-Add-missing-includes.patch
@@ -0,0 +1,37 @@
+From 7ce395bfbff36cf0020d0a425ff3053fcf2eaa3d Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Sat, 4 Jun 2016 14:48:20 -0700
+Subject: [PATCH] diff: Add missing includes
+
+---
+ usr.bin/diff/diff.c | 1 +
+ usr.bin/diff/diffreg.c | 1 +
+ 2 files changed, 2 insertions(+)
+
+diff --git a/usr.bin/diff/diff.c b/usr.bin/diff/diff.c
+index 2b075f12c..80c7f842e 100644
+--- a/usr.bin/diff/diff.c
++++ b/usr.bin/diff/diff.c
+@@ -20,6 +20,7 @@
+ * Materiel Command, USAF, under agreement number F39502-99-1-0512.
+ */
+
++#include <sys/cdefs.h>
+ #include <sys/stat.h>
+
+ #include <ctype.h>
+diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c
+index 35d61c349..953018cf5 100644
+--- a/usr.bin/diff/diffreg.c
++++ b/usr.bin/diff/diffreg.c
+@@ -77,6 +77,7 @@
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
++#include <time.h>
+ #include <unistd.h>
+ #include <limits.h>
+
+--
+2.12.2
+
diff --git a/patches/0008-patch-Add-missing-includes.patch b/patches/0008-patch-Add-missing-includes.patch
new file mode 100644
index 0000000..ec6f2d9
--- /dev/null
+++ b/patches/0008-patch-Add-missing-includes.patch
@@ -0,0 +1,24 @@
+From 299d570c708b33349131b8ca925c3e9bb733db84 Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Sat, 4 Jun 2016 18:40:24 -0700
+Subject: [PATCH] patch: Add missing includes
+
+---
+ usr.bin/patch/patch.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/usr.bin/patch/patch.c b/usr.bin/patch/patch.c
+index 0cb924db733..17b3aa4e23a 100644
+--- a/usr.bin/patch/patch.c
++++ b/usr.bin/patch/patch.c
+@@ -26,6 +26,7 @@
+ * behaviour
+ */
+
++#include <sys/cdefs.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <unistd.h>
+--
+2.19.0
+
diff --git a/patches/0009-patch-Avoid-d_namlen.patch b/patches/0009-patch-Avoid-d_namlen.patch
new file mode 100644
index 0000000..33d744a
--- /dev/null
+++ b/patches/0009-patch-Avoid-d_namlen.patch
@@ -0,0 +1,25 @@
+From 91483dfca3aa6373451120db45c60198faa0766e Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Sat, 4 Jun 2016 18:40:37 -0700
+Subject: [PATCH] patch: Avoid d_namlen
+
+---
+ usr.bin/patch/backupfile.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/usr.bin/patch/backupfile.c b/usr.bin/patch/backupfile.c
+index d9e40bcba..1d7858ae3 100644
+--- a/usr.bin/patch/backupfile.c
++++ b/usr.bin/patch/backupfile.c
+@@ -95,7 +95,7 @@ max_backup_version(const char *file, const char *dir)
+ file_name_length = strlen(file);
+
+ while ((dp = readdir(dirp)) != NULL) {
+- if (dp->d_namlen <= file_name_length)
++ if (strlen(dp->d_name) <= file_name_length)
+ continue;
+
+ this_version = version_number(file, dp->d_name, file_name_length);
+--
+2.12.2
+
diff --git a/patches/0010-patch-Fix-with-musl-s-basename-dirname.patch b/patches/0010-patch-Fix-with-musl-s-basename-dirname.patch
new file mode 100644
index 0000000..80a1db3
--- /dev/null
+++ b/patches/0010-patch-Fix-with-musl-s-basename-dirname.patch
@@ -0,0 +1,46 @@
+From e16acc0e80f475b2139eabe1b07b7eb0521a7918 Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Sat, 4 Jun 2016 20:13:35 -0700
+Subject: [PATCH] patch: Fix with musl's basename/dirname
+
+---
+ usr.bin/patch/backupfile.c | 15 ++++++++-------
+ 1 file changed, 8 insertions(+), 7 deletions(-)
+
+diff --git a/usr.bin/patch/backupfile.c b/usr.bin/patch/backupfile.c
+index 1d7858ae3..243d00e32 100644
+--- a/usr.bin/patch/backupfile.c
++++ b/usr.bin/patch/backupfile.c
+@@ -53,21 +53,22 @@ static void invalid_arg(const char *, const char *, int);
+ char *
+ find_backup_file_name(const char *file)
+ {
+- char *dir, *base_versions;
++ char *path, *base_versions;
+ int highest_backup;
+
+ if (backup_type == simple)
+ return concat(file, simple_backup_suffix);
+- base_versions = concat(basename(file), ".~");
+- if (base_versions == NULL)
++ path = strdup(file);
++ if (path == NULL)
+ return NULL;
+- dir = dirname(file);
+- if (dir == NULL) {
+- free(base_versions);
++ base_versions = concat(basename(path), ".~");
++ if (base_versions == NULL) {
++ free(path);
+ return NULL;
+ }
+- highest_backup = max_backup_version(base_versions, dir);
++ highest_backup = max_backup_version(base_versions, dirname(path));
+ free(base_versions);
++ free(path);
+ if (backup_type == numbered_existing && highest_backup == 0)
+ return concat(file, simple_backup_suffix);
+ return make_version_name(file, highest_backup + 1);
+--
+2.12.2
+
diff --git a/patches/0011-pax-Fix-GNU-long-name-handling-with-short-read.patch b/patches/0011-pax-Fix-GNU-long-name-handling-with-short-read.patch
new file mode 100644
index 0000000..b88aa2b
--- /dev/null
+++ b/patches/0011-pax-Fix-GNU-long-name-handling-with-short-read.patch
@@ -0,0 +1,176 @@
+From ec3fd37495e977af375a98a472d19ae0ccbcd874 Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Sat, 3 Dec 2016 20:49:24 -0800
+Subject: [PATCH] pax: Fix GNU long name handling with short read
+
+---
+ bin/pax/ar_subs.c | 66 +++++++++++++++++++++++++++++++++------------
+ bin/pax/buf_subs.c | 4 +--
+ bin/pax/file_subs.c | 25 +----------------
+ 3 files changed, 51 insertions(+), 44 deletions(-)
+
+diff --git a/bin/pax/ar_subs.c b/bin/pax/ar_subs.c
+index e5b0a4ee5d1..f0a55abe2f7 100644
+--- a/bin/pax/ar_subs.c
++++ b/bin/pax/ar_subs.c
+@@ -37,6 +37,7 @@
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <sys/time.h>
++#include <err.h>
+ #include <errno.h>
+ #include <fcntl.h>
+ #include <signal.h>
+@@ -51,6 +52,7 @@
+ static void wr_archive(ARCHD *, int is_app);
+ static int get_arc(void);
+ static int next_head(ARCHD *);
++static int rd_gnu_string(ARCHD *);
+ extern sigset_t s_mask;
+
+ /*
+@@ -93,16 +95,8 @@ list(void)
+ * step through the archive until the format says it is done
+ */
+ while (next_head(arcn) == 0) {
+- if (arcn->type == PAX_GLL || arcn->type == PAX_GLF) {
+- /*
+- * we need to read, to get the real filename
+- */
+- off_t cnt;
+- if (!rd_wrfile(arcn, arcn->type == PAX_GLF
+- ? -1 : -2, &cnt))
+- (void)rd_skip(cnt + arcn->pad);
++ if (rd_gnu_string(arcn))
+ continue;
+- }
+
+ /*
+ * check for pattern, and user specified options match.
+@@ -208,15 +202,8 @@ extract(void)
+ * says it is done
+ */
+ while (next_head(arcn) == 0) {
+- if (arcn->type == PAX_GLL || arcn->type == PAX_GLF) {
+- /*
+- * we need to read, to get the real filename
+- */
+- if (!rd_wrfile(arcn, arcn->type == PAX_GLF
+- ? -1 : -2, &cnt))
+- (void)rd_skip(cnt + arcn->pad);
++ if (rd_gnu_string(arcn))
+ continue;
+- }
+
+ /*
+ * check for pattern, and user specified options match. When
+@@ -1243,3 +1230,48 @@ get_arc(void)
+ paxwarn(1, "Sorry, unable to determine archive format.");
+ return(-1);
+ }
++
++/*
++ * rd_gnu_string()
++ * Read the file contents into an allocated string if it is a GNU tar
++ * long link/file.
++ * Return:
++ * 1 if gnu string read, 0 otherwise
++ */
++
++static int
++rd_gnu_string(ARCHD *arcn)
++{
++ char **strp;
++
++ switch (arcn->type) {
++ case PAX_GLF:
++ strp = &gnu_name_string;
++ break;
++ case PAX_GLL:
++ strp = &gnu_link_string;
++ break;
++ default:
++ strp = NULL;
++ break;
++ }
++ if (!strp)
++ return 0;
++ /*
++ * we need to read, to get the real filename
++ */
++ if (*strp)
++ err(1, "WARNING! Major Internal Error! GNU hack Failing!");
++ *strp = malloc(arcn->sb.st_size + 1);
++ if (*strp == NULL) {
++ paxwarn(1, "Out of memory");
++ (void)rd_skip(arcn->skip + arcn->pad);
++ } else if (rd_wrbuf(*strp, arcn->sb.st_size) < arcn->sb.st_size) {
++ free(*strp);
++ *strp = NULL;
++ } else {
++ (*strp)[arcn->sb.st_size] = '\0';
++ (void)rd_skip(arcn->pad);
++ }
++ return 1;
++}
+diff --git a/bin/pax/buf_subs.c b/bin/pax/buf_subs.c
+index 68534dcbe25..e84f9e0d3d6 100644
+--- a/bin/pax/buf_subs.c
++++ b/bin/pax/buf_subs.c
+@@ -673,9 +673,7 @@ rd_wrfile(ARCHD *arcn, int ofd, off_t *left)
+ * pass the blocksize of the file being written to the write routine,
+ * if the size is zero, use the default MINFBSZ
+ */
+- if (ofd < 0)
+- sz = PAXPATHLEN + 1; /* GNU tar long link/file */
+- else if (fstat(ofd, &sb) == 0) {
++ if (fstat(ofd, &sb) == 0) {
+ if (sb.st_blksize > 0)
+ sz = (int)sb.st_blksize;
+ } else
+diff --git a/bin/pax/file_subs.c b/bin/pax/file_subs.c
+index 89b4872988b..8aa3d249923 100644
+--- a/bin/pax/file_subs.c
++++ b/bin/pax/file_subs.c
+@@ -919,7 +919,6 @@ file_write(int fd, char *str, int cnt, int *rem, int *isempt, int sz,
+ char *end;
+ int wcnt;
+ char *st = str;
+- char **strp;
+
+ /*
+ * while we have data to process
+@@ -978,29 +977,7 @@ file_write(int fd, char *str, int cnt, int *rem, int *isempt, int sz,
+ /*
+ * have non-zero data in this file system block, have to write
+ */
+- switch (fd) {
+- case -1:
+- strp = &gnu_name_string;
+- break;
+- case -2:
+- strp = &gnu_link_string;
+- break;
+- default:
+- strp = NULL;
+- break;
+- }
+- if (strp) {
+- if (*strp)
+- err(1, "WARNING! Major Internal Error! GNU hack Failing!");
+- *strp = malloc(wcnt + 1);
+- if (*strp == NULL) {
+- paxwarn(1, "Out of memory");
+- return(-1);
+- }
+- memcpy(*strp, st, wcnt);
+- (*strp)[wcnt] = '\0';
+- break;
+- } else if (write(fd, st, wcnt) != wcnt) {
++ if (write(fd, st, wcnt) != wcnt) {
+ syswarn(1, errno, "Failed write to file %s", name);
+ return(-1);
+ }
+--
+2.26.2
+
diff --git a/patches/0012-pax-Support-xz-compression-with-J-flag.patch b/patches/0012-pax-Support-xz-compression-with-J-flag.patch
new file mode 100644
index 0000000..00f8a8b
--- /dev/null
+++ b/patches/0012-pax-Support-xz-compression-with-J-flag.patch
@@ -0,0 +1,90 @@
+From ac4a17dd01df3889bac917b0dc34ba9fd15aa7fe Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Sat, 3 Dec 2016 23:50:27 -0800
+Subject: [PATCH] pax: Support xz compression with -J flag
+
+---
+ bin/pax/options.c | 25 ++++++++++++++++++++++---
+ 1 file changed, 22 insertions(+), 3 deletions(-)
+
+diff --git a/bin/pax/options.c b/bin/pax/options.c
+index c7e64a5d22c..917414c999a 100644
+--- a/bin/pax/options.c
++++ b/bin/pax/options.c
+@@ -154,6 +154,7 @@ static int xz_id(char *_blk, int _size);
+ #define GZIP_CMD "gzip" /* command to run as gzip */
+ #define COMPRESS_CMD "compress" /* command to run as compress */
+ #define BZIP2_CMD "bzip2" /* command to run as bzip2 */
++#define XZ_CMD "xz" /* command to run as xz */
+
+ /*
+ * Format specific routine table
+@@ -300,7 +301,7 @@ pax_options(int argc, char **argv)
+ /*
+ * process option flags
+ */
+- while ((c=getopt(argc,argv,"ab:cdf:ijklno:p:rs:tuvwx:zB:DE:G:HLOPT:U:XYZ0"))
++ while ((c=getopt(argc,argv,"ab:cdf:ijklno:p:rs:tuvwx:zB:DE:G:HJLOPT:U:XYZ0"))
+ != -1) {
+ switch (c) {
+ case 'a':
+@@ -556,6 +557,12 @@ pax_options(int argc, char **argv)
+ Hflag = 1;
+ flg |= CHF;
+ break;
++ case 'J':
++ /*
++ * use xz. Non standard option.
++ */
++ gzip_program = XZ_CMD;
++ break;
+ case 'L':
+ /*
+ * follow symlinks
+@@ -731,7 +738,7 @@ tar_options(int argc, char **argv)
+ * process option flags
+ */
+ while ((c = getoldopt(argc, argv,
+- "b:cef:hjmopqruts:vwxzBC:HI:LNOPXZ014578")) != -1) {
++ "b:cef:hjmopqruts:vwxzBC:HI:JLNOPXZ014578")) != -1) {
+ switch (c) {
+ case 'b':
+ /*
+@@ -880,6 +887,12 @@ tar_options(int argc, char **argv)
+ incfiles[nincfiles - 1].file = optarg;
+ incfiles[nincfiles - 1].dir = chdname;
+ break;
++ case 'J':
++ /*
++ * use xz. Non standard option.
++ */
++ gzip_program = XZ_CMD;
++ break;
+ case 'L':
+ /*
+ * follow symlinks
+@@ -1164,7 +1177,7 @@ cpio_options(int argc, char **argv)
+ dflag = 1;
+ act = -1;
+ nodirs = 1;
+- while ((c=getopt(argc,argv,"abcdfijklmoprstuvzABC:E:F:H:I:LO:SZ6")) != -1)
++ while ((c=getopt(argc,argv,"abcdfijklmoprstuvzABC:E:F:H:I:JLO:SZ6")) != -1)
+ switch (c) {
+ case 'a':
+ /*
+@@ -1348,6 +1361,12 @@ cpio_options(int argc, char **argv)
+ (void)fputs("\n\n", stderr);
+ cpio_usage();
+ break;
++ case 'J':
++ /*
++ * use xz. Non standard option.
++ */
++ gzip_program = XZ_CMD;
++ break;
+ case 'L':
+ /*
+ * follow symbolic links
+--
+2.26.2
+
diff --git a/patches/0013-setprogname-Explicitly-discard-const-qualifier.patch b/patches/0013-setprogname-Explicitly-discard-const-qualifier.patch
new file mode 100644
index 0000000..a645a9e
--- /dev/null
+++ b/patches/0013-setprogname-Explicitly-discard-const-qualifier.patch
@@ -0,0 +1,23 @@
+From 7cc3b8b8b1ca390b6ed65d3234827bc7393f9300 Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Sun, 11 Dec 2016 14:36:13 -0800
+Subject: [PATCH] setprogname: Explicitly discard const qualifier
+
+---
+ lib/libc/gen/setprogname.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/lib/libc/gen/setprogname.c b/lib/libc/gen/setprogname.c
+index bce4cbdac44..0c1573c9162 100644
+--- a/lib/libc/gen/setprogname.c
++++ b/lib/libc/gen/setprogname.c
+@@ -27,5 +27,5 @@ setprogname(const char *progname)
+ if (tmpn == NULL)
+ __progname = (char *)progname;
+ else
+- __progname = tmpn + 1;
++ __progname = (char *)tmpn + 1;
+ }
+--
+2.14.2
+
diff --git a/patches/0014-readpassphrase-Support-systems-without-VSTATUS-and-T.patch b/patches/0014-readpassphrase-Support-systems-without-VSTATUS-and-T.patch
new file mode 100644
index 0000000..7866090
--- /dev/null
+++ b/patches/0014-readpassphrase-Support-systems-without-VSTATUS-and-T.patch
@@ -0,0 +1,38 @@
+From d36036bbd959091b6442d003128342ed515af01b Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Sun, 26 Feb 2017 17:01:33 -0800
+Subject: [PATCH] readpassphrase: Support systems without VSTATUS and TCSASOFT
+
+---
+ lib/libc/gen/readpassphrase.c | 6 ++++++
+ 1 file changed, 6 insertions(+)
+
+diff --git a/lib/libc/gen/readpassphrase.c b/lib/libc/gen/readpassphrase.c
+index a1aeb342b..a50eaf003 100644
+--- a/lib/libc/gen/readpassphrase.c
++++ b/lib/libc/gen/readpassphrase.c
+@@ -32,6 +32,10 @@
+ #include <unistd.h>
+ #include <readpassphrase.h>
+
++#ifndef TCSASOFT
++#define TCSASOFT 0
++#endif
++
+ static volatile sig_atomic_t signo[_NSIG];
+
+ static void handler(int);
+@@ -81,8 +85,10 @@ restart:
+ memcpy(&term, &oterm, sizeof(term));
+ if (!(flags & RPP_ECHO_ON))
+ term.c_lflag &= ~(ECHO | ECHONL);
++#ifdef VSTATUS
+ if (term.c_cc[VSTATUS] != _POSIX_VDISABLE)
+ term.c_cc[VSTATUS] = _POSIX_VDISABLE;
++#endif
+ (void)tcsetattr(input, TCSAFLUSH|TCSASOFT, &term);
+ } else {
+ memset(&term, 0, sizeof(term));
+--
+2.12.2
+
diff --git a/patches/0015-Remove-getpass-definition.patch b/patches/0015-Remove-getpass-definition.patch
new file mode 100644
index 0000000..f2adafd
--- /dev/null
+++ b/patches/0015-Remove-getpass-definition.patch
@@ -0,0 +1,36 @@
+From e76fda424564544bc8298fb5be7cda966451497d Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Sun, 26 Feb 2017 17:12:56 -0800
+Subject: [PATCH] Remove getpass definition
+
+It is a legacy function and musl already provides an implementation.
+---
+ lib/libc/gen/readpassphrase.c | 12 ++----------
+ 1 file changed, 2 insertions(+), 10 deletions(-)
+
+diff --git a/lib/libc/gen/readpassphrase.c b/lib/libc/gen/readpassphrase.c
+index a50eaf003..57c6dc527 100644
+--- a/lib/libc/gen/readpassphrase.c
++++ b/lib/libc/gen/readpassphrase.c
+@@ -183,16 +183,8 @@ restart:
+ }
+ DEF_WEAK(readpassphrase);
+
+-char *
+-getpass(const char *prompt)
+-{
+- static char buf[_PASSWORD_LEN + 1];
+-
+- return(readpassphrase(prompt, buf, sizeof(buf), RPP_ECHO_OFF));
+-}
+-
+-static void handler(int s)
++static void
++handler(int s)
+ {
+-
+ signo[s] = 1;
+ }
+--
+2.12.2
+
diff --git a/patches/0016-doas-Port-to-linux-musl.patch b/patches/0016-doas-Port-to-linux-musl.patch
new file mode 100644
index 0000000..877d3f0
--- /dev/null
+++ b/patches/0016-doas-Port-to-linux-musl.patch
@@ -0,0 +1,435 @@
+From c95443d87b64650823e41016c26b1f5a3b38e7b3 Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Sun, 26 Feb 2017 16:50:55 -0800
+Subject: [PATCH] doas: Port to linux/musl
+
+Remove -a login style option and BSD authentication. Instead, compare
+against shadow file.
+
+Use timestamp files in /run/doas instead of TIOC*VERAUTH to implement
+persist.
+
+Use initgroups/setgid/setuid instead of setusercontext.
+
+Provide UID_MAX and GID_MAX defaults.
+
+Use LOGIN_NAME_MAX instead of _PW_NAME_LEN.
+
+Remove call to closefrom.
+
+Replace calls to errc with err after setting errno.
+
+Call openlog at start to set syslog identity.
+---
+ usr.bin/doas/doas.1 | 9 ---
+ usr.bin/doas/doas.c | 97 ++++++++++++++++--------------
+ usr.bin/doas/doas.h | 4 ++
+ usr.bin/doas/parse.y | 1 +
+ usr.bin/doas/persist.c | 133 +++++++++++++++++++++++++++++++++++++++++
+ 5 files changed, 191 insertions(+), 53 deletions(-)
+ create mode 100644 usr.bin/doas/persist.c
+
+diff --git a/usr.bin/doas/doas.1 b/usr.bin/doas/doas.1
+index fc769bdb336..c7196e347a9 100644
+--- a/usr.bin/doas/doas.1
++++ b/usr.bin/doas/doas.1
+@@ -22,7 +22,6 @@
+ .Sh SYNOPSIS
+ .Nm doas
+ .Op Fl Lns
+-.Op Fl a Ar style
+ .Op Fl C Ar config
+ .Op Fl u Ar user
+ .Ar command
+@@ -67,14 +66,6 @@ The working directory is not changed.
+ .Pp
+ The options are as follows:
+ .Bl -tag -width tenletters
+-.It Fl a Ar style
+-Use the specified authentication style when validating the user,
+-as allowed by
+-.Pa /etc/login.conf .
+-A list of doas-specific authentication methods may be configured by adding an
+-.Sq auth-doas
+-entry in
+-.Xr login.conf 5 .
+ .It Fl C Ar config
+ Parse and check the configuration file
+ .Ar config ,
+diff --git a/usr.bin/doas/doas.c b/usr.bin/doas/doas.c
+index a723c67a3eb..e7e3e639401 100644
+--- a/usr.bin/doas/doas.c
++++ b/usr.bin/doas/doas.c
+@@ -20,8 +20,6 @@
+ #include <sys/ioctl.h>
+
+ #include <limits.h>
+-#include <login_cap.h>
+-#include <bsd_auth.h>
+ #include <readpassphrase.h>
+ #include <string.h>
+ #include <stdio.h>
+@@ -33,13 +31,22 @@
+ #include <syslog.h>
+ #include <errno.h>
+ #include <fcntl.h>
++#include <shadow.h>
+
+ #include "doas.h"
+
++#ifndef UID_MAX
++#define UID_MAX 65535
++#endif
++
++#ifndef GID_MAX
++#define GID_MAX 65535
++#endif
++
+ static void __dead
+ usage(void)
+ {
+- fprintf(stderr, "usage: doas [-Lns] [-a style] [-C config] [-u user]"
++ fprintf(stderr, "usage: doas [-Lns] [-C config] [-u user]"
+ " command [args]\n");
+ exit(1);
+ }
+@@ -197,23 +204,36 @@ checkconfig(const char *confpath, int argc, char **argv,
+ }
+ }
+
++static int
++verifypasswd(const char *user, const char *pass)
++{
++ struct spwd *sp;
++ char *p1, *p2;
++
++ sp = getspnam(user);
++ if (!sp)
++ return 0;
++ p1 = sp->sp_pwdp;
++ if (p1[0] == '!' || p1[0] == '*')
++ return 0;
++ p2 = crypt(pass, p1);
++ if (!p2)
++ return 0;
++ return strcmp(p1, p2) == 0;
++}
++
+ static void
+-authuser(char *myname, char *login_style, int persist)
++authuser(char *myname, int persist)
+ {
+ char *challenge = NULL, *response, rbuf[1024], cbuf[128];
+- auth_session_t *as;
+- int fd = -1;
++ int fd = -1, valid = 0;
+
+- if (persist)
+- fd = open("/dev/tty", O_RDWR);
+- if (fd != -1) {
+- if (ioctl(fd, TIOCCHKVERAUTH) == 0)
++ if (persist) {
++ fd = openpersist(&valid);
++ if (valid)
+ goto good;
+ }
+
+- if (!(as = auth_userchallenge(myname, login_style, "auth-doas",
+- &challenge)))
+- errx(1, "Authorization failed");
+ if (!challenge) {
+ char host[HOST_NAME_MAX + 1];
+ if (gethostname(host, sizeof(host)))
+@@ -225,21 +245,18 @@ authuser(char *myname, char *login_style, int persist)
+ response = readpassphrase(challenge, rbuf, sizeof(rbuf),
+ RPP_REQUIRE_TTY);
+ if (response == NULL && errno == ENOTTY) {
+- syslog(LOG_AUTHPRIV | LOG_NOTICE,
+- "tty required for %s", myname);
++ syslog(LOG_NOTICE, "tty required for %s", myname);
+ errx(1, "a tty is required");
+ }
+- if (!auth_userresponse(as, response, 0)) {
++ if (!verifypasswd(myname, response)) {
+ explicit_bzero(rbuf, sizeof(rbuf));
+- syslog(LOG_AUTHPRIV | LOG_NOTICE,
+- "failed auth for %s", myname);
++ syslog(LOG_NOTICE, "failed auth for %s", myname);
+ errx(1, "Authorization failed");
+ }
+ explicit_bzero(rbuf, sizeof(rbuf));
+ good:
+ if (fd != -1) {
+- int secs = 5 * 60;
+- ioctl(fd, TIOCSETVERAUTH, &secs);
++ setpersist(fd);
+ close(fd);
+ }
+ }
+@@ -285,15 +302,14 @@ done:
+ int
+ main(int argc, char **argv)
+ {
+- const char *safepath = "/bin:/sbin:/usr/bin:/usr/sbin:"
+- "/usr/local/bin:/usr/local/sbin";
++ const char *safepath = "/bin";
+ const char *confpath = NULL;
+ char *shargv[] = { NULL, NULL };
+ char *sh;
+ const char *p;
+ const char *cmd;
+ char cmdline[LINE_MAX];
+- char mypwbuf[_PW_BUF_LEN], targpwbuf[_PW_BUF_LEN];
++ char mypwbuf[1024], targpwbuf[1024];
+ struct passwd mypwstore, targpwstore;
+ struct passwd *mypw, *targpw;
+ const struct rule *rule;
+@@ -306,28 +322,20 @@ main(int argc, char **argv)
+ int nflag = 0;
+ char cwdpath[PATH_MAX];
+ const char *cwd;
+- char *login_style = NULL;
+ char **envp;
+
+ setprogname("doas");
+-
+- closefrom(STDERR_FILENO + 1);
++ openlog("doas", 0, LOG_AUTHPRIV);
+
+ uid = getuid();
+
+- while ((ch = getopt(argc, argv, "a:C:Lnsu:")) != -1) {
++ while ((ch = getopt(argc, argv, "C:Lnsu:")) != -1) {
+ switch (ch) {
+- case 'a':
+- login_style = optarg;
+- break;
+ case 'C':
+ confpath = optarg;
+ break;
+ case 'L':
+- i = open("/dev/tty", O_RDWR);
+- if (i != -1)
+- ioctl(i, TIOCCLRVERAUTH);
+- exit(i == -1);
++ exit(clearpersist() != 0);
+ case 'u':
+ if (parseuid(optarg, &target) != 0)
+ errx(1, "unknown user");
+@@ -395,16 +403,16 @@ main(int argc, char **argv)
+ cmd = argv[0];
+ if (!permit(uid, groups, ngroups, &rule, target, cmd,
+ (const char **)argv + 1)) {
+- syslog(LOG_AUTHPRIV | LOG_NOTICE,
+- "failed command for %s: %s", mypw->pw_name, cmdline);
+- errc(1, EPERM, NULL);
++ syslog(LOG_NOTICE, "failed command for %s: %s", mypw->pw_name, cmdline);
++ errno = EPERM;
++ err(1, NULL);
+ }
+
+ if (!(rule->options & NOPASS)) {
+ if (nflag)
+ errx(1, "Authorization required");
+
+- authuser(mypw->pw_name, login_style, rule->options & PERSIST);
++ authuser(mypw->pw_name, rule->options & PERSIST);
+ }
+
+ if ((p = getenv("PATH")) != NULL)
+@@ -431,11 +439,12 @@ main(int argc, char **argv)
+ if (targpw == NULL)
+ errx(1, "no passwd entry for target");
+
+- if (setusercontext(NULL, targpw, target, LOGIN_SETGROUP |
+- LOGIN_SETPATH |
+- LOGIN_SETPRIORITY | LOGIN_SETRESOURCES | LOGIN_SETUMASK |
+- LOGIN_SETUSER) != 0)
+- errx(1, "failed to set user context for target");
++ if (initgroups(targpw->pw_name, targpw->pw_gid) < 0)
++ err(1, "initgroups");
++ if (setgid(targpw->pw_gid) < 0)
++ err(1, "setgid");
++ if (setuid(targpw->pw_uid) < 0)
++ err(1, "setuid");
+
+ if (pledge("stdio rpath exec", NULL) == -1)
+ err(1, "pledge");
+@@ -448,7 +457,7 @@ main(int argc, char **argv)
+ if (pledge("stdio exec", NULL) == -1)
+ err(1, "pledge");
+
+- syslog(LOG_AUTHPRIV | LOG_INFO, "%s ran command %s as %s from %s",
++ syslog(LOG_INFO, "%s ran command %s as %s from %s",
+ mypw->pw_name, cmdline, targpw->pw_name, cwd);
+
+ envp = prepenv(rule, mypw, targpw);
+diff --git a/usr.bin/doas/doas.h b/usr.bin/doas/doas.h
+index 6f50fc22869..c97986e3cf3 100644
+--- a/usr.bin/doas/doas.h
++++ b/usr.bin/doas/doas.h
+@@ -36,6 +36,10 @@ struct passwd;
+ char **prepenv(const struct rule *, const struct passwd *,
+ const struct passwd *);
+
++int openpersist(int *valid);
++int setpersist(int fd);
++int clearpersist(void);
++
+ #define PERMIT 1
+ #define DENY 2
+
+diff --git a/usr.bin/doas/parse.y b/usr.bin/doas/parse.y
+index dd9466e5f13..d1f698c7679 100644
+--- a/usr.bin/doas/parse.y
++++ b/usr.bin/doas/parse.y
+@@ -19,6 +19,7 @@
+ #include <sys/types.h>
+ #include <ctype.h>
+ #include <unistd.h>
++#include <stdlib.h>
+ #include <stdint.h>
+ #include <stdarg.h>
+ #include <stdio.h>
+diff --git a/usr.bin/doas/persist.c b/usr.bin/doas/persist.c
+new file mode 100644
+index 00000000000..4ad1bf1efbf
+--- /dev/null
++++ b/usr.bin/doas/persist.c
+@@ -0,0 +1,133 @@
++#include <errno.h>
++#include <fcntl.h>
++#include <limits.h>
++#include <stdio.h>
++#include <stdlib.h>
++#include <string.h>
++#include <sys/stat.h>
++#include <sys/types.h>
++#include <time.h>
++#include <unistd.h>
++
++#include "doas.h"
++
++#define PERSIST_DIR "/run/doas"
++#define PERSIST_TIMEOUT 5 * 60
++
++static int
++ttyid(dev_t *tty)
++{
++ int fd, i;
++ char buf[BUFSIZ], *p;
++ ssize_t n;
++
++ fd = open("/proc/self/stat", O_RDONLY);
++ if (fd == -1)
++ return -1;
++ n = read(fd, buf, sizeof(buf) - 1);
++ if (n >= 0)
++ buf[n] = '\0';
++ /* check that we read the whole file */
++ n = read(fd, buf, 1);
++ close(fd);
++ if (n != 0)
++ return -1;
++ p = strrchr(buf, ')');
++ if (!p)
++ return -1;
++ ++p;
++ /* ttr_nr is the 5th field after executable name, so skip the next 4 */
++ for (i = 0; i < 4; ++i) {
++ p = strchr(++p, ' ');
++ if (!p)
++ return -1;
++ }
++ *tty = strtol(p, &p, 10);
++ if (*p != ' ')
++ return -1;
++ return 0;
++}
++
++static int
++persistpath(char *buf, size_t len)
++{
++ dev_t tty;
++ int n;
++
++ if (ttyid(&tty) < 0)
++ return -1;
++ n = snprintf(buf, len, PERSIST_DIR "/%ju-%ju", (uintmax_t)getuid(), (uintmax_t)tty);
++ if (n < 0 || n >= (int)len)
++ return -1;
++ return 0;
++}
++
++int
++openpersist(int *valid)
++{
++ char path[256];
++ struct stat st;
++ struct timespec ts;
++ int fd;
++
++ if (stat(PERSIST_DIR, &st) < 0) {
++ if (errno != ENOENT)
++ return -1;
++ if (mkdir(PERSIST_DIR, 0700) < 0)
++ return -1;
++ } else if (st.st_uid != 0 || st.st_mode != (S_IFDIR | 0700)) {
++ return -1;
++ }
++ if (persistpath(path, sizeof(path)) < 0)
++ return -1;
++ fd = open(path, O_RDONLY);
++ if (fd == -1) {
++ char tmp[256];
++ struct timespec ts[2] = { { .tv_nsec = UTIME_OMIT }, { 0 } };
++ int n;
++
++ n = snprintf(tmp, sizeof(tmp), PERSIST_DIR "/.tmp-%d", getpid());
++ if (n < 0 || n >= (int)sizeof(tmp))
++ return -1;
++ fd = open(tmp, O_RDONLY | O_CREAT | O_EXCL, 0);
++ if (fd == -1)
++ return -1;
++ if (futimens(fd, ts) < 0 || rename(tmp, path) < 0) {
++ close(fd);
++ unlink(tmp);
++ return -1;
++ }
++ *valid = 0;
++ } else {
++ *valid = clock_gettime(CLOCK_BOOTTIME, &ts) == 0 &&
++ fstat(fd, &st) == 0 &&
++ (ts.tv_sec < st.st_mtim.tv_sec ||
++ (ts.tv_sec == st.st_mtim.tv_sec && ts.tv_nsec < st.st_mtim.tv_nsec)) &&
++ st.st_mtime - ts.tv_sec <= PERSIST_TIMEOUT;
++ }
++ return fd;
++}
++
++int
++setpersist(int fd)
++{
++ struct timespec times[2];
++
++ if (clock_gettime(CLOCK_BOOTTIME, &times[1]) < 0)
++ return -1;
++ times[0].tv_nsec = UTIME_OMIT;
++ times[1].tv_sec += PERSIST_TIMEOUT;
++ return futimens(fd, times);
++}
++
++int
++clearpersist(void)
++{
++ char path[256];
++
++ if (persistpath(path, sizeof(path)) < 0)
++ return -1;
++ if (unlink(path) < 0 && errno != ENOENT)
++ return -1;
++ return 0;
++}
+--
+2.27.0
+
diff --git a/patches/0017-pwcache-Don-t-use-fixed-buffer-sizes.patch b/patches/0017-pwcache-Don-t-use-fixed-buffer-sizes.patch
new file mode 100644
index 0000000..3b7896b
--- /dev/null
+++ b/patches/0017-pwcache-Don-t-use-fixed-buffer-sizes.patch
@@ -0,0 +1,92 @@
+From ab480e176692b91f2fb6fb9ea2e1725d980d805d Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Fri, 14 Apr 2017 11:25:01 -0700
+Subject: [PATCH] pwcache: Don't use fixed buffer sizes
+
+---
+ lib/libc/gen/pwcache.c | 20 ++++++++------------
+ 1 file changed, 8 insertions(+), 12 deletions(-)
+
+diff --git a/lib/libc/gen/pwcache.c b/lib/libc/gen/pwcache.c
+index d54daa08cc7..2f30f4b966b 100644
+--- a/lib/libc/gen/pwcache.c
++++ b/lib/libc/gen/pwcache.c
+@@ -202,8 +202,7 @@ grptb_start(void)
+ const char *
+ user_from_uid(uid_t uid, int noname)
+ {
+- struct passwd pwstore, *pw = NULL;
+- char pwbuf[_PW_BUF_LEN];
++ struct passwd *pw;
+ UIDC **pptr, *ptr = NULL;
+
+ if ((uidtb != NULL) || (uidtb_start() == 0)) {
+@@ -226,7 +225,7 @@ user_from_uid(uid_t uid, int noname)
+ *pptr = ptr = malloc(sizeof(UIDC));
+ }
+
+- getpwuid_r(uid, &pwstore, pwbuf, sizeof(pwbuf), &pw);
++ pw = getpwuid(uid);
+ if (pw == NULL) {
+ /*
+ * no match for this uid in the local password file
+@@ -263,8 +262,7 @@ user_from_uid(uid_t uid, int noname)
+ const char *
+ group_from_gid(gid_t gid, int noname)
+ {
+- struct group grstore, *gr = NULL;
+- char grbuf[_GR_BUF_LEN];
++ struct group *gr;
+ GIDC **pptr, *ptr = NULL;
+
+ if ((gidtb != NULL) || (gidtb_start() == 0)) {
+@@ -287,7 +285,7 @@ group_from_gid(gid_t gid, int noname)
+ *pptr = ptr = malloc(sizeof(GIDC));
+ }
+
+- getgrgid_r(gid, &grstore, grbuf, sizeof(grbuf), &gr);
++ gr = getgrgid(gid);
+ if (gr == NULL) {
+ /*
+ * no match for this gid in the local group file, put in
+@@ -322,8 +320,7 @@ group_from_gid(gid_t gid, int noname)
+ int
+ uid_from_user(const char *name, uid_t *uid)
+ {
+- struct passwd pwstore, *pw = NULL;
+- char pwbuf[_PW_BUF_LEN];
++ struct passwd *pw;
+ UIDC **pptr, *ptr = NULL;
+ size_t namelen;
+
+@@ -357,7 +354,7 @@ uid_from_user(const char *name, uid_t *uid)
+ * no match, look it up, if no match store it as an invalid entry,
+ * or store the matching uid
+ */
+- getpwnam_r(name, &pwstore, pwbuf, sizeof(pwbuf), &pw);
++ pw = getpwnam(name);
+ if (ptr == NULL) {
+ if (pw == NULL)
+ return -1;
+@@ -383,8 +380,7 @@ uid_from_user(const char *name, uid_t *uid)
+ int
+ gid_from_group(const char *name, gid_t *gid)
+ {
+- struct group grstore, *gr = NULL;
+- char grbuf[_GR_BUF_LEN];
++ struct group *gr;
+ GIDC **pptr, *ptr = NULL;
+ size_t namelen;
+
+@@ -418,7 +414,7 @@ gid_from_group(const char *name, gid_t *gid)
+ * no match, look it up, if no match store it as an invalid entry,
+ * or store the matching gid
+ */
+- getgrnam_r(name, &grstore, grbuf, sizeof(grbuf), &gr);
++ gr = getgrnam(name);
+ if (ptr == NULL) {
+ if (gr == NULL)
+ return -1;
+--
+2.19.0
+
diff --git a/patches/0018-yacc-Remove-__unused.patch b/patches/0018-yacc-Remove-__unused.patch
new file mode 100644
index 0000000..d8e49be
--- /dev/null
+++ b/patches/0018-yacc-Remove-__unused.patch
@@ -0,0 +1,27 @@
+From 8c468833465d7fa0d5372807de01272414b1f4bb Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Tue, 10 Oct 2017 02:55:38 -0700
+Subject: [PATCH] yacc: Remove __unused
+
+We can't define this to __attribute__((unused)) because musl uses this
+identifier as a structure field.
+---
+ usr.bin/yacc/main.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/usr.bin/yacc/main.c b/usr.bin/yacc/main.c
+index 3d9f6add5c8..dd34a04c5bf 100644
+--- a/usr.bin/yacc/main.c
++++ b/usr.bin/yacc/main.c
+@@ -122,7 +122,7 @@ done(int k)
+
+
+ void
+-onintr(__unused int signo)
++onintr(int signo)
+ {
+ sigdie = 1;
+ done(1);
+--
+2.14.2
+
diff --git a/patches/0019-Add-standalone-freezero.patch b/patches/0019-Add-standalone-freezero.patch
new file mode 100644
index 0000000..249a3e4
--- /dev/null
+++ b/patches/0019-Add-standalone-freezero.patch
@@ -0,0 +1,51 @@
+From 98a3b77cfa775c87010159d49f5b17d84fe1aa7b Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Tue, 10 Oct 2017 03:07:56 -0700
+Subject: [PATCH] Add standalone freezero
+
+---
+ lib/libc/stdlib/freezero.c | 32 ++++++++++++++++++++++++++++++++
+ 1 file changed, 32 insertions(+)
+ create mode 100644 lib/libc/stdlib/freezero.c
+
+diff --git a/lib/libc/stdlib/freezero.c b/lib/libc/stdlib/freezero.c
+new file mode 100644
+index 00000000000..31face3828b
+--- /dev/null
++++ b/lib/libc/stdlib/freezero.c
+@@ -0,0 +1,32 @@
++/*
++ * Copyright (c) 2008, 2010, 2011, 2016 Otto Moerbeek <otto@drijf.net>
++ * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org>
++ * Copyright (c) 2008 Damien Miller <djm@openbsd.org>
++ * Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org>
++ *
++ * 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 <string.h>
++#include <stdlib.h>
++
++void
++freezero(void *ptr, size_t sz)
++{
++ /* This is legal. */
++ if (ptr == NULL)
++ return;
++
++ explicit_bzero(ptr, sz);
++ free(ptr);
++}
+--
+2.14.2
+
diff --git a/patches/0020-m4-Use-hand-written-lexer-to-avoid-cycle-in-bootstra.patch b/patches/0020-m4-Use-hand-written-lexer-to-avoid-cycle-in-bootstra.patch
new file mode 100644
index 0000000..f58f366
--- /dev/null
+++ b/patches/0020-m4-Use-hand-written-lexer-to-avoid-cycle-in-bootstra.patch
@@ -0,0 +1,327 @@
+From edf250c633bef40e7e37dafc9fc393dd2ad9074f Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Tue, 10 Apr 2018 13:37:14 -0700
+Subject: [PATCH] m4: Use hand-written lexer to avoid cycle in bootstrap
+
+---
+ usr.bin/m4/tokenizer.c | 191 +++++++++++++++++++++++++++++++++++++++++
+ usr.bin/m4/tokenizer.l | 109 -----------------------
+ 2 files changed, 191 insertions(+), 109 deletions(-)
+ create mode 100644 usr.bin/m4/tokenizer.c
+ delete mode 100644 usr.bin/m4/tokenizer.l
+
+diff --git a/usr.bin/m4/tokenizer.c b/usr.bin/m4/tokenizer.c
+new file mode 100644
+index 00000000000..fa19fc65035
+--- /dev/null
++++ b/usr.bin/m4/tokenizer.c
+@@ -0,0 +1,191 @@
++/* $OpenBSD: tokenizer.l,v 1.10 2017/06/17 01:55:16 bcallah Exp $ */
++/*
++ * Copyright (c) 2004 Marc Espie <espie@cvs.openbsd.org>
++ *
++ * 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 "parser.tab.h"
++#include <assert.h>
++#include <ctype.h>
++#include <errno.h>
++#include <limits.h>
++#include <stdbool.h>
++#include <stdio.h>
++#include <stdlib.h>
++#include <stdint.h>
++
++extern void m4_warnx(const char *, ...);
++extern int mimic_gnu;
++extern int32_t yylval;
++static const char *yypos;
++
++void
++yy_scan_string(const char *s)
++{
++ yypos = s;
++}
++
++static int32_t
++number(const char *yytext, size_t yylen)
++{
++ long l;
++
++ errno = 0;
++ l = strtol(yytext, NULL, 0);
++ if (((l == LONG_MAX || l == LONG_MIN) && errno == ERANGE) ||
++ l > INT32_MAX || l < INT32_MIN)
++ m4_warnx("numeric overflow in expr: %.*s", (int)yylen, yytext);
++ return l;
++}
++
++static int32_t
++parse_radix(const char *yytext, size_t yylen)
++{
++ long base;
++ char *next;
++ long l;
++ int d;
++
++ l = 0;
++ base = strtol(yytext+2, &next, 0);
++ if (base > 36 || next == NULL) {
++ m4_warnx("error in number %.*s", (int)yylen, yytext);
++ } else {
++ next++;
++ while (*next != 0) {
++ if (*next >= '0' && *next <= '9')
++ d = *next - '0';
++ else if (*next >= 'a' && *next <= 'z')
++ d = *next - 'a' + 10;
++ else {
++ assert(*next >= 'A' && *next <= 'Z');
++ d = *next - 'A' + 10;
++ }
++ if (d >= base) {
++ m4_warnx("error in number %.*s", (int)yylen, yytext);
++ return 0;
++ }
++ l = base * l + d;
++ next++;
++ }
++ }
++ return l;
++}
++
++static int
++isodigit(int c)
++{
++ return c >= '0' && c <= '7';
++}
++
++int yylex(void)
++{
++ const char *start;
++
++next:
++ start = yypos;
++ switch (*yypos) {
++ case ' ':
++ case '\t':
++ case '\n':
++ ++yypos;
++ goto next;
++ case '<':
++ switch (yypos[1]) {
++ case '=':
++ yypos += 2;
++ return LE;
++ case '<':
++ yypos += 2;
++ return LSHIFT;
++ }
++ break;
++ case '>':
++ switch (yypos[1]) {
++ case '=':
++ yypos += 2;
++ return GE;
++ case '>':
++ yypos += 2;
++ return RSHIFT;
++ }
++ break;
++ case '=':
++ if (yypos[1] != '=')
++ break;
++ yypos += 2;
++ return EQ;
++ case '!':
++ if (yypos[1] != '=')
++ break;
++ yypos += 2;
++ return NE;
++ case '&':
++ if (yypos[1] != '&')
++ break;
++ yypos += 2;
++ return LAND;
++ case '|':
++ if (yypos[1] != '|')
++ break;
++ yypos += 2;
++ return LOR;
++ case '*':
++ if (!mimic_gnu || yypos[1] != '*')
++ break;
++ yypos += 2;
++ return EXPONENT;
++ case '0':
++ switch (*++yypos) {
++ case 'x':
++ case 'X':
++ if (!isxdigit(*++yypos))
++ return ERROR;
++ do ++yypos;
++ while (isxdigit(*yypos));
++ break;
++ case 'r':
++ case 'R':
++ if (!mimic_gnu)
++ break;
++ if (!isdigit(*++yypos))
++ return ERROR;
++ do ++yypos;
++ while (isdigit(*yypos));
++ if (*yypos != ':')
++ return ERROR;
++ if (!isalnum(*++yypos))
++ return ERROR;
++ do ++yypos;
++ while (isalnum(*yypos));
++ yylval = parse_radix(start, yypos - start);
++ return NUMBER;
++ default:
++ do ++yypos;
++ while (isodigit(*yypos));
++ break;
++ }
++ yylval = number(start, yypos - start);
++ return NUMBER;
++ case '\0':
++ return '\0';
++ }
++ if (isdigit(*yypos)) {
++ do ++yypos;
++ while (isdigit(*yypos));
++ yylval = number(start, yypos - start);
++ return NUMBER;
++ }
++
++ return *yypos++;
++}
+diff --git a/usr.bin/m4/tokenizer.l b/usr.bin/m4/tokenizer.l
+deleted file mode 100644
+index 94f02fb6085..00000000000
+--- a/usr.bin/m4/tokenizer.l
++++ /dev/null
+@@ -1,109 +0,0 @@
+-%{
+-/* $OpenBSD: tokenizer.l,v 1.10 2017/06/17 01:55:16 bcallah Exp $ */
+-/*
+- * Copyright (c) 2004 Marc Espie <espie@cvs.openbsd.org>
+- *
+- * 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 "parser.h"
+-#include <assert.h>
+-#include <stdlib.h>
+-#include <errno.h>
+-#include <stdint.h>
+-#include <limits.h>
+-
+-extern void m4_warnx(const char *, ...);
+-extern int mimic_gnu;
+-extern int32_t yylval;
+-
+-int32_t number(void);
+-int32_t parse_radix(void);
+-%}
+-
+-delim [ \t\n]
+-ws {delim}+
+-hex 0[xX][0-9a-fA-F]+
+-oct 0[0-7]*
+-dec [1-9][0-9]*
+-radix 0[rR][0-9]+:[0-9a-zA-Z]+
+-
+-%option noyywrap
+-
+-%%
+-{ws} {/* just skip it */}
+-{hex}|{oct}|{dec} { yylval = number(); return(NUMBER); }
+-{radix} { if (mimic_gnu) {
+- yylval = parse_radix(); return(NUMBER);
+- } else {
+- return(ERROR);
+- }
+- }
+-"<=" { return(LE); }
+-">=" { return(GE); }
+-"<<" { return(LSHIFT); }
+-">>" { return(RSHIFT); }
+-"==" { return(EQ); }
+-"!=" { return(NE); }
+-"&&" { return(LAND); }
+-"||" { return(LOR); }
+-"**" { if (mimic_gnu) { return (EXPONENT); } }
+-. { return yytext[0]; }
+-%%
+-
+-int32_t
+-number()
+-{
+- long l;
+-
+- errno = 0;
+- l = strtol(yytext, NULL, 0);
+- if (((l == LONG_MAX || l == LONG_MIN) && errno == ERANGE) ||
+- l > INT32_MAX || l < INT32_MIN)
+- m4_warnx("numeric overflow in expr: %s", yytext);
+- return l;
+-}
+-
+-int32_t
+-parse_radix()
+-{
+- long base;
+- char *next;
+- long l;
+- int d;
+-
+- l = 0;
+- base = strtol(yytext+2, &next, 0);
+- if (base > 36 || next == NULL) {
+- m4_warnx("error in number %s", yytext);
+- } else {
+- next++;
+- while (*next != 0) {
+- if (*next >= '0' && *next <= '9')
+- d = *next - '0';
+- else if (*next >= 'a' && *next <= 'z')
+- d = *next - 'a' + 10;
+- else {
+- assert(*next >= 'A' && *next <= 'Z');
+- d = *next - 'A' + 10;
+- }
+- if (d >= base) {
+- m4_warnx("error in number %s", yytext);
+- return 0;
+- }
+- l = base * l + d;
+- next++;
+- }
+- }
+- return l;
+-}
+-
+--
+2.17.0
+
diff --git a/patches/0021-m4-Use-_Noreturn-instead-of-__dead.patch b/patches/0021-m4-Use-_Noreturn-instead-of-__dead.patch
new file mode 100644
index 0000000..c78d504
--- /dev/null
+++ b/patches/0021-m4-Use-_Noreturn-instead-of-__dead.patch
@@ -0,0 +1,25 @@
+From 0f0eb43f3d6fb749fac229e3d6c8f74b2c40ece2 Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Tue, 10 Apr 2018 16:03:44 -0700
+Subject: [PATCH] m4: Use _Noreturn instead of __dead
+
+---
+ usr.bin/m4/extern.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/usr.bin/m4/extern.h b/usr.bin/m4/extern.h
+index ea8406b8540..0c07599777d 100644
+--- a/usr.bin/m4/extern.h
++++ b/usr.bin/m4/extern.h
+@@ -113,7 +113,7 @@ extern void usage(void);
+ extern void resizedivs(int);
+ extern size_t buffer_mark(void);
+ extern void dump_buffer(FILE *, size_t);
+-extern void __dead m4errx(int, const char *, ...);
++extern void _Noreturn m4errx(int, const char *, ...);
+
+ extern int obtain_char(struct input_file *);
+ extern void set_input(struct input_file *, FILE *, const char *);
+--
+2.17.0
+
diff --git a/patches/0022-m4-Add-missing-includes.patch b/patches/0022-m4-Add-missing-includes.patch
new file mode 100644
index 0000000..d647009
--- /dev/null
+++ b/patches/0022-m4-Add-missing-includes.patch
@@ -0,0 +1,50 @@
+From 3cc2a61c553d138778a6ec1dd84cd042ce834b4e Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Tue, 10 Apr 2018 16:24:12 -0700
+Subject: [PATCH] m4: Add missing includes
+
+---
+ usr.bin/m4/look.c | 1 +
+ usr.bin/m4/main.c | 1 +
+ usr.bin/m4/parser.y | 1 +
+ 3 files changed, 3 insertions(+)
+
+diff --git a/usr.bin/m4/look.c b/usr.bin/m4/look.c
+index ac504570a9f..5feb0413cd6 100644
+--- a/usr.bin/m4/look.c
++++ b/usr.bin/m4/look.c
+@@ -38,6 +38,7 @@
+ * by: oz
+ */
+
++#include <sys/cdefs.h>
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <stdint.h>
+diff --git a/usr.bin/m4/main.c b/usr.bin/m4/main.c
+index f1b8fa5a55b..4e664c0a50b 100644
+--- a/usr.bin/m4/main.c
++++ b/usr.bin/m4/main.c
+@@ -39,6 +39,7 @@
+ * by: oz
+ */
+
++#include <sys/cdefs.h>
+ #include <assert.h>
+ #include <signal.h>
+ #include <err.h>
+diff --git a/usr.bin/m4/parser.y b/usr.bin/m4/parser.y
+index 5b46d261a9a..fedded1e44c 100644
+--- a/usr.bin/m4/parser.y
++++ b/usr.bin/m4/parser.y
+@@ -17,6 +17,7 @@
+ */
+ #include <math.h>
+ #include <stdint.h>
++#include <stdlib.h>
+ #define YYSTYPE int32_t
+ extern int32_t end_result;
+ extern int yylex(void);
+--
+2.22.0
+
diff --git a/patches/0023-libutil-Add-missing-includes.patch b/patches/0023-libutil-Add-missing-includes.patch
new file mode 100644
index 0000000..c441c19
--- /dev/null
+++ b/patches/0023-libutil-Add-missing-includes.patch
@@ -0,0 +1,24 @@
+From 72cfeec702c7b76cce88be4c411ce40a8abb628c Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Tue, 10 Apr 2018 16:23:22 -0700
+Subject: [PATCH] libutil: Add missing includes
+
+---
+ lib/libutil/ohash.c | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/lib/libutil/ohash.c b/lib/libutil/ohash.c
+index 74ca4fafd9c..9537c60eac4 100644
+--- a/lib/libutil/ohash.c
++++ b/lib/libutil/ohash.c
+@@ -15,6 +15,7 @@
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
++#include <sys/cdefs.h>
+ #include <stddef.h>
+ #include <stdint.h>
+ #include <stdlib.h>
+--
+2.17.0
+
diff --git a/patches/0024-acme-client-Add-missing-includes.patch b/patches/0024-acme-client-Add-missing-includes.patch
new file mode 100644
index 0000000..31f034c
--- /dev/null
+++ b/patches/0024-acme-client-Add-missing-includes.patch
@@ -0,0 +1,25 @@
+From 7ea4349d2ed8afd672348a7d2f3534007e5dc442 Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Mon, 18 Mar 2019 14:52:31 -0700
+Subject: [PATCH] acme-client: Add missing includes
+
+---
+ usr.sbin/acme-client/extern.h | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/usr.sbin/acme-client/extern.h b/usr.sbin/acme-client/extern.h
+index dda2edde4..d83ead634 100644
+--- a/usr.sbin/acme-client/extern.h
++++ b/usr.sbin/acme-client/extern.h
+@@ -17,6 +17,8 @@
+ #ifndef EXTERN_H
+ #define EXTERN_H
+
++#include <sys/cdefs.h>
++#include <sys/types.h>
+ #include "parse.h"
+
+ #define MAX_SERVERS_DNS 8
+--
+2.21.0
+
diff --git a/patches/0025-rsync-Add-missing-includes.patch b/patches/0025-rsync-Add-missing-includes.patch
new file mode 100644
index 0000000..2f632cb
--- /dev/null
+++ b/patches/0025-rsync-Add-missing-includes.patch
@@ -0,0 +1,40 @@
+From ca34590e5d0065db581b3b4c05c9c7aea0015dff Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Fri, 14 Jun 2019 12:40:56 -0700
+Subject: [PATCH] rsync: Add missing includes
+
+- stdio.h in socket.c for sscanf
+- sys/types.h in extern.h for various type definitions
+---
+ usr.bin/rsync/extern.h | 2 ++
+ usr.bin/rsync/socket.c | 1 +
+ 2 files changed, 3 insertions(+)
+
+diff --git a/usr.bin/rsync/extern.h b/usr.bin/rsync/extern.h
+index 305821be579..040588003a4 100644
+--- a/usr.bin/rsync/extern.h
++++ b/usr.bin/rsync/extern.h
+@@ -17,6 +17,8 @@
+ #ifndef EXTERN_H
+ #define EXTERN_H
+
++#include <sys/types.h>
++
+ /*
+ * This is the rsync protocol version that we support.
+ */
+diff --git a/usr.bin/rsync/socket.c b/usr.bin/rsync/socket.c
+index 36384d063a0..43d8d7d01af 100644
+--- a/usr.bin/rsync/socket.c
++++ b/usr.bin/rsync/socket.c
+@@ -28,6 +28,7 @@
+ #include <poll.h>
+ #include <resolv.h>
+ #include <stdlib.h>
++#include <stdio.h>
+ #include <string.h>
+ #include <unistd.h>
+ #include <err.h>
+--
+2.22.0
+
diff --git a/patches/0026-rsync-Use-standard-S_ISVTX-instead-of-S_ISTXT.patch b/patches/0026-rsync-Use-standard-S_ISVTX-instead-of-S_ISTXT.patch
new file mode 100644
index 0000000..39bc650
--- /dev/null
+++ b/patches/0026-rsync-Use-standard-S_ISVTX-instead-of-S_ISTXT.patch
@@ -0,0 +1,34 @@
+From b8ea0a7fc75f79d89f9f225da1112f477419d0bd Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Fri, 14 Jun 2019 12:42:15 -0700
+Subject: [PATCH] rsync: Use standard S_ISVTX instead of S_ISTXT
+
+---
+ usr.bin/rsync/receiver.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/usr.bin/rsync/receiver.c b/usr.bin/rsync/receiver.c
+index 5ffd3458b74..51f9ddf6a5c 100644
+--- a/usr.bin/rsync/receiver.c
++++ b/usr.bin/rsync/receiver.c
+@@ -86,7 +86,7 @@ rsync_set_metadata(struct sess *sess, int newfile,
+ "to user.group: %u.%u", f->path, uid, gid);
+ } else
+ LOG4("%s: updated uid and/or gid", f->path);
+- mode &= ~(S_ISTXT | S_ISUID | S_ISGID);
++ mode &= ~(S_ISVTX | S_ISUID | S_ISGID);
+ }
+
+ /* Conditionally adjust file permissions. */
+@@ -147,7 +147,7 @@ rsync_set_metadata_at(struct sess *sess, int newfile, int rootfd,
+ "to user.group: %u.%u", f->path, uid, gid);
+ } else
+ LOG4("%s: updated uid and/or gid", f->path);
+- mode &= ~(S_ISTXT | S_ISUID | S_ISGID);
++ mode &= ~(S_ISVTX | S_ISUID | S_ISGID);
+ }
+
+ /* Conditionally adjust file permissions. */
+--
+2.23.0
+
diff --git a/patches/0027-rsync-Use-1-instead-of-INFTIM-for-poll-timeout.patch b/patches/0027-rsync-Use-1-instead-of-INFTIM-for-poll-timeout.patch
new file mode 100644
index 0000000..6169131
--- /dev/null
+++ b/patches/0027-rsync-Use-1-instead-of-INFTIM-for-poll-timeout.patch
@@ -0,0 +1,25 @@
+From 588522657724047a2e4c838e62dfff5db41bd506 Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Fri, 14 Jun 2019 12:44:02 -0700
+Subject: [PATCH] rsync: Use -1 instead of INFTIM for poll timeout
+
+---
+ usr.bin/rsync/extern.h | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/usr.bin/rsync/extern.h b/usr.bin/rsync/extern.h
+index 040588003a4..64a02349adc 100644
+--- a/usr.bin/rsync/extern.h
++++ b/usr.bin/rsync/extern.h
+@@ -47,7 +47,7 @@
+ * Use this for debugging deadlocks.
+ * All poll events will use it and catch time-outs.
+ */
+-#define POLL_TIMEOUT (INFTIM)
++#define POLL_TIMEOUT (-1)
+
+ /*
+ * Operating mode for a client or a server.
+--
+2.22.0
+
diff --git a/patches/0028-rsync-Avoid-pointer-arithmetic-on-void.patch b/patches/0028-rsync-Avoid-pointer-arithmetic-on-void.patch
new file mode 100644
index 0000000..885ce49
--- /dev/null
+++ b/patches/0028-rsync-Avoid-pointer-arithmetic-on-void.patch
@@ -0,0 +1,148 @@
+From bae6ab2cb50b4c5784dcd17207f145707c77f317 Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Sat, 15 Jun 2019 20:06:13 -0700
+Subject: [PATCH] rsync: Avoid pointer arithmetic on `void *`
+
+---
+ usr.bin/rsync/blocks.c | 8 ++++----
+ usr.bin/rsync/downloader.c | 2 +-
+ usr.bin/rsync/io.c | 12 ++++++------
+ usr.bin/rsync/sender.c | 4 ++--
+ 4 files changed, 13 insertions(+), 13 deletions(-)
+
+diff --git a/usr.bin/rsync/blocks.c b/usr.bin/rsync/blocks.c
+index 4f21a41833d..242590e5bae 100644
+--- a/usr.bin/rsync/blocks.c
++++ b/usr.bin/rsync/blocks.c
+@@ -157,7 +157,7 @@ blk_find(struct sess *sess, struct blkstat *st,
+ if (!recomp) {
+ fhash = (st->s1 & 0xFFFF) | (st->s2 << 16);
+ } else {
+- fhash = hash_fast(st->map + st->offs, (size_t)osz);
++ fhash = hash_fast((char *)st->map + st->offs, (size_t)osz);
+ st->s1 = fhash & 0xFFFF;
+ st->s2 = fhash >> 16;
+ }
+@@ -170,7 +170,7 @@ blk_find(struct sess *sess, struct blkstat *st,
+ if (st->hint < blks->blksz &&
+ fhash == blks->blks[st->hint].chksum_short &&
+ (size_t)osz == blks->blks[st->hint].len) {
+- hash_slow(st->map + st->offs, (size_t)osz, md, sess);
++ hash_slow((char *)st->map + st->offs, (size_t)osz, md, sess);
+ have_md = 1;
+ if (memcmp(md, blks->blks[st->hint].chksum_long, blks->csum) == 0) {
+ LOG4("%s: found matching hinted match: "
+@@ -203,7 +203,7 @@ blk_find(struct sess *sess, struct blkstat *st,
+ (intmax_t)ent->blk->offs, ent->blk->len);
+
+ if (have_md == 0) {
+- hash_slow(st->map + st->offs, (size_t)osz, md, sess);
++ hash_slow((char *)st->map + st->offs, (size_t)osz, md, sess);
+ have_md = 1;
+ }
+
+@@ -221,7 +221,7 @@ blk_find(struct sess *sess, struct blkstat *st,
+ * block in the sequence.
+ */
+
+- map = st->map + st->offs;
++ map = (char *)st->map + st->offs;
+ st->s1 -= map[0];
+ st->s2 -= osz * map[0];
+
+diff --git a/usr.bin/rsync/downloader.c b/usr.bin/rsync/downloader.c
+index 9ddb8600a73..36b086f74c8 100644
+--- a/usr.bin/rsync/downloader.c
++++ b/usr.bin/rsync/downloader.c
+@@ -495,7 +495,7 @@ again:
+ sz = tok == p->blk.blksz - 1 ? p->blk.rem : p->blk.len;
+ assert(sz);
+ assert(p->map != MAP_FAILED);
+- buf = p->map + (tok * p->blk.len);
++ buf = (char *)p->map + (tok * p->blk.len);
+
+ /*
+ * Now we read from our block.
+diff --git a/usr.bin/rsync/io.c b/usr.bin/rsync/io.c
+index 8d113d6d013..181458ced08 100644
+--- a/usr.bin/rsync/io.c
++++ b/usr.bin/rsync/io.c
+@@ -117,7 +117,7 @@ io_write_blocking(int fd, const void *buf, size_t sz)
+ ERRX("io_write_nonblocking: short write");
+ return 0;
+ }
+- buf += wsz;
++ buf = (char *)buf + wsz;
+ sz -= wsz;
+ }
+
+@@ -156,7 +156,7 @@ io_write_buf(struct sess *sess, int fd, const void *buf, size_t sz)
+ }
+ sess->total_write += wsz;
+ sz -= wsz;
+- buf += wsz;
++ buf = (char *)buf + wsz;
+ }
+
+ return 1;
+@@ -250,7 +250,7 @@ io_read_blocking(int fd, void *buf, size_t sz)
+ ERRX("io_read_nonblocking: short read");
+ return 0;
+ }
+- buf += rsz;
++ buf = (char *)buf + rsz;
+ sz -= rsz;
+ }
+
+@@ -367,7 +367,7 @@ io_read_buf(struct sess *sess, int fd, void *buf, size_t sz)
+ }
+ sz -= rsz;
+ sess->mplex_read_remain -= rsz;
+- buf += rsz;
++ buf = (char *)buf + rsz;
+ sess->total_read += rsz;
+ continue;
+ }
+@@ -463,7 +463,7 @@ io_buffer_buf(void *buf, size_t *bufpos, size_t buflen, const void *val,
+ {
+
+ assert(*bufpos + valsz <= buflen);
+- memcpy(buf + *bufpos, val, valsz);
++ memcpy((char *)buf + *bufpos, val, valsz);
+ *bufpos += valsz;
+ }
+
+@@ -661,7 +661,7 @@ io_unbuffer_buf(const void *buf, size_t *bufpos, size_t bufsz, void *val,
+ {
+
+ assert(*bufpos + valsz <= bufsz);
+- memcpy(val, buf + *bufpos, valsz);
++ memcpy(val, (char *)buf + *bufpos, valsz);
+ *bufpos += valsz;
+ }
+
+diff --git a/usr.bin/rsync/sender.c b/usr.bin/rsync/sender.c
+index 5f9850ee9d2..d6a1f55d1a9 100644
+--- a/usr.bin/rsync/sender.c
++++ b/usr.bin/rsync/sender.c
+@@ -128,7 +128,7 @@ send_up_fsm(struct sess *sess, size_t *phase,
+ return 0;
+ }
+ io_lowbuffer_buf(sess, *wb, &pos, *wbsz,
+- up->stat.map + up->stat.curpos, sz);
++ (char *)up->stat.map + up->stat.curpos, sz);
+
+ up->stat.curpos += sz;
+ if (up->stat.curpos == up->stat.curlen)
+@@ -569,7 +569,7 @@ rsync_sender(struct sess *sess, int fdin,
+ assert(pfd[2].fd == -1);
+ assert(wbufsz - wbufpos);
+ ssz = write(fdout,
+- wbuf + wbufpos, wbufsz - wbufpos);
++ (char *)wbuf + wbufpos, wbufsz - wbufpos);
+ if (ssz == -1) {
+ ERR("write");
+ goto out;
+--
+2.23.0
+
diff --git a/patches/0029-Include-sys-sysmacros.h-if-necessary.patch b/patches/0029-Include-sys-sysmacros.h-if-necessary.patch
new file mode 100644
index 0000000..6b64a04
--- /dev/null
+++ b/patches/0029-Include-sys-sysmacros.h-if-necessary.patch
@@ -0,0 +1,73 @@
+From a8d547a2cf005a00a111394464fc2692f426ceed Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Mon, 5 Aug 2019 21:42:54 -0700
+Subject: [PATCH] Include sys/sysmacros.h if necessary
+
+---
+ bin/pax/cpio.c | 4 ++++
+ bin/pax/gen_subs.c | 3 +++
+ bin/pax/tar.c | 3 +++
+ usr.bin/rsync/flist.c | 4 ++++
+ 4 files changed, 14 insertions(+)
+
+diff --git a/bin/pax/cpio.c b/bin/pax/cpio.c
+index 92fe965163a..3832b1e87aa 100644
+--- a/bin/pax/cpio.c
++++ b/bin/pax/cpio.c
+@@ -41,6 +41,10 @@
+ #include <stdio.h>
+ #include <unistd.h>
+ #include <stdlib.h>
++#ifndef major
++#include <sys/sysmacros.h>
++#endif
++
+ #include "pax.h"
+ #include "cpio.h"
+ #include "extern.h"
+diff --git a/bin/pax/gen_subs.c b/bin/pax/gen_subs.c
+index 42c70804fb7..405dd2c24ed 100644
+--- a/bin/pax/gen_subs.c
++++ b/bin/pax/gen_subs.c
+@@ -45,6 +45,9 @@
+ #include <unistd.h>
+ #include <utmp.h>
+ #include <vis.h>
++#ifndef major
++#include <sys/sysmacros.h>
++#endif
+
+ #include "pax.h"
+ #include "extern.h"
+diff --git a/bin/pax/tar.c b/bin/pax/tar.c
+index a49a5e885fb..3bfa9444dd5 100644
+--- a/bin/pax/tar.c
++++ b/bin/pax/tar.c
+@@ -45,6 +45,9 @@
+ #include <stdlib.h>
+ #include <string.h>
+ #include <unistd.h>
++#ifndef major
++#include <sys/sysmacros.h>
++#endif
+
+ #include "pax.h"
+ #include "extern.h"
+diff --git a/usr.bin/rsync/flist.c b/usr.bin/rsync/flist.c
+index ac29ad47098..9680883ca77 100644
+--- a/usr.bin/rsync/flist.c
++++ b/usr.bin/rsync/flist.c
+@@ -17,6 +17,10 @@
+ */
+ #include <sys/param.h>
+ #include <sys/stat.h>
++#include <sys/types.h>
++#ifndef major
++#include <sys/sysmacros.h>
++#endif
+
+ #include <assert.h>
+ #include <errno.h>
+--
+2.22.0
+
diff --git a/patches/0030-nc-Portability-fixes-from-libressl-portable.patch b/patches/0030-nc-Portability-fixes-from-libressl-portable.patch
new file mode 100644
index 0000000..2c3cb23
--- /dev/null
+++ b/patches/0030-nc-Portability-fixes-from-libressl-portable.patch
@@ -0,0 +1,194 @@
+From 074f2b35512b16c9644c8bd878fa9ace208c17a6 Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Mon, 2 Dec 2019 21:11:04 -0800
+Subject: [PATCH] nc: Portability fixes from libressl-portable
+
+---
+ usr.bin/nc/netcat.c | 55 +++++++++++++++++++++++++++++++++++++++------
+ 1 file changed, 48 insertions(+), 7 deletions(-)
+
+diff --git a/usr.bin/nc/netcat.c b/usr.bin/nc/netcat.c
+index 503095584ad..f052766213e 100644
+--- a/usr.bin/nc/netcat.c
++++ b/usr.bin/nc/netcat.c
+@@ -93,9 +93,13 @@ int zflag; /* Port Scan Flag */
+ int Dflag; /* sodebug */
+ int Iflag; /* TCP receive buffer size */
+ int Oflag; /* TCP send buffer size */
++#ifdef TCP_MD5SIG
+ int Sflag; /* TCP MD5 signature option */
++#endif
+ int Tflag = -1; /* IP Type of Service */
++#ifdef SO_RTABLE
+ int rtableid = -1;
++#endif
+
+ int usetls; /* use TLS */
+ const char *Cflag; /* Public cert file */
+@@ -269,12 +273,14 @@ main(int argc, char *argv[])
+ case 'u':
+ uflag = 1;
+ break;
++#ifdef SO_RTABLE
+ case 'V':
+ rtableid = (int)strtonum(optarg, 0,
+ RT_TABLEID_MAX, &errstr);
+ if (errstr)
+ errx(1, "rtable %s: %s", errstr, optarg);
+ break;
++#endif
+ case 'v':
+ vflag = 1;
+ break;
+@@ -321,9 +327,11 @@ main(int argc, char *argv[])
+ case 'o':
+ oflag = optarg;
+ break;
++#ifdef TCP_MD5SIG
+ case 'S':
+ Sflag = 1;
+ break;
++#endif
+ case 'T':
+ errstr = NULL;
+ errno = 0;
+@@ -347,9 +355,11 @@ main(int argc, char *argv[])
+ argc -= optind;
+ argv += optind;
+
++#ifdef SO_RTABLE
+ if (rtableid >= 0)
+ if (setrtable(rtableid) == -1)
+ err(1, "setrtable");
++#endif
+
+ /* Cruft to make sure options are clean, and used properly. */
+ if (argc == 1 && family == AF_UNIX) {
+@@ -947,7 +957,10 @@ remote_connect(const char *host, const char *port, struct addrinfo hints,
+ char *ipaddr)
+ {
+ struct addrinfo *res, *res0;
+- int s = -1, error, herr, on = 1, save_errno;
++ int s = -1, error, herr, save_errno;
++#ifdef SO_BINDANY
++ int on = 1;
++#endif
+
+ if ((error = getaddrinfo(host, port, &hints, &res0)))
+ errx(1, "getaddrinfo for host \"%s\" port %s: %s", host,
+@@ -962,8 +975,10 @@ remote_connect(const char *host, const char *port, struct addrinfo hints,
+ if (sflag || pflag) {
+ struct addrinfo ahints, *ares;
+
++#ifdef SO_BINDANY
+ /* try SO_BINDANY, but don't insist */
+ setsockopt(s, SOL_SOCKET, SO_BINDANY, &on, sizeof(on));
++#endif
+ memset(&ahints, 0, sizeof(struct addrinfo));
+ ahints.ai_family = res->ai_family;
+ ahints.ai_socktype = uflag ? SOCK_DGRAM : SOCK_STREAM;
+@@ -1055,8 +1070,11 @@ int
+ local_listen(const char *host, const char *port, struct addrinfo hints)
+ {
+ struct addrinfo *res, *res0;
+- int s = -1, ret, x = 1, save_errno;
++ int s = -1, save_errno;
+ int error;
++#ifdef SO_REUSEPORT
++ int ret, x = 1;
++#endif
+
+ /* Allow nodename to be null. */
+ hints.ai_flags |= AI_PASSIVE;
+@@ -1076,9 +1094,11 @@ local_listen(const char *host, const char *port, struct addrinfo hints)
+ res->ai_protocol)) == -1)
+ continue;
+
++#ifdef SO_REUSEPORT
+ ret = setsockopt(s, SOL_SOCKET, SO_REUSEPORT, &x, sizeof(x));
+ if (ret == -1)
+ err(1, NULL);
++#endif
+
+ set_common_sockopts(s, res->ai_family);
+
+@@ -1548,11 +1568,13 @@ set_common_sockopts(int s, int af)
+ {
+ int x = 1;
+
++#ifdef TCP_MD5SIG
+ if (Sflag) {
+ if (setsockopt(s, IPPROTO_TCP, TCP_MD5SIG,
+ &x, sizeof(x)) == -1)
+ err(1, NULL);
+ }
++#endif
+ if (Dflag) {
+ if (setsockopt(s, SOL_SOCKET, SO_DEBUG,
+ &x, sizeof(x)) == -1)
+@@ -1563,9 +1585,16 @@ set_common_sockopts(int s, int af)
+ IP_TOS, &Tflag, sizeof(Tflag)) == -1)
+ err(1, "set IP ToS");
+
++#ifdef IPV6_TCLASS
+ else if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
+ IPV6_TCLASS, &Tflag, sizeof(Tflag)) == -1)
+ err(1, "set IPv6 traffic class");
++#else
++ else if (af == AF_INET6) {
++ errno = ENOPROTOOPT;
++ err(1, "set IPv6 traffic class not supported");
++ }
++#endif
+ }
+ if (Iflag) {
+ if (setsockopt(s, SOL_SOCKET, SO_RCVBUF,
+@@ -1589,13 +1618,17 @@ set_common_sockopts(int s, int af)
+ }
+
+ if (minttl != -1) {
++#ifdef IP_MINTTL
+ if (af == AF_INET && setsockopt(s, IPPROTO_IP,
+ IP_MINTTL, &minttl, sizeof(minttl)))
+ err(1, "set IP min TTL");
++#endif
+
+- else if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
++#ifdef IPV6_MINHOPCOUNT
++ if (af == AF_INET6 && setsockopt(s, IPPROTO_IPV6,
+ IPV6_MINHOPCOUNT, &minttl, sizeof(minttl)))
+ err(1, "set IPv6 min hop count");
++#endif
+ }
+ }
+
+@@ -1820,14 +1853,22 @@ help(void)
+ \t-P proxyuser\tUsername for proxy authentication\n\
+ \t-p port\t Specify local port for remote connects\n\
+ \t-R CAfile CA bundle\n\
+- \t-r Randomize remote ports\n\
+- \t-S Enable the TCP MD5 signature option\n\
++ \t-r Randomize remote ports\n"
++#ifdef TCP_MD5SIG
++ "\
++ \t-S Enable the TCP MD5 signature option\n"
++#endif
++ "\
+ \t-s sourceaddr Local source address\n\
+ \t-T keyword TOS value or TLS options\n\
+ \t-t Answer TELNET negotiation\n\
+ \t-U Use UNIX domain socket\n\
+- \t-u UDP mode\n\
+- \t-V rtable Specify alternate routing table\n\
++ \t-u UDP mode\n"
++#ifdef SO_RTABLE
++ "\
++ \t-V rtable Specify alternate routing table\n"
++#endif
++ "\
+ \t-v Verbose\n\
+ \t-W recvlimit Terminate after receiving a number of packets\n\
+ \t-w timeout Timeout for connects and final net reads\n\
+--
+2.26.2
+
diff --git a/patches/0031-pax-Ignore-EOPNOTSUPP-from-fchmodat.patch b/patches/0031-pax-Ignore-EOPNOTSUPP-from-fchmodat.patch
new file mode 100644
index 0000000..2b0a5f2
--- /dev/null
+++ b/patches/0031-pax-Ignore-EOPNOTSUPP-from-fchmodat.patch
@@ -0,0 +1,26 @@
+From 0f49ae38698a163f7954d28bbaba473b6bf28239 Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Fri, 10 Jan 2020 21:40:03 -0800
+Subject: [PATCH] pax: Ignore EOPNOTSUPP from fchmodat
+
+Linux does not support changing the mode of symlinks.
+---
+ bin/pax/file_subs.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/bin/pax/file_subs.c b/bin/pax/file_subs.c
+index 8aa3d249923..2c0994feca6 100644
+--- a/bin/pax/file_subs.c
++++ b/bin/pax/file_subs.c
+@@ -795,7 +795,7 @@ void
+ set_pmode(char *fnm, mode_t mode)
+ {
+ mode &= ABITS;
+- if (fchmodat(AT_FDCWD, fnm, mode, AT_SYMLINK_NOFOLLOW) == -1)
++ if (fchmodat(AT_FDCWD, fnm, mode, AT_SYMLINK_NOFOLLOW) == -1 && errno != EOPNOTSUPP)
+ syswarn(1, errno, "Could not set permissions on %s", fnm);
+ }
+
+--
+2.26.2
+
diff --git a/patches/0032-acme-client-Fix-build-with-old-bison-versions.patch b/patches/0032-acme-client-Fix-build-with-old-bison-versions.patch
new file mode 100644
index 0000000..5063920
--- /dev/null
+++ b/patches/0032-acme-client-Fix-build-with-old-bison-versions.patch
@@ -0,0 +1,24 @@
+From c3aab43559f17feb64a29f8b0d395532cb423e8b Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Wed, 15 Apr 2020 20:26:16 -0700
+Subject: [PATCH] acme-client: Fix build with old bison versions
+
+---
+ usr.sbin/acme-client/parse.y | 1 +
+ 1 file changed, 1 insertion(+)
+
+diff --git a/usr.sbin/acme-client/parse.y b/usr.sbin/acme-client/parse.y
+index 20818328d92..f392e516b63 100644
+--- a/usr.sbin/acme-client/parse.y
++++ b/usr.sbin/acme-client/parse.y
+@@ -97,6 +97,7 @@ typedef struct {
+ } v;
+ int lineno;
+ } YYSTYPE;
++#define YYSTYPE_IS_DECLARED 1
+
+ %}
+
+--
+2.26.1
+
diff --git a/patches/0033-rsync-Add-implementation-of-MD4.patch b/patches/0033-rsync-Add-implementation-of-MD4.patch
new file mode 100644
index 0000000..fc02ee8
--- /dev/null
+++ b/patches/0033-rsync-Add-implementation-of-MD4.patch
@@ -0,0 +1,414 @@
+From 7fd1cb22e4d028d19ae1a02e50a6fac2c8e26773 Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Wed, 15 Apr 2020 22:10:06 -0700
+Subject: [PATCH] rsync: Add implementation of MD4
+
+---
+ usr.bin/rsync/Makefile | 6 +-
+ usr.bin/rsync/blocks.c | 2 +-
+ usr.bin/rsync/downloader.c | 2 +-
+ usr.bin/rsync/hash.c | 2 +-
+ usr.bin/rsync/md4.c | 266 +++++++++++++++++++++++++++++++++++++
+ usr.bin/rsync/md4.h | 47 +++++++
+ usr.bin/rsync/sender.c | 2 +-
+ 7 files changed, 320 insertions(+), 7 deletions(-)
+ create mode 100644 usr.bin/rsync/md4.c
+ create mode 100644 usr.bin/rsync/md4.h
+
+diff --git a/usr.bin/rsync/Makefile b/usr.bin/rsync/Makefile
+index d7af8bd0a87..e04a0268392 100644
+--- a/usr.bin/rsync/Makefile
++++ b/usr.bin/rsync/Makefile
+@@ -3,9 +3,9 @@
+ PROG= openrsync
+ SRCS= blocks.c client.c downloader.c fargs.c flist.c hash.c ids.c \
+ io.c log.c mkpath.c mktemp.c receiver.c sender.c server.c session.c \
+- socket.c symlinks.c uploader.c main.c misc.c
+-LDADD+= -lcrypto -lm
+-DPADD+= ${LIBCRYPTO} ${LIBM}
++ socket.c symlinks.c uploader.c main.c misc.c md4.c
++LDADD+= -lm
++DPADD+= ${LIBM}
+ MAN= openrsync.1
+
+ CFLAGS+=-g -W -Wall -Wextra
+diff --git a/usr.bin/rsync/blocks.c b/usr.bin/rsync/blocks.c
+index 242590e5bae..8c1564005e2 100644
+--- a/usr.bin/rsync/blocks.c
++++ b/usr.bin/rsync/blocks.c
+@@ -26,7 +26,7 @@
+ #include <string.h>
+ #include <unistd.h>
+
+-#include <openssl/md4.h>
++#include "md4.h"
+
+ #include "extern.h"
+
+diff --git a/usr.bin/rsync/downloader.c b/usr.bin/rsync/downloader.c
+index 36b086f74c8..26d1b531f85 100644
+--- a/usr.bin/rsync/downloader.c
++++ b/usr.bin/rsync/downloader.c
+@@ -28,7 +28,7 @@
+ #include <time.h>
+ #include <unistd.h>
+
+-#include <openssl/md4.h>
++#include "md4.h"
+
+ #include "extern.h"
+
+diff --git a/usr.bin/rsync/hash.c b/usr.bin/rsync/hash.c
+index edad21f13a6..6cb131b4b3e 100644
+--- a/usr.bin/rsync/hash.c
++++ b/usr.bin/rsync/hash.c
+@@ -21,7 +21,7 @@
+ #include <stdint.h>
+ #include <stdlib.h>
+
+-#include <openssl/md4.h>
++#include "md4.h"
+
+ #include "extern.h"
+
+diff --git a/usr.bin/rsync/md4.c b/usr.bin/rsync/md4.c
+new file mode 100644
+index 00000000000..528f985563f
+--- /dev/null
++++ b/usr.bin/rsync/md4.c
+@@ -0,0 +1,266 @@
++/*
++ * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
++ * MD4 Message-Digest Algorithm (RFC 1320).
++ *
++ * Homepage:
++ * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md4
++ *
++ * Author:
++ * Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
++ *
++ * This software was written by Alexander Peslyak in 2001. No copyright is
++ * claimed, and the software is hereby placed in the public domain.
++ * In case this attempt to disclaim copyright and place the software in the
++ * public domain is deemed null and void, then the software is
++ * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
++ * general public under the following terms:
++ *
++ * Redistribution and use in source and binary forms, with or without
++ * modification, are permitted.
++ *
++ * There's ABSOLUTELY NO WARRANTY, express or implied.
++ *
++ * (This is a heavily cut-down "BSD license".)
++ *
++ * This differs from Colin Plumb's older public domain implementation in that
++ * no exactly 32-bit integer data type is required (any 32-bit or wider
++ * unsigned integer data type will do), there's no compile-time endianness
++ * configuration, and the function prototypes match OpenSSL's. No code from
++ * Colin Plumb's implementation has been reused; this comment merely compares
++ * the properties of the two independent implementations.
++ *
++ * The primary goals of this implementation are portability and ease of use.
++ * It is meant to be fast, but not as fast as possible. Some known
++ * optimizations are not included to reduce source code size and avoid
++ * compile-time configuration.
++ */
++
++#include <string.h>
++
++#include "md4.h"
++
++/*
++ * The basic MD4 functions.
++ *
++ * F and G are optimized compared to their RFC 1320 definitions, with the
++ * optimization for F borrowed from Colin Plumb's MD5 implementation.
++ */
++#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
++#define G(x, y, z) (((x) & ((y) | (z))) | ((y) & (z)))
++#define H(x, y, z) ((x) ^ (y) ^ (z))
++
++/*
++ * The MD4 transformation for all three rounds.
++ */
++#define STEP(f, a, b, c, d, x, s) \
++ (a) += f((b), (c), (d)) + (x); \
++ (a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s))));
++
++/*
++ * SET reads 4 input bytes in little-endian byte order and stores them in a
++ * properly aligned word in host byte order.
++ *
++ * The check for little-endian architectures that tolerate unaligned memory
++ * accesses is just an optimization. Nothing will break if it fails to detect
++ * a suitable architecture.
++ *
++ * Unfortunately, this optimization may be a C strict aliasing rules violation
++ * if the caller's data buffer has effective type that cannot be aliased by
++ * MD4_u32plus. In practice, this problem may occur if these MD4 routines are
++ * inlined into a calling function, or with future and dangerously advanced
++ * link-time optimizations. For the time being, keeping these MD4 routines in
++ * their own translation unit avoids the problem.
++ */
++#if defined(__i386__) || defined(__x86_64__) || defined(__vax__)
++#define SET(n) \
++ (*(MD4_u32plus *)&ptr[(n) * 4])
++#define GET(n) \
++ SET(n)
++#else
++#define SET(n) \
++ (ctx->block[(n)] = \
++ (MD4_u32plus)ptr[(n) * 4] | \
++ ((MD4_u32plus)ptr[(n) * 4 + 1] << 8) | \
++ ((MD4_u32plus)ptr[(n) * 4 + 2] << 16) | \
++ ((MD4_u32plus)ptr[(n) * 4 + 3] << 24))
++#define GET(n) \
++ (ctx->block[(n)])
++#endif
++
++/*
++ * This processes one or more 64-byte data blocks, but does NOT update the bit
++ * counters. There are no alignment requirements.
++ */
++static const void *body(MD4_CTX *ctx, const void *data, unsigned long size)
++{
++ const unsigned char *ptr;
++ MD4_u32plus a, b, c, d;
++ MD4_u32plus saved_a, saved_b, saved_c, saved_d;
++ const MD4_u32plus ac1 = 0x5a827999, ac2 = 0x6ed9eba1;
++
++ ptr = (const unsigned char *)data;
++
++ a = ctx->a;
++ b = ctx->b;
++ c = ctx->c;
++ d = ctx->d;
++
++ do {
++ saved_a = a;
++ saved_b = b;
++ saved_c = c;
++ saved_d = d;
++
++/* Round 1 */
++ STEP(F, a, b, c, d, SET(0), 3)
++ STEP(F, d, a, b, c, SET(1), 7)
++ STEP(F, c, d, a, b, SET(2), 11)
++ STEP(F, b, c, d, a, SET(3), 19)
++ STEP(F, a, b, c, d, SET(4), 3)
++ STEP(F, d, a, b, c, SET(5), 7)
++ STEP(F, c, d, a, b, SET(6), 11)
++ STEP(F, b, c, d, a, SET(7), 19)
++ STEP(F, a, b, c, d, SET(8), 3)
++ STEP(F, d, a, b, c, SET(9), 7)
++ STEP(F, c, d, a, b, SET(10), 11)
++ STEP(F, b, c, d, a, SET(11), 19)
++ STEP(F, a, b, c, d, SET(12), 3)
++ STEP(F, d, a, b, c, SET(13), 7)
++ STEP(F, c, d, a, b, SET(14), 11)
++ STEP(F, b, c, d, a, SET(15), 19)
++
++/* Round 2 */
++ STEP(G, a, b, c, d, GET(0) + ac1, 3)
++ STEP(G, d, a, b, c, GET(4) + ac1, 5)
++ STEP(G, c, d, a, b, GET(8) + ac1, 9)
++ STEP(G, b, c, d, a, GET(12) + ac1, 13)
++ STEP(G, a, b, c, d, GET(1) + ac1, 3)
++ STEP(G, d, a, b, c, GET(5) + ac1, 5)
++ STEP(G, c, d, a, b, GET(9) + ac1, 9)
++ STEP(G, b, c, d, a, GET(13) + ac1, 13)
++ STEP(G, a, b, c, d, GET(2) + ac1, 3)
++ STEP(G, d, a, b, c, GET(6) + ac1, 5)
++ STEP(G, c, d, a, b, GET(10) + ac1, 9)
++ STEP(G, b, c, d, a, GET(14) + ac1, 13)
++ STEP(G, a, b, c, d, GET(3) + ac1, 3)
++ STEP(G, d, a, b, c, GET(7) + ac1, 5)
++ STEP(G, c, d, a, b, GET(11) + ac1, 9)
++ STEP(G, b, c, d, a, GET(15) + ac1, 13)
++
++/* Round 3 */
++ STEP(H, a, b, c, d, GET(0) + ac2, 3)
++ STEP(H, d, a, b, c, GET(8) + ac2, 9)
++ STEP(H, c, d, a, b, GET(4) + ac2, 11)
++ STEP(H, b, c, d, a, GET(12) + ac2, 15)
++ STEP(H, a, b, c, d, GET(2) + ac2, 3)
++ STEP(H, d, a, b, c, GET(10) + ac2, 9)
++ STEP(H, c, d, a, b, GET(6) + ac2, 11)
++ STEP(H, b, c, d, a, GET(14) + ac2, 15)
++ STEP(H, a, b, c, d, GET(1) + ac2, 3)
++ STEP(H, d, a, b, c, GET(9) + ac2, 9)
++ STEP(H, c, d, a, b, GET(5) + ac2, 11)
++ STEP(H, b, c, d, a, GET(13) + ac2, 15)
++ STEP(H, a, b, c, d, GET(3) + ac2, 3)
++ STEP(H, d, a, b, c, GET(11) + ac2, 9)
++ STEP(H, c, d, a, b, GET(7) + ac2, 11)
++ STEP(H, b, c, d, a, GET(15) + ac2, 15)
++
++ a += saved_a;
++ b += saved_b;
++ c += saved_c;
++ d += saved_d;
++
++ ptr += 64;
++ } while (size -= 64);
++
++ ctx->a = a;
++ ctx->b = b;
++ ctx->c = c;
++ ctx->d = d;
++
++ return ptr;
++}
++
++void MD4_Init(MD4_CTX *ctx)
++{
++ ctx->a = 0x67452301;
++ ctx->b = 0xefcdab89;
++ ctx->c = 0x98badcfe;
++ ctx->d = 0x10325476;
++
++ ctx->lo = 0;
++ ctx->hi = 0;
++}
++
++void MD4_Update(MD4_CTX *ctx, const void *data, unsigned long size)
++{
++ MD4_u32plus saved_lo;
++ unsigned long used, available;
++
++ saved_lo = ctx->lo;
++ if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
++ ctx->hi++;
++ ctx->hi += size >> 29;
++
++ used = saved_lo & 0x3f;
++
++ if (used) {
++ available = 64 - used;
++
++ if (size < available) {
++ memcpy(&ctx->buffer[used], data, size);
++ return;
++ }
++
++ memcpy(&ctx->buffer[used], data, available);
++ data = (const unsigned char *)data + available;
++ size -= available;
++ body(ctx, ctx->buffer, 64);
++ }
++
++ if (size >= 64) {
++ data = body(ctx, data, size & ~(unsigned long)0x3f);
++ size &= 0x3f;
++ }
++
++ memcpy(ctx->buffer, data, size);
++}
++
++#define OUT(dst, src) \
++ (dst)[0] = (unsigned char)(src); \
++ (dst)[1] = (unsigned char)((src) >> 8); \
++ (dst)[2] = (unsigned char)((src) >> 16); \
++ (dst)[3] = (unsigned char)((src) >> 24);
++
++void MD4_Final(unsigned char *result, MD4_CTX *ctx)
++{
++ unsigned long used, available;
++
++ used = ctx->lo & 0x3f;
++
++ ctx->buffer[used++] = 0x80;
++
++ available = 64 - used;
++
++ if (available < 8) {
++ memset(&ctx->buffer[used], 0, available);
++ body(ctx, ctx->buffer, 64);
++ used = 0;
++ available = 64;
++ }
++
++ memset(&ctx->buffer[used], 0, available - 8);
++
++ ctx->lo <<= 3;
++ OUT(&ctx->buffer[56], ctx->lo)
++ OUT(&ctx->buffer[60], ctx->hi)
++
++ body(ctx, ctx->buffer, 64);
++
++ OUT(&result[0], ctx->a)
++ OUT(&result[4], ctx->b)
++ OUT(&result[8], ctx->c)
++ OUT(&result[12], ctx->d)
++
++ memset(ctx, 0, sizeof(*ctx));
++}
+diff --git a/usr.bin/rsync/md4.h b/usr.bin/rsync/md4.h
+new file mode 100644
+index 00000000000..ebf5bb555a0
+--- /dev/null
++++ b/usr.bin/rsync/md4.h
+@@ -0,0 +1,47 @@
++/*
++ * This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
++ * MD4 Message-Digest Algorithm (RFC 1320).
++ *
++ * Homepage:
++ * http://openwall.info/wiki/people/solar/software/public-domain-source-code/md4
++ *
++ * Author:
++ * Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
++ *
++ * This software was written by Alexander Peslyak in 2001. No copyright is
++ * claimed, and the software is hereby placed in the public domain.
++ * In case this attempt to disclaim copyright and place the software in the
++ * public domain is deemed null and void, then the software is
++ * Copyright (c) 2001 Alexander Peslyak and it is hereby released to the
++ * general public under the following terms:
++ *
++ * Redistribution and use in source and binary forms, with or without
++ * modification, are permitted.
++ *
++ * There's ABSOLUTELY NO WARRANTY, express or implied.
++ *
++ * See md4.c for more information.
++ */
++
++#ifndef _MD4_H
++#define _MD4_H
++
++#include <stdint.h>
++
++#define MD4_DIGEST_LENGTH 16
++
++/* Any 32-bit or wider unsigned integer data type will do */
++typedef uint_fast32_t MD4_u32plus;
++
++typedef struct {
++ MD4_u32plus lo, hi;
++ MD4_u32plus a, b, c, d;
++ unsigned char buffer[64];
++ MD4_u32plus block[16];
++} MD4_CTX;
++
++extern void MD4_Init(MD4_CTX *ctx);
++extern void MD4_Update(MD4_CTX *ctx, const void *data, unsigned long size);
++extern void MD4_Final(unsigned char *result, MD4_CTX *ctx);
++
++#endif
+diff --git a/usr.bin/rsync/sender.c b/usr.bin/rsync/sender.c
+index d6a1f55d1a9..3dacfc3709d 100644
+--- a/usr.bin/rsync/sender.c
++++ b/usr.bin/rsync/sender.c
+@@ -26,7 +26,7 @@
+ #include <string.h>
+ #include <unistd.h>
+
+-#include <openssl/md4.h>
++#include "md4.h"
+
+ #include "extern.h"
+
+--
+2.26.1
+
diff --git a/patches/0034-pax-Fix-some-incorrect-format-specifiers.patch b/patches/0034-pax-Fix-some-incorrect-format-specifiers.patch
new file mode 100644
index 0000000..05dd7d3
--- /dev/null
+++ b/patches/0034-pax-Fix-some-incorrect-format-specifiers.patch
@@ -0,0 +1,48 @@
+From f855b534ca2c34c3691a0c89d1be482a33a3610c Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Thu, 4 Jun 2020 21:36:11 -0700
+Subject: [PATCH] pax: Fix some incorrect format specifiers
+
+---
+ bin/pax/cpio.c | 2 +-
+ bin/pax/gen_subs.c | 4 ++--
+ 2 files changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/bin/pax/cpio.c b/bin/pax/cpio.c
+index 3832b1e87aa..769a9dfb990 100644
+--- a/bin/pax/cpio.c
++++ b/bin/pax/cpio.c
+@@ -214,7 +214,7 @@ rd_ln_nm(ARCHD *arcn)
+ */
+ if ((arcn->sb.st_size <= 0) ||
+ (arcn->sb.st_size >= (off_t)sizeof(arcn->ln_name))) {
+- paxwarn(1, "Cpio link name length is invalid: %lld",
++ paxwarn(1, "Cpio link name length is invalid: %zu",
+ arcn->sb.st_size);
+ return(-1);
+ }
+diff --git a/bin/pax/gen_subs.c b/bin/pax/gen_subs.c
+index 405dd2c24ed..7eb82007e3b 100644
+--- a/bin/pax/gen_subs.c
++++ b/bin/pax/gen_subs.c
+@@ -109,7 +109,7 @@ ls_list(ARCHD *arcn, time_t now, FILE *fp)
+ if (strftime(f_date, sizeof(f_date), TIMEFMT(sbp->st_mtime, now),
+ localtime(&(sbp->st_mtime))) == 0)
+ f_date[0] = '\0';
+- (void)fprintf(fp, "%s%2u %-*.*s %-*.*s ", f_mode, sbp->st_nlink,
++ (void)fprintf(fp, "%s%2u %-*.*s %-*.*s ", f_mode, (unsigned)sbp->st_nlink,
+ NAME_WIDTH, UT_NAMESIZE, user_from_uid(sbp->st_uid, 0),
+ NAME_WIDTH, UT_NAMESIZE, group_from_gid(sbp->st_gid, 0));
+
+@@ -121,7 +121,7 @@ ls_list(ARCHD *arcn, time_t now, FILE *fp)
+ (unsigned long)MAJOR(sbp->st_rdev),
+ (unsigned long)MINOR(sbp->st_rdev));
+ else {
+- (void)fprintf(fp, "%9llu ", sbp->st_size);
++ (void)fprintf(fp, "%9zu ", sbp->st_size);
+ }
+
+ /*
+--
+2.27.0
+
diff --git a/patches/0035-pax-Use-memcpy-to-set-TMAGIC-and-TVERSION-to-avoid-w.patch b/patches/0035-pax-Use-memcpy-to-set-TMAGIC-and-TVERSION-to-avoid-w.patch
new file mode 100644
index 0000000..ecf17ad
--- /dev/null
+++ b/patches/0035-pax-Use-memcpy-to-set-TMAGIC-and-TVERSION-to-avoid-w.patch
@@ -0,0 +1,27 @@
+From b6eaf185d9a9c39e31c638ac162ec5f5a364e94d Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Thu, 4 Jun 2020 21:44:26 -0700
+Subject: [PATCH] pax: Use memcpy to set TMAGIC and TVERSION to avoid warning
+
+---
+ bin/pax/tar.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/bin/pax/tar.c b/bin/pax/tar.c
+index 8c9e4baea9c..c62705b2199 100644
+--- a/bin/pax/tar.c
++++ b/bin/pax/tar.c
+@@ -1030,8 +1030,8 @@ ustar_wr(ARCHD *arcn)
+ break;
+ }
+
+- strncpy(hd->magic, TMAGIC, TMAGLEN);
+- strncpy(hd->version, TVERSION, TVERSLEN);
++ memcpy(hd->magic, TMAGIC, TMAGLEN);
++ memcpy(hd->version, TVERSION, TVERSLEN);
+
+ /*
+ * set the remaining fields. Some versions want all 16 bits of mode
+--
+2.27.0
+
diff --git a/patches/0036-rsync-Fix-some-incorrect-format-specifiers.patch b/patches/0036-rsync-Fix-some-incorrect-format-specifiers.patch
new file mode 100644
index 0000000..14d9a00
--- /dev/null
+++ b/patches/0036-rsync-Fix-some-incorrect-format-specifiers.patch
@@ -0,0 +1,25 @@
+From dbec208559b72489671f119e695a4c340a288803 Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Thu, 4 Jun 2020 21:36:24 -0700
+Subject: [PATCH] rsync: Fix some incorrect format specifiers
+
+---
+ usr.bin/rsync/uploader.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/usr.bin/rsync/uploader.c b/usr.bin/rsync/uploader.c
+index 38d5d24fcc7..bf82896d221 100644
+--- a/usr.bin/rsync/uploader.c
++++ b/usr.bin/rsync/uploader.c
+@@ -945,7 +945,7 @@ rsync_uploader(struct upload *u, int *fileinfd,
+ init_blk(&blk.blks[i], &blk, offs, i, mbuf, sess);
+ offs += blk.len;
+ LOG3(
+- "i=%ld, offs=%lld, msz=%ld, blk.len=%lu, blk.rem=%lu",
++ "i=%zu, offs=%td, msz=%zd, blk.len=%zu, blk.rem=%zu",
+ i, offs, msz, blk.len, blk.rem);
+ i++;
+ } while (i < blk.blksz);
+--
+2.27.0
+
diff --git a/patches/0037-m4-Declare-dopaste-only-when-it-s-used.patch b/patches/0037-m4-Declare-dopaste-only-when-it-s-used.patch
new file mode 100644
index 0000000..3d3ccfd
--- /dev/null
+++ b/patches/0037-m4-Declare-dopaste-only-when-it-s-used.patch
@@ -0,0 +1,26 @@
+From 666a050e706230ba5b0316a316100d8c7e86c93c Mon Sep 17 00:00:00 2001
+From: Michael Forney <mforney@mforney.org>
+Date: Thu, 4 Jun 2020 21:42:18 -0700
+Subject: [PATCH] m4: Declare dopaste only when it's used
+
+---
+ usr.bin/m4/eval.c | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/usr.bin/m4/eval.c b/usr.bin/m4/eval.c
+index d226505cab3..fe9fbde3d9c 100644
+--- a/usr.bin/m4/eval.c
++++ b/usr.bin/m4/eval.c
+@@ -61,7 +61,9 @@ static void dodump(const char *[], int);
+ static void dotrace(const char *[], int, int);
+ static void doifelse(const char *[], int);
+ static int doincl(const char *);
++#ifdef EXTENDED
+ static int dopaste(const char *);
++#endif
+ static void dochq(const char *[], int);
+ static void dochc(const char *[], int);
+ static void dom4wrap(const char *);
+--
+2.27.0
+
diff --git a/patches/0038-sha2-add-missing-include.patch b/patches/0038-sha2-add-missing-include.patch
new file mode 100644
index 0000000..3bde964
--- /dev/null
+++ b/patches/0038-sha2-add-missing-include.patch
@@ -0,0 +1,11 @@
+--- a/lib/libc/hash/sha2.c 2019-07-23 15:35:22.000000000 +0300
++++ b/lib/libc/hash/sha2.c 2020-10-15 16:36:04.849056534 +0300
+@@ -35,6 +35,8 @@
+ */
+
+ #include <sys/types.h>
++#include <sys/cdefs.h>
++#include <sys/compat.h>
+
+ #include <string.h>
+ #include <sha2.h>
diff --git a/patches/0039-bcrypt-add-cdefs.patch b/patches/0039-bcrypt-add-cdefs.patch
new file mode 100644
index 0000000..1182442
--- /dev/null
+++ b/patches/0039-bcrypt-add-cdefs.patch
@@ -0,0 +1,10 @@
+--- a/lib/libutil/bcrypt_pbkdf.c 2019-11-21 19:13:39.000000000 +0300
++++ b/lib/libutil/bcrypt_pbkdf.c 2020-10-15 17:25:45.569164914 +0300
+@@ -16,6 +16,7 @@
+ */
+
+ #include <sys/types.h>
++#include <sys/cdefs.h>
+
+ #include <stdint.h>
+ #include <stdlib.h>
diff --git a/patches/0040-mandoc-port-to-musl.patch b/patches/0040-mandoc-port-to-musl.patch
new file mode 100644
index 0000000..fe2b769
--- /dev/null
+++ b/patches/0040-mandoc-port-to-musl.patch
@@ -0,0 +1,159 @@
+Apart from some definitions and includes, this patch also removes the LESS -T
+call so that other implementations of LESS (such as busybox) work as well.
+diff -upr a/usr.bin/mandoc/chars.c b/usr.bin/mandoc/chars.c
+--- a/usr.bin/mandoc/chars.c 2020-02-13 19:16:03.000000000 +0300
++++ b/usr.bin/mandoc/chars.c 2020-10-15 20:28:37.865510442 +0300
+@@ -16,6 +16,7 @@
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
++#include <sys/cdefs.h>
+ #include <sys/types.h>
+
+ #include <assert.h>
+diff -upr a/usr.bin/mandoc/dba.c b/usr.bin/mandoc/dba.c
+--- a/usr.bin/mandoc/dba.c 2017-02-09 21:26:17.000000000 +0300
++++ b/usr.bin/mandoc/dba.c 2020-10-15 20:14:07.403360262 +0300
+@@ -17,6 +17,7 @@
+ * Allocation-based version of the mandoc database, for read-write access.
+ * The interface is defined in "dba.h".
+ */
++#include <sys/cdefs.h>
+ #include <sys/types.h>
+ #include <endian.h>
+ #include <errno.h>
+diff -upr a/usr.bin/mandoc/dbm.c b/usr.bin/mandoc/dbm.c
+--- a/usr.bin/mandoc/dbm.c 2019-07-02 01:43:03.000000000 +0300
++++ b/usr.bin/mandoc/dbm.c 2020-10-15 20:15:44.217488475 +0300
+@@ -31,6 +31,10 @@
+ #include "dbm_map.h"
+ #include "dbm.h"
+
++#ifndef EFTYPE
++#define EFTYPE 79
++#endif
++
+ struct macro {
+ int32_t value;
+ int32_t pages;
+diff -upr a/usr.bin/mandoc/dbm_map.c b/usr.bin/mandoc/dbm_map.c
+--- a/usr.bin/mandoc/dbm_map.c 2017-02-09 21:26:17.000000000 +0300
++++ b/usr.bin/mandoc/dbm_map.c 2020-10-15 20:16:40.740563806 +0300
+@@ -36,6 +36,10 @@
+ #include "dbm_map.h"
+ #include "dbm.h"
+
++#ifndef EFTYPE
++#define EFTYPE 79
++#endif
++
+ static struct stat st;
+ static char *dbm_base;
+ static int ifd;
+diff -upr a/usr.bin/mandoc/html.c b/usr.bin/mandoc/html.c
+--- a/usr.bin/mandoc/html.c 2020-04-20 15:59:24.000000000 +0300
++++ b/usr.bin/mandoc/html.c 2020-10-15 20:31:07.733706743 +0300
+@@ -18,6 +18,7 @@
+ * Common functions for mandoc(1) HTML formatters.
+ * For use by individual formatters and by the main program.
+ */
++#include <sys/cdefs.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+
+diff -upr a/usr.bin/mandoc/main.c b/usr.bin/mandoc/main.c
+--- a/usr.bin/mandoc/main.c 2020-04-03 01:10:27.000000000 +0300
++++ b/usr.bin/mandoc/main.c 2020-10-15 20:36:12.432111094 +0300
+@@ -405,8 +405,10 @@ main(int argc, char *argv[])
+ }
+ if (search.arch == NULL)
+ search.arch = getenv("MACHINE");
++#ifdef MACHINE
+ if (search.arch == NULL)
+ search.arch = MACHINE;
++#endif
+ if (outmode == OUTMODE_ONE)
+ search.firstmatch = 1;
+ }
+@@ -1183,7 +1185,6 @@ spawn_pager(struct tag_files *tag_files,
+ char *argv[MAX_PAGER_ARGS];
+ const char *pager;
+ char *cp;
+- size_t cmdlen;
+ int argc, use_ofn;
+ pid_t pager_pid;
+
+@@ -1218,18 +1219,6 @@ spawn_pager(struct tag_files *tag_files,
+ /* For more(1) and less(1), use the tag file. */
+
+ use_ofn = 1;
+- if (*tag_files->tfn != '\0' && (cmdlen = strlen(argv[0])) >= 4) {
+- cp = argv[0] + cmdlen - 4;
+- if (strcmp(cp, "less") == 0 || strcmp(cp, "more") == 0) {
+- argv[argc++] = mandoc_strdup("-T");
+- argv[argc++] = tag_files->tfn;
+- if (tag_target != NULL) {
+- argv[argc++] = mandoc_strdup("-t");
+- argv[argc++] = tag_target;
+- use_ofn = 0;
+- }
+- }
+- }
+ if (use_ofn)
+ argv[argc++] = tag_files->ofn;
+ argv[argc] = NULL;
+diff -upr a/usr.bin/mandoc/mandoc_ohash.c b/usr.bin/mandoc/mandoc_ohash.c
+--- a/usr.bin/mandoc/mandoc_ohash.c 2015-10-19 21:58:20.000000000 +0300
++++ b/usr.bin/mandoc/mandoc_ohash.c 2020-10-15 20:22:30.788037370 +0300
+@@ -14,6 +14,7 @@
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
++#include <sys/cdefs.h>
+ #include <sys/types.h>
+ #include <stddef.h>
+ #include <stdint.h>
+diff -upr a/usr.bin/mandoc/mandoc_xr.c b/usr.bin/mandoc/mandoc_xr.c
+--- a/usr.bin/mandoc/mandoc_xr.c 2017-07-03 00:17:12.000000000 +0300
++++ b/usr.bin/mandoc/mandoc_xr.c 2020-10-15 20:22:48.871060409 +0300
+@@ -14,6 +14,7 @@
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
++#include <sys/cdefs.h>
+ #include <sys/types.h>
+
+ #include <assert.h>
+diff -upr a/usr.bin/mandoc/mansearch.c b/usr.bin/mandoc/mansearch.c
+--- a/usr.bin/mandoc/mansearch.c 2019-07-02 01:43:03.000000000 +0300
++++ b/usr.bin/mandoc/mansearch.c 2020-10-15 20:23:05.476081586 +0300
+@@ -16,6 +16,7 @@
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
++#include <sys/cdefs.h>
+ #include <sys/mman.h>
+ #include <sys/types.h>
+
+diff -upr a/usr.bin/mandoc/roff.c b/usr.bin/mandoc/roff.c
+--- a/usr.bin/mandoc/roff.c 2020-04-08 14:54:14.000000000 +0300
++++ b/usr.bin/mandoc/roff.c 2020-10-15 20:23:23.988105223 +0300
+@@ -17,6 +17,7 @@
+ *
+ * Implementation of the roff(7) parser for mandoc(1).
+ */
++#include <sys/cdefs.h>
+ #include <sys/types.h>
+
+ #include <assert.h>
+diff -upr a/usr.bin/mandoc/tag.c b/usr.bin/mandoc/tag.c
+--- a/usr.bin/mandoc/tag.c 2020-04-19 19:26:11.000000000 +0300
++++ b/usr.bin/mandoc/tag.c 2020-10-15 20:23:39.327124832 +0300
+@@ -17,6 +17,7 @@
+ * Functions to tag syntax tree nodes.
+ * For internal use by mandoc(1) validation modules only.
+ */
++#include <sys/cdefs.h>
+ #include <sys/types.h>
+
+ #include <assert.h>
diff --git a/patches/0041-pidfile-add-cdefs.patch b/patches/0041-pidfile-add-cdefs.patch
new file mode 100644
index 0000000..99efd99
--- /dev/null
+++ b/patches/0041-pidfile-add-cdefs.patch
@@ -0,0 +1,10 @@
+--- a/lib/libutil/pidfile.c 2019-06-28 17:20:40.000000000 +0300
++++ b/lib/libutil/pidfile.c 2020-10-16 12:52:17.812742477 +0300
+@@ -30,6 +30,7 @@
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
++#include <sys/cdefs.h>
+ #include <sys/types.h>
+ #include <errno.h>
+ #include <paths.h>
diff --git a/patches/0042-doas-define-gnu-source.patch b/patches/0042-doas-define-gnu-source.patch
new file mode 100644
index 0000000..cfd119b
--- /dev/null
+++ b/patches/0042-doas-define-gnu-source.patch
@@ -0,0 +1,13 @@
+--- a/usr.bin/doas/doas.c 2020-10-16 13:11:26.769202572 +0300
++++ b/usr.bin/doas/doas.c 2020-10-16 13:09:43.558056917 +0300
+@@ -15,6 +15,10 @@
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
++#ifndef _GNU_SOURCE
++#define _GNU_SOURCE
++#endif
++
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <sys/ioctl.h>
diff --git a/patches/0043-signify-add-headers.patch b/patches/0043-signify-add-headers.patch
new file mode 100644
index 0000000..b07991f
--- /dev/null
+++ b/patches/0043-signify-add-headers.patch
@@ -0,0 +1,34 @@
+diff -ur openbsd-nopatch/usr.bin/signify/crypto_api.c b/usr.bin/signify/crypto_api.c
+--- a/usr.bin/signify/crypto_api.c 2014-01-08 05:59:46.000000000 +0200
++++ b/usr.bin/signify/crypto_api.c 2020-10-16 14:29:11.994722510 +0300
+@@ -3,6 +3,7 @@
+ * Public domain. Author: Ted Unangst <tedu@openbsd.org>
+ * API compatible reimplementation of functions from nacl
+ */
++#include <sys/cdefs.h>
+ #include <sys/types.h>
+
+ #include <string.h>
+diff -ur a/usr.bin/signify/signify.c b/usr.bin/signify/signify.c
+--- a/usr.bin/signify/signify.c 2020-01-21 15:13:21.000000000 +0300
++++ b/usr.bin/signify/signify.c 2020-10-16 14:27:02.856481664 +0300
+@@ -14,6 +14,7 @@
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
++#include <sys/cdefs.h>
+ #include <sys/stat.h>
+
+ #include <netinet/in.h>
+diff -ur a/usr.bin/signify/zsig.c b/usr.bin/signify/zsig.c
+--- a/usr.bin/signify/zsig.c 2019-12-22 09:37:25.000000000 +0300
++++ b/usr.bin/signify/zsig.c 2020-10-16 14:31:00.168365855 +0300
+@@ -16,6 +16,8 @@
+ */
+
+ #ifndef VERIFYONLY
++#include <sys/cdefs.h>
++#include <sys/compat.h>
+ #include <stdint.h>
+ #include <err.h>
+ #include <stdio.h>
diff --git a/patches/0044-fix-hash-objects.patch b/patches/0044-fix-hash-objects.patch
new file mode 100644
index 0000000..bf7bdc0
--- /dev/null
+++ b/patches/0044-fix-hash-objects.patch
@@ -0,0 +1,40 @@
+--- a/lib/libc/hash/helper.c 2019-06-28 16:32:41.000000000 +0300
++++ b/lib/libc/hash/helper.c 2020-10-15 17:19:18.086197995 +0300
+@@ -22,6 +22,7 @@
+ */
+
+ #include <sys/types.h>
++#include <sys/cdefs.h>
+ #include <sys/stat.h>
+
+ #include <errno.h>
+--- a/lib/libc/hash/md5.c 2015-09-11 12:18:27.000000000 +0300
++++ b/lib/libc/hash/md5.c 2020-10-16 16:15:28.878466917 +0300
+@@ -17,6 +17,7 @@
+ * will fill a supplied 16-byte array with the digest.
+ */
+
++#include <sys/cdefs.h>
+ #include <sys/types.h>
+ #include <string.h>
+ #include <md5.h>
+--- a/lib/libc/hash/rmd160.c 2015-09-11 12:18:27.000000000 +0300
++++ b/lib/libc/hash/rmd160.c 2020-10-16 16:16:34.873811145 +0300
+@@ -26,6 +26,7 @@
+ * RSA Laboratories, CryptoBytes, Volume 3, Number 2, Autumn 1997,
+ * ftp://ftp.rsasecurity.com/pub/cryptobytes/crypto3n2.pdf
+ */
++#include <sys/cdefs.h>
+ #include <sys/types.h>
+ #include <endian.h>
+ #include <string.h>
+--- a/lib/libc/hash/sha1.c 2019-06-08 01:56:36.000000000 +0300
++++ b/lib/libc/hash/sha1.c 2020-10-16 16:12:06.772977604 +0300
+@@ -14,6 +14,7 @@
+ * 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
+ */
+
++#include <sys/cdefs.h>
+ #include <sys/types.h>
+ #include <string.h>
+ #include <sha1.h>
diff --git a/patches/0045-md5-add-headers.patch b/patches/0045-md5-add-headers.patch
new file mode 100644
index 0000000..117faa5
--- /dev/null
+++ b/patches/0045-md5-add-headers.patch
@@ -0,0 +1,19 @@
+--- openbsd-nopatch/bin/md5/md5.c 2019-05-18 19:53:39.000000000 +0300
++++ src/bin/md5/md5.c 2020-10-16 16:05:40.294296211 +0300
+@@ -21,6 +21,7 @@
+ * Materiel Command, USAF, under agreement number F39502-99-1-0512.
+ */
+
++#include <sys/cdefs.h>
+ #include <sys/types.h>
+ #include <sys/time.h>
+ #include <sys/queue.h>
+@@ -42,7 +43,7 @@
+ #include <rmd160.h>
+ #include <sha1.h>
+ #include <sha2.h>
+-#include <crc.h>
++#include "crc.h"
+
+ #define STYLE_MD5 0
+ #define STYLE_CKSUM 1
diff --git a/sys/sys/CVS/Entries b/sys/sys/CVS/Entries
new file mode 100644
index 0000000..5813030
--- /dev/null
+++ b/sys/sys/CVS/Entries
@@ -0,0 +1,139 @@
+/_endian.h/1.8/Thu Jan 11 23:13:37 2018//
+/_lock.h/1.4/Tue Apr 23 13:35:12 2019//
+/_null.h/1.2/Fri Sep 9 22:07:58 2016//
+/_time.h/1.9/Mon Dec 18 05:51:53 2017//
+/_types.h/1.9/Fri Aug 22 23:05:15 2014//
+/acct.h/1.9/Mon Sep 9 20:02:26 2019//
+/ataio.h/1.5/Fri Sep 26 21:43:32 2003//
+/atomic.h/1.6/Sat Mar 9 06:14:21 2019//
+/audioio.h/1.27/Wed Sep 14 06:12:20 2016//
+/buf.h/1.112/Fri Nov 29 01:04:08 2019//
+/cdefs.h/1.43/Mon Oct 29 17:10:40 2018//
+/cdio.h/1.17/Tue Oct 24 09:36:13 2017//
+/chio.h/1.7/Wed May 31 03:01:44 2006//
+/conf.h/1.150/Tue Apr 21 08:29:27 2020//
+/core.h/1.7/Sat Sep 17 06:09:08 2016//
+/ctf.h/1.5/Sun Aug 13 14:56:05 2017//
+/device.h/1.55/Mon Sep 10 16:18:34 2018//
+/dir.h/1.5/Mon Jun 2 23:28:21 2003//
+/dirent.h/1.11/Fri Dec 13 18:09:27 2013//
+/disk.h/1.36/Thu May 4 22:47:27 2017//
+/disklabel.h/1.75/Tue Oct 24 09:36:13 2017//
+/dkio.h/1.12/Tue Oct 24 09:36:13 2017//
+/domain.h/1.20/Thu Jun 13 08:12:11 2019//
+/endian.h/1.25/Sun Dec 21 04:49:00 2014//
+/errno.h/1.25/Tue Sep 5 03:06:26 2017//
+/evcount.h/1.3/Mon Sep 20 06:33:46 2010//
+/event.h/1.35/Tue Apr 7 13:27:52 2020//
+/eventvar.h/1.9/Tue Apr 7 13:27:52 2020//
+/exec.h/1.40/Fri Nov 29 06:34:46 2019//
+/exec_elf.h/1.87/Sun Dec 1 13:10:51 2019//
+/exec_script.h/1.6/Wed Feb 7 20:31:57 2018//
+/extent.h/1.14/Sat Feb 8 20:29:01 2014//
+/fcntl.h/1.22/Mon Jan 21 18:09:21 2019//
+/file.h/1.61/Fri Mar 13 10:07:01 2020//
+/filedesc.h/1.44/Thu Jan 30 15:33:04 2020//
+/filio.h/1.5/Fri Jun 1 22:30:48 2007//
+/fusebuf.h/1.13/Tue Jun 19 11:27:54 2018//
+/futex.h/1.2/Sun Jun 3 15:09:26 2018//
+/gmon.h/1.8/Sat May 7 19:30:52 2016//
+/gpio.h/1.8/Mon Oct 3 20:24:51 2011//
+/hibernate.h/1.42/Thu Jun 21 07:33:30 2018//
+/hotplug.h/1.5/Sun May 28 16:52:34 2006//
+/ioccom.h/1.5/Fri Mar 22 21:22:05 2013//
+/ioctl.h/1.17/Sun Feb 28 15:46:19 2016//
+/ipc.h/1.13/Sat Nov 15 21:42:50 2014//
+/kcore.h/1.1/Thu Apr 18 21:40:57 1996//
+/kcov.h/1.4/Sun Jan 20 09:57:23 2019//
+/kernel.h/1.22/Sat Sep 7 01:23:23 2019//
+/kthread.h/1.7/Tue Feb 18 12:13:40 2020//
+/ktrace.h/1.38/Tue Feb 26 22:24:41 2019//
+/limits.h/1.10/Sat Jun 30 20:21:10 2012//
+/lock.h/1.27/Sun Jun 19 11:54:33 2016//
+/lockf.h/1.17/Sat Apr 20 08:28:59 2019//
+/malloc.h/1.119/Thu Nov 28 16:23:11 2019//
+/mbuf.h/1.246/Wed Jan 22 22:56:35 2020//
+/memrange.h/1.10/Tue Aug 18 20:19:32 2015//
+/mman.h/1.34/Fri Mar 1 01:46:18 2019//
+/mount.h/1.147/Sat Jan 18 08:40:19 2020//
+/mplock.h/1.13/Tue Apr 23 13:35:12 2019//
+/msg.h/1.19/Sun Nov 23 04:31:42 2014//
+/msgbuf.h/1.11/Thu Jun 23 13:15:21 2016//
+/mtio.h/1.9/Fri Jun 1 18:44:48 2007//
+/mutex.h/1.18/Tue Apr 23 13:35:12 2019//
+/namei.h/1.45/Thu Mar 19 13:55:20 2020//
+/param.h/1.130/Sun Apr 5 06:34:20 2020//
+/pciio.h/1.7/Sun Sep 5 18:14:33 2010//
+/percpu.h/1.8/Tue Aug 28 15:15:02 2018//
+/pipe.h/1.24/Fri Jan 24 11:07:41 2020//
+/pledge.h/1.41/Sun Apr 5 07:31:45 2020//
+/poll.h/1.15/Tue Jun 7 06:12:37 2016//
+/pool.h/1.77/Fri Jul 19 09:03:03 2019//
+/proc.h/1.295/Tue Apr 28 08:29:40 2020//
+/protosw.h/1.31/Tue Jan 23 20:49:58 2018//
+/ptrace.h/1.16/Mon Mar 16 11:58:46 2020//
+/queue.h/1.45/Thu Jul 12 14:22:54 2018//
+/radioio.h/1.5/Wed Jan 14 21:15:36 2015//
+/reboot.h/1.18/Mon Apr 1 07:00:52 2019//
+/refcnt.h/1.4/Tue Jun 7 07:53:33 2016//
+/resource.h/1.14/Fri Oct 25 04:42:48 2013//
+/resourcevar.h/1.24/Fri Jun 21 09:39:48 2019//
+/rwlock.h/1.26/Tue Jul 16 01:40:49 2019//
+/sched.h/1.56/Mon Oct 21 10:24:01 2019//
+/scsiio.h/1.10/Wed Sep 5 17:17:47 2012//
+/select.h/1.17/Mon Sep 12 19:41:20 2016//
+/selinfo.h/1.5/Tue Jul 18 19:20:26 2017//
+/sem.h/1.24/Thu Sep 1 08:33:40 2016//
+/sensors.h/1.36/Mon Dec 10 13:35:54 2018//
+/shm.h/1.29/Sun Nov 3 20:16:01 2019//
+/siginfo.h/1.12/Fri Apr 7 04:48:44 2017//
+/sigio.h/1.4/Wed Jan 8 16:27:42 2020//
+/signal.h/1.29/Wed Apr 18 16:05:20 2018//
+/signalvar.h/1.40/Fri Mar 13 09:25:21 2020//
+/smr.h/1.6/Sun Apr 12 07:20:33 2020//
+/socket.h/1.98/Mon Jul 22 15:34:07 2019//
+/socketvar.h/1.91/Wed Jan 15 13:17:35 2020//
+/sockio.h/1.83/Wed Nov 13 11:54:01 2019//
+/specdev.h/1.39/Fri Dec 27 22:17:01 2019//
+/srp.h/1.14/Sun Mar 31 14:03:40 2019//
+/stacktrace.h/1.3/Sat Apr 18 04:45:20 2020//
+/stat.h/1.28/Sat Apr 4 18:06:08 2015//
+/statvfs.h/1.3/Sun Mar 24 17:45:50 2013//
+/stdarg.h/1.9/Thu Dec 12 15:55:36 2019//
+/stdint.h/1.11/Fri Jan 25 00:19:26 2019//
+/swap.h/1.7/Mon Sep 30 12:02:30 2013//
+/syscall.h/1.215/Wed Mar 18 19:35:00 2020//
+/syscall_mi.h/1.25/Tue Jan 21 16:16:23 2020//
+/syscallargs.h/1.218/Wed Mar 18 19:35:00 2020//
+/sysctl.h/1.205/Fri Mar 13 10:07:01 2020//
+/syslimits.h/1.14/Thu Apr 2 18:00:00 2020//
+/syslog.h/1.16/Tue Aug 8 14:23:23 2017//
+/systm.h/1.145/Fri Mar 20 03:37:08 2020//
+/task.h/1.16/Sun Jun 23 12:56:10 2019//
+/termios.h/1.13/Tue Sep 20 21:10:22 2016//
+/time.h/1.50/Wed Jan 15 13:17:35 2020//
+/timeout.h/1.36/Fri Jan 3 02:16:38 2020//
+/times.h/1.6/Sat Jul 6 18:44:21 2013//
+/timetc.h/1.10/Sat Oct 26 21:16:38 2019//
+/tprintf.h/1.6/Sun Aug 24 01:27:07 2003//
+/tracepoint.h/1.1/Tue Jan 21 16:16:23 2020//
+/tree.h/1.29/Sun Jul 30 19:27:20 2017//
+/tty.h/1.38/Fri Jul 19 00:17:16 2019//
+/ttycom.h/1.17/Sat Jun 16 13:55:03 2018//
+/ttydefaults.h/1.7/Tue Mar 12 11:01:25 2019//
+/types.h/1.48/Sat Feb 9 04:54:11 2019//
+/ucred.h/1.13/Thu Jun 21 13:58:21 2018//
+/uio.h/1.19/Mon Aug 20 16:00:22 2018//
+/un.h/1.14/Sat Jul 18 15:00:01 2015//
+/unistd.h/1.31/Mon Jul 20 00:56:10 2015//
+/unpcb.h/1.17/Mon Jul 15 12:28:06 2019//
+/user.h/1.9/Tue Jul 8 23:31:22 2014//
+/utsname.h/1.6/Sun Mar 24 17:45:50 2013//
+/uuid.h/1.3/Sun Aug 31 09:36:39 2014//
+/varargs.h/1.3/Sat Dec 7 06:55:20 2019//
+/videoio.h/1.16/Fri Feb 17 06:48:33 2017//
+/vmmeter.h/1.15/Wed Jul 27 14:44:59 2016//
+/vnode.h/1.156/Wed Apr 8 08:07:52 2020//
+/wait.h/1.17/Fri Jun 13 22:40:31 2014//
+/witness.h/1.5/Tue Apr 23 13:35:12 2019//
+D
diff --git a/sys/sys/CVS/Repository b/sys/sys/CVS/Repository
new file mode 100644
index 0000000..559e41f
--- /dev/null
+++ b/sys/sys/CVS/Repository
@@ -0,0 +1 @@
+src/sys/sys
diff --git a/sys/sys/CVS/Root b/sys/sys/CVS/Root
new file mode 100644
index 0000000..3811072
--- /dev/null
+++ b/sys/sys/CVS/Root
@@ -0,0 +1 @@
+/cvs
diff --git a/sys/sys/_endian.h b/sys/sys/_endian.h
new file mode 100644
index 0000000..e1ce82e
--- /dev/null
+++ b/sys/sys/_endian.h
@@ -0,0 +1,179 @@
+/* $OpenBSD: _endian.h,v 1.8 2018/01/11 23:13:37 dlg Exp $ */
+
+/*-
+ * Copyright (c) 1997 Niklas Hallqvist. 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.
+ */
+
+/*
+ * Internal endianness macros. This pulls in <machine/endian.h> to
+ * get the correct setting direction for the platform and sets internal
+ * ('__' prefix) macros appropriately.
+ */
+
+#ifndef _SYS__ENDIAN_H_
+#define _SYS__ENDIAN_H_
+
+#include <sys/_types.h>
+
+#define __FROM_SYS__ENDIAN
+#include <machine/endian.h>
+#undef __FROM_SYS__ENDIAN
+
+#define _LITTLE_ENDIAN 1234
+#define _BIG_ENDIAN 4321
+#define _PDP_ENDIAN 3412
+
+/* Note that these macros evaluate their arguments several times. */
+
+#define __swap16gen(x) \
+ (__uint16_t)(((__uint16_t)(x) & 0xffU) << 8 | ((__uint16_t)(x) & 0xff00U) >> 8)
+
+#define __swap32gen(x) \
+ (__uint32_t)(((__uint32_t)(x) & 0xff) << 24 | \
+ ((__uint32_t)(x) & 0xff00) << 8 | ((__uint32_t)(x) & 0xff0000) >> 8 |\
+ ((__uint32_t)(x) & 0xff000000) >> 24)
+
+#define __swap64gen(x) \
+ (__uint64_t)((((__uint64_t)(x) & 0xff) << 56) | \
+ ((__uint64_t)(x) & 0xff00ULL) << 40 | \
+ ((__uint64_t)(x) & 0xff0000ULL) << 24 | \
+ ((__uint64_t)(x) & 0xff000000ULL) << 8 | \
+ ((__uint64_t)(x) & 0xff00000000ULL) >> 8 | \
+ ((__uint64_t)(x) & 0xff0000000000ULL) >> 24 | \
+ ((__uint64_t)(x) & 0xff000000000000ULL) >> 40 | \
+ ((__uint64_t)(x) & 0xff00000000000000ULL) >> 56)
+
+#ifndef __HAVE_MD_SWAP
+static __inline __uint16_t
+__swap16md(__uint16_t x)
+{
+ return (__swap16gen(x));
+}
+
+static __inline __uint32_t
+__swap32md(__uint32_t x)
+{
+ return (__swap32gen(x));
+}
+
+static __inline __uint64_t
+__swap64md(__uint64_t x)
+{
+ return (__swap64gen(x));
+}
+#endif
+
+#define __swap16(x) \
+ (__uint16_t)(__builtin_constant_p(x) ? __swap16gen(x) : __swap16md(x))
+#define __swap32(x) \
+ (__uint32_t)(__builtin_constant_p(x) ? __swap32gen(x) : __swap32md(x))
+#define __swap64(x) \
+ (__uint64_t)(__builtin_constant_p(x) ? __swap64gen(x) : __swap64md(x))
+
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+
+#define _QUAD_HIGHWORD 1
+#define _QUAD_LOWWORD 0
+
+#define __htobe16 __swap16
+#define __htobe32 __swap32
+#define __htobe64 __swap64
+#define __htole16(x) ((__uint16_t)(x))
+#define __htole32(x) ((__uint32_t)(x))
+#define __htole64(x) ((__uint64_t)(x))
+
+#ifdef _KERNEL
+#ifdef __HAVE_MD_SWAPIO
+
+#define __bemtoh16(_x) __mswap16(_x)
+#define __bemtoh32(_x) __mswap32(_x)
+#define __bemtoh64(_x) __mswap64(_x)
+
+#define __htobem16(_x, _v) __swapm16((_x), (_v))
+#define __htobem32(_x, _v) __swapm32((_x), (_v))
+#define __htobem64(_x, _v) __swapm64((_x), (_v))
+
+#endif /* __HAVE_MD_SWAPIO */
+#endif /* _KERNEL */
+#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */
+
+#if _BYTE_ORDER == _BIG_ENDIAN
+
+#define _QUAD_HIGHWORD 0
+#define _QUAD_LOWWORD 1
+
+#define __htobe16(x) ((__uint16_t)(x))
+#define __htobe32(x) ((__uint32_t)(x))
+#define __htobe64(x) ((__uint64_t)(x))
+#define __htole16 __swap16
+#define __htole32 __swap32
+#define __htole64 __swap64
+
+#ifdef _KERNEL
+#ifdef __HAVE_MD_SWAPIO
+
+#define __lemtoh16(_x) __mswap16(_x)
+#define __lemtoh32(_x) __mswap32(_x)
+#define __lemtoh64(_x) __mswap64(_x)
+
+#define __htolem16(_x, _v) __swapm16((_x), (_v))
+#define __htolem32(_x, _v) __swapm32((_x), (_v))
+#define __htolem64(_x, _v) __swapm64((_x), (_v))
+
+#endif /* __HAVE_MD_SWAPIO */
+#endif /* _KERNEL */
+#endif /* _BYTE_ORDER == _BIG_ENDIAN */
+
+
+#ifdef _KERNEL
+/*
+ * Fill in the __hto[bl]em{16,32,64} and __[bl]emtoh{16,32,64} macros
+ * that haven't been defined yet
+ */
+
+#ifndef __bemtoh16
+#define __bemtoh16(_x) __htobe16(*(__uint16_t *)(_x))
+#define __bemtoh32(_x) __htobe32(*(__uint32_t *)(_x))
+#define __bemtoh64(_x) __htobe64(*(__uint64_t *)(_x))
+#endif
+
+#ifndef __htobem16
+#define __htobem16(_x, _v) (*(__uint16_t *)(_x) = __htobe16(_v))
+#define __htobem32(_x, _v) (*(__uint32_t *)(_x) = __htobe32(_v))
+#define __htobem64(_x, _v) (*(__uint64_t *)(_x) = __htobe64(_v))
+#endif
+
+#ifndef __lemtoh16
+#define __lemtoh16(_x) __htole16(*(__uint16_t *)(_x))
+#define __lemtoh32(_x) __htole32(*(__uint32_t *)(_x))
+#define __lemtoh64(_x) __htole64(*(__uint64_t *)(_x))
+#endif
+
+#ifndef __htolem16
+#define __htolem16(_x, _v) (*(__uint16_t *)(_x) = __htole16(_v))
+#define __htolem32(_x, _v) (*(__uint32_t *)(_x) = __htole32(_v))
+#define __htolem64(_x, _v) (*(__uint64_t *)(_x) = __htole64(_v))
+#endif
+#endif /* _KERNEL */
+
+#endif /* _SYS__ENDIAN_H_ */
diff --git a/sys/sys/_lock.h b/sys/sys/_lock.h
new file mode 100644
index 0000000..fbcfb0a
--- /dev/null
+++ b/sys/sys/_lock.h
@@ -0,0 +1,70 @@
+/* $OpenBSD: _lock.h,v 1.4 2019/04/23 13:35:12 visa Exp $ */
+
+/*-
+ * Copyright (c) 1997 Berkeley Software Design, 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.
+ * 3. Berkeley Software Design Inc's name may not be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN 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 BERKELEY SOFTWARE DESIGN INC 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: head/sys/sys/_lock.h 179025 2008-05-15 20:10:06Z attilio $
+ */
+
+#ifndef _SYS__LOCK_H_
+#define _SYS__LOCK_H_
+
+#define LO_CLASSFLAGS 0x0000ffff /* Class specific flags. */
+#define LO_INITIALIZED 0x00010000 /* Lock has been initialized. */
+#define LO_WITNESS 0x00020000 /* Should witness monitor this lock. */
+#define LO_QUIET 0x00040000 /* Don't log locking operations. */
+#define LO_RECURSABLE 0x00080000 /* Lock may recurse. */
+#define LO_SLEEPABLE 0x00100000 /* Lock may be held while sleeping. */
+#define LO_UPGRADABLE 0x00200000 /* Lock may be upgraded/downgraded. */
+#define LO_DUPOK 0x00400000 /* Don't check for duplicate acquires */
+#define LO_IS_VNODE 0x00800000 /* Tell WITNESS about a VNODE lock */
+#define LO_CLASSMASK 0x0f000000 /* Class index bitmask. */
+#define LO_NOPROFILE 0x10000000 /* Don't profile this lock */
+#define LO_NEW 0x20000000 /* Don't check for double-init */
+
+#define LO_CLASSSHIFT 24
+
+enum lock_class_index {
+ LO_CLASS_KERNEL_LOCK,
+ LO_CLASS_SCHED_LOCK,
+ LO_CLASS_MUTEX,
+ LO_CLASS_RWLOCK,
+ LO_CLASS_RRWLOCK
+};
+
+struct lock_object {
+ const struct lock_type *lo_type;
+ const char *lo_name; /* Individual lock name. */
+ struct witness *lo_witness; /* Data for witness. */
+ unsigned int lo_flags;
+};
+
+struct lock_type {
+ const char *lt_name;
+};
+
+#endif /* !_SYS__LOCK_H_ */
diff --git a/sys/sys/_null.h b/sys/sys/_null.h
new file mode 100644
index 0000000..5d15401
--- /dev/null
+++ b/sys/sys/_null.h
@@ -0,0 +1,18 @@
+/* $OpenBSD: _null.h,v 1.2 2016/09/09 22:07:58 millert Exp $ */
+
+/*
+ * Written by Todd C. Miller, September 9, 2016
+ * Public domain.
+ */
+
+#ifndef NULL
+#if !defined(__cplusplus)
+#define NULL ((void *)0)
+#elif __cplusplus >= 201103L
+#define NULL nullptr
+#elif defined(__GNUG__)
+#define NULL __null
+#else
+#define NULL 0L
+#endif
+#endif
diff --git a/sys/sys/_time.h b/sys/sys/_time.h
new file mode 100644
index 0000000..a8ac94e
--- /dev/null
+++ b/sys/sys/_time.h
@@ -0,0 +1,64 @@
+/* $OpenBSD: _time.h,v 1.9 2017/12/18 05:51:53 cheloha 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.
+ * 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 _SYS__TIME_H_
+#define _SYS__TIME_H_
+
+#define CLOCK_REALTIME 0
+#define CLOCK_PROCESS_CPUTIME_ID 2
+#define CLOCK_MONOTONIC 3
+#define CLOCK_THREAD_CPUTIME_ID 4
+#define CLOCK_UPTIME 5
+#define CLOCK_BOOTTIME 6
+
+#if __BSD_VISIBLE
+/*
+ * Per-process and per-thread clocks encode the PID or TID into the
+ * high bits, with the type in the bottom bits
+ */
+#define __CLOCK_ENCODE(type,id) ((type) | ((id) << 12))
+#define __CLOCK_TYPE(c) ((c) & 0xfff)
+#define __CLOCK_PTID(c) (((c) >> 12) & 0xfffff)
+#endif
+
+/*
+ * Structure defined by POSIX 1003.1b to be like a itimerval,
+ * but with timespecs. Used in the timer_*() system calls.
+ */
+struct itimerspec {
+ struct timespec it_interval; /* timer interval */
+ struct timespec it_value; /* timer expiration */
+};
+
+#define TIMER_RELTIME 0x0 /* relative timer */
+#define TIMER_ABSTIME 0x1 /* absolute timer */
+
+#endif /* !_SYS__TIME_H_ */
diff --git a/sys/sys/_types.h b/sys/sys/_types.h
new file mode 100644
index 0000000..e058674
--- /dev/null
+++ b/sys/sys/_types.h
@@ -0,0 +1,78 @@
+/* $OpenBSD: _types.h,v 1.9 2014/08/22 23:05:15 krw Exp $ */
+
+/*-
+ * Copyright (c) 1990, 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.
+ *
+ * @(#)types.h 8.3 (Berkeley) 1/5/94
+ */
+
+#ifndef _SYS__TYPES_H_
+#define _SYS__TYPES_H_
+
+#include <machine/_types.h>
+
+typedef __int64_t __blkcnt_t; /* blocks allocated for file */
+typedef __int32_t __blksize_t; /* optimal blocksize for I/O */
+typedef __int64_t __clock_t; /* ticks in CLOCKS_PER_SEC */
+typedef __int32_t __clockid_t; /* CLOCK_* identifiers */
+typedef unsigned long __cpuid_t; /* CPU id */
+typedef __int32_t __dev_t; /* device number */
+typedef __uint32_t __fixpt_t; /* fixed point number */
+typedef __uint64_t __fsblkcnt_t; /* file system block count */
+typedef __uint64_t __fsfilcnt_t; /* file system file count */
+typedef __uint32_t __gid_t; /* group id */
+typedef __uint32_t __id_t; /* may contain pid, uid or gid */
+typedef __uint32_t __in_addr_t; /* base type for internet address */
+typedef __uint16_t __in_port_t; /* IP port type */
+typedef __uint64_t __ino_t; /* inode number */
+typedef long __key_t; /* IPC key (for Sys V IPC) */
+typedef __uint32_t __mode_t; /* permissions */
+typedef __uint32_t __nlink_t; /* link count */
+typedef __int64_t __off_t; /* file offset or size */
+typedef __int32_t __pid_t; /* process id */
+typedef __uint64_t __rlim_t; /* resource limit */
+typedef __uint8_t __sa_family_t; /* sockaddr address family type */
+typedef __int32_t __segsz_t; /* segment size */
+typedef __uint32_t __socklen_t; /* length type for network syscalls */
+typedef long __suseconds_t; /* microseconds (signed) */
+typedef __int32_t __swblk_t; /* swap offset */
+typedef __int64_t __time_t; /* epoch time */
+typedef __int32_t __timer_t; /* POSIX timer identifiers */
+typedef __uint32_t __uid_t; /* user id */
+typedef __uint32_t __useconds_t; /* microseconds */
+
+/*
+ * mbstate_t is an opaque object to keep conversion state, during multibyte
+ * stream conversions. The content must not be referenced by user programs.
+ */
+typedef union {
+ char __mbstate8[128];
+ __int64_t __mbstateL; /* for alignment */
+} __mbstate_t;
+
+#endif /* !_SYS__TYPES_H_ */
diff --git a/sys/sys/acct.h b/sys/sys/acct.h
new file mode 100644
index 0000000..db7c846
--- /dev/null
+++ b/sys/sys/acct.h
@@ -0,0 +1,79 @@
+/* $OpenBSD: acct.h,v 1.9 2019/09/09 20:02:26 bluhm Exp $ */
+/* $NetBSD: acct.h,v 1.16 1995/03/26 20:23:52 jtc Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)acct.h 8.3 (Berkeley) 7/10/94
+ */
+
+/*
+ * Accounting structures; these use a comp_t type which is a 3 bits base 8
+ * exponent, 13 bit fraction ``floating point'' number. Units are 1/AHZ
+ * seconds.
+ */
+typedef u_int16_t comp_t;
+
+struct acct {
+ char ac_comm[10]; /* command name */
+ comp_t ac_utime; /* user time */
+ comp_t ac_stime; /* system time */
+ comp_t ac_etime; /* elapsed time */
+ time_t ac_btime; /* starting time */
+ uid_t ac_uid; /* user id */
+ gid_t ac_gid; /* group id */
+ u_int16_t ac_mem; /* average memory usage */
+ comp_t ac_io; /* count of IO blocks */
+ dev_t ac_tty; /* controlling tty */
+
+#define AFORK 0x01 /* fork'd but not exec'd */
+#define ASU 0x02 /* used super-user permissions */
+#define AMAP 0x04 /* system call or stack mapping violation */
+#define ACORE 0x08 /* dumped core */
+#define AXSIG 0x10 /* killed by a signal */
+#define APLEDGE 0x20 /* killed due to pledge violation */
+#define ATRAP 0x40 /* memory access violation */
+#define AUNVEIL 0x80 /* unveil access violation */
+ u_int8_t ac_flag; /* accounting flags */
+};
+
+/*
+ * 1/AHZ is the granularity of the data encoded in the comp_t fields.
+ * This is not necessarily equal to hz.
+ */
+#define AHZ 64
+
+#ifdef _KERNEL
+int acct_process(struct proc *p);
+void acct_shutdown(void);
+#endif
diff --git a/sys/sys/ataio.h b/sys/sys/ataio.h
new file mode 100644
index 0000000..fe79794
--- /dev/null
+++ b/sys/sys/ataio.h
@@ -0,0 +1,48 @@
+/* $OpenBSD: ataio.h,v 1.5 2003/09/26 21:43:32 miod Exp $ */
+/* $NetBSD: ataio.h,v 1.2 1998/11/23 22:58:23 kenh Exp $ */
+
+#ifndef _SYS_ATAIO_H_
+#define _SYS_ATAIO_H_
+
+#include <sys/types.h>
+#include <sys/ioctl.h>
+
+typedef struct atareq {
+ u_long flags; /* info about the request status and type */
+ u_char command; /* command code */
+ u_char features; /* feature modifier bits for command */
+ u_char sec_count; /* sector count */
+ u_char sec_num; /* sector number */
+ u_char head; /* head number */
+ u_short cylinder; /* cylinder/lba address */
+
+ caddr_t databuf; /* pointer to I/O data buffer */
+ u_long datalen; /* length of data buffer */
+ int timeout; /* command timeout */
+ u_char retsts; /* return status for the command */
+ u_char error; /* error bits */
+} atareq_t;
+
+/* bit definitions for flags */
+#define ATACMD_READ 0x00000001
+#define ATACMD_WRITE 0x00000002
+#define ATACMD_READREG 0x00000004
+
+/* definitions for the return status (retsts) */
+#define ATACMD_OK 0x00
+#define ATACMD_TIMEOUT 0x01
+#define ATACMD_ERROR 0x02
+#define ATACMD_DF 0x03
+
+#define ATAIOCCOMMAND _IOWR('Q', 8, atareq_t)
+
+typedef struct atagettrace {
+ unsigned int buf_size; /* length of data buffer */
+ void *buf; /* pointer to data buffer */
+ unsigned int bytes_copied; /* number of bytes copied to buffer */
+ unsigned int bytes_left; /* number of bytes left */
+} atagettrace_t;
+
+#define ATAIOGETTRACE _IOWR('Q', 27, struct atagettrace)
+
+#endif /* _SYS_ATAIO_H_ */
diff --git a/sys/sys/atomic.h b/sys/sys/atomic.h
new file mode 100644
index 0000000..22b92b6
--- /dev/null
+++ b/sys/sys/atomic.h
@@ -0,0 +1,258 @@
+/* $OpenBSD: atomic.h,v 1.6 2019/03/09 06:14:21 visa Exp $ */
+/*
+ * Copyright (c) 2014 David Gwynne <dlg@openbsd.org>
+ *
+ * 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.
+ */
+
+#ifndef _SYS_ATOMIC_H_
+#define _SYS_ATOMIC_H_
+
+#include <machine/atomic.h>
+
+/*
+ * an arch wanting to provide its own implementations does so by defining
+ * macros.
+ */
+
+/*
+ * atomic_cas_*
+ */
+
+#ifndef atomic_cas_uint
+static inline unsigned int
+atomic_cas_uint(volatile unsigned int *p, unsigned int o, unsigned int n)
+{
+ return __sync_val_compare_and_swap(p, o, n);
+}
+#endif
+
+#ifndef atomic_cas_ulong
+static inline unsigned long
+atomic_cas_ulong(volatile unsigned long *p, unsigned long o, unsigned long n)
+{
+ return __sync_val_compare_and_swap(p, o, n);
+}
+#endif
+
+#ifndef atomic_cas_ptr
+static inline void *
+atomic_cas_ptr(volatile void *pp, void *o, void *n)
+{
+ void * volatile *p = (void * volatile *)pp;
+ return __sync_val_compare_and_swap(p, o, n);
+}
+#endif
+
+/*
+ * atomic_swap_*
+ */
+
+#ifndef atomic_swap_uint
+static inline unsigned int
+atomic_swap_uint(volatile unsigned int *p, unsigned int v)
+{
+ return __sync_lock_test_and_set(p, v);
+}
+#endif
+
+#ifndef atomic_swap_ulong
+static inline unsigned long
+atomic_swap_ulong(volatile unsigned long *p, unsigned long v)
+{
+ return __sync_lock_test_and_set(p, v);
+}
+#endif
+
+#ifndef atomic_swap_ptr
+static inline void *
+atomic_swap_ptr(volatile void *pp, void *v)
+{
+ void * volatile *p = (void * volatile *)pp;
+ return __sync_lock_test_and_set(p, v);
+}
+#endif
+
+/*
+ * atomic_add_*_nv - add and fetch
+ */
+
+#ifndef atomic_add_int_nv
+static inline unsigned int
+atomic_add_int_nv(volatile unsigned int *p, unsigned int v)
+{
+ return __sync_add_and_fetch(p, v);
+}
+#endif
+
+#ifndef atomic_add_long_nv
+static inline unsigned long
+atomic_add_long_nv(volatile unsigned long *p, unsigned long v)
+{
+ return __sync_add_and_fetch(p, v);
+}
+#endif
+
+/*
+ * atomic_add - add
+ */
+
+#ifndef atomic_add_int
+#define atomic_add_int(_p, _v) ((void)atomic_add_int_nv((_p), (_v)))
+#endif
+
+#ifndef atomic_add_long
+#define atomic_add_long(_p, _v) ((void)atomic_add_long_nv((_p), (_v)))
+#endif
+
+/*
+ * atomic_inc_*_nv - increment and fetch
+ */
+
+#ifndef atomic_inc_int_nv
+#define atomic_inc_int_nv(_p) atomic_add_int_nv((_p), 1)
+#endif
+
+#ifndef atomic_inc_long_nv
+#define atomic_inc_long_nv(_p) atomic_add_long_nv((_p), 1)
+#endif
+
+/*
+ * atomic_inc_* - increment
+ */
+
+#ifndef atomic_inc_int
+#define atomic_inc_int(_p) ((void)atomic_inc_int_nv(_p))
+#endif
+
+#ifndef atomic_inc_long
+#define atomic_inc_long(_p) ((void)atomic_inc_long_nv(_p))
+#endif
+
+/*
+ * atomic_sub_*_nv - sub and fetch
+ */
+
+#ifndef atomic_sub_int_nv
+static inline unsigned int
+atomic_sub_int_nv(volatile unsigned int *p, unsigned int v)
+{
+ return __sync_sub_and_fetch(p, v);
+}
+#endif
+
+#ifndef atomic_sub_long_nv
+static inline unsigned long
+atomic_sub_long_nv(volatile unsigned long *p, unsigned long v)
+{
+ return __sync_sub_and_fetch(p, v);
+}
+#endif
+
+/*
+ * atomic_sub_* - sub
+ */
+
+#ifndef atomic_sub_int
+#define atomic_sub_int(_p, _v) ((void)atomic_sub_int_nv((_p), (_v)))
+#endif
+
+#ifndef atomic_sub_long
+#define atomic_sub_long(_p, _v) ((void)atomic_sub_long_nv((_p), (_v)))
+#endif
+
+/*
+ * atomic_dec_*_nv - decrement and fetch
+ */
+
+#ifndef atomic_dec_int_nv
+#define atomic_dec_int_nv(_p) atomic_sub_int_nv((_p), 1)
+#endif
+
+#ifndef atomic_dec_long_nv
+#define atomic_dec_long_nv(_p) atomic_sub_long_nv((_p), 1)
+#endif
+
+/*
+ * atomic_dec_* - decrement
+ */
+
+#ifndef atomic_dec_int
+#define atomic_dec_int(_p) ((void)atomic_dec_int_nv(_p))
+#endif
+
+#ifndef atomic_dec_long
+#define atomic_dec_long(_p) ((void)atomic_dec_long_nv(_p))
+#endif
+
+/*
+ * memory barriers
+ */
+
+#ifndef membar_enter
+#define membar_enter() __sync_synchronize()
+#endif
+
+#ifndef membar_exit
+#define membar_exit() __sync_synchronize()
+#endif
+
+#ifndef membar_producer
+#define membar_producer() __sync_synchronize()
+#endif
+
+#ifndef membar_consumer
+#define membar_consumer() __sync_synchronize()
+#endif
+
+#ifndef membar_sync
+#define membar_sync() __sync_synchronize()
+#endif
+
+#ifndef membar_enter_after_atomic
+#define membar_enter_after_atomic() membar_enter()
+#endif
+
+#ifndef membar_exit_before_atomic
+#define membar_exit_before_atomic() membar_exit()
+#endif
+
+#ifdef _KERNEL
+
+/*
+ * Force any preceding reads to happen before any subsequent reads that
+ * depend on the value returned by the preceding reads.
+ */
+static inline void
+membar_datadep_consumer(void)
+{
+#ifdef __alpha__
+ membar_consumer();
+#endif
+}
+
+#define READ_ONCE(x) ({ \
+ typeof(x) __tmp = *(volatile typeof(x) *)&(x); \
+ membar_datadep_consumer(); \
+ __tmp; \
+})
+
+#define WRITE_ONCE(x, val) ({ \
+ typeof(x) __tmp = (val); \
+ *(volatile typeof(x) *)&(x) = __tmp; \
+ __tmp; \
+})
+
+#endif /* _KERNEL */
+
+#endif /* _SYS_ATOMIC_H_ */
diff --git a/sys/sys/audioio.h b/sys/sys/audioio.h
new file mode 100644
index 0000000..62a98e8
--- /dev/null
+++ b/sys/sys/audioio.h
@@ -0,0 +1,231 @@
+/* $OpenBSD: audioio.h,v 1.27 2016/09/14 06:12:20 ratchov Exp $ */
+/* $NetBSD: audioio.h,v 1.24 1998/08/13 06:28:41 mrg Exp $ */
+
+/*
+ * Copyright (c) 1991-1993 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the Computer Systems
+ * Engineering Group at Lawrence Berkeley Laboratory.
+ * 4. Neither the name of the University nor of the Laboratory 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 _SYS_AUDIOIO_H_
+#define _SYS_AUDIOIO_H_
+
+#define AUMODE_PLAY 0x01
+#define AUMODE_RECORD 0x02
+
+#define AUDIO_INITPAR(p) \
+ (void)memset((void *)(p), 0xff, sizeof(struct audio_swpar))
+
+/*
+ * argument to AUDIO_SETPAR and AUDIO_GETPAR ioctls
+ */
+struct audio_swpar {
+ unsigned int sig; /* if 1, encoding is signed */
+ unsigned int le; /* if 1, encoding is little-endian */
+ unsigned int bits; /* bits per sample */
+ unsigned int bps; /* bytes per sample */
+ unsigned int msb; /* if 1, bits are msb-aligned */
+ unsigned int rate; /* common play & rec sample rate */
+ unsigned int pchan; /* play channels */
+ unsigned int rchan; /* rec channels */
+ unsigned int nblks; /* number of blocks in play buffer */
+ unsigned int round; /* common frames per block */
+ unsigned int _spare[6];
+};
+
+/*
+ * argument to AUDIO_GETSTATUS
+ */
+struct audio_status {
+ int mode;
+ int pause;
+ int active;
+ int _spare[5];
+};
+
+/*
+ * Parameter for the AUDIO_GETDEV ioctl to determine current
+ * audio devices.
+ */
+#define MAX_AUDIO_DEV_LEN 16
+typedef struct audio_device {
+ char name[MAX_AUDIO_DEV_LEN];
+ char version[MAX_AUDIO_DEV_LEN];
+ char config[MAX_AUDIO_DEV_LEN];
+} audio_device_t;
+
+struct audio_pos {
+ unsigned int play_pos; /* total bytes played */
+ unsigned int play_xrun; /* bytes of silence inserted */
+ unsigned int rec_pos; /* total bytes recorded */
+ unsigned int rec_xrun; /* bytes dropped */
+};
+
+/*
+ * Audio device operations
+ */
+#define AUDIO_GETDEV _IOR('A', 27, struct audio_device)
+#define AUDIO_GETPOS _IOR('A', 35, struct audio_pos)
+#define AUDIO_GETPAR _IOR('A', 36, struct audio_swpar)
+#define AUDIO_SETPAR _IOWR('A', 37, struct audio_swpar)
+#define AUDIO_START _IO('A', 38)
+#define AUDIO_STOP _IO('A', 39)
+#define AUDIO_GETSTATUS _IOR('A', 40, struct audio_status)
+
+/*
+ * Mixer device
+ */
+#define AUDIO_MIN_GAIN 0
+#define AUDIO_MAX_GAIN 255
+
+typedef struct mixer_level {
+ int num_channels;
+ u_char level[8]; /* [num_channels] */
+} mixer_level_t;
+#define AUDIO_MIXER_LEVEL_MONO 0
+#define AUDIO_MIXER_LEVEL_LEFT 0
+#define AUDIO_MIXER_LEVEL_RIGHT 1
+
+/*
+ * Device operations
+ */
+
+typedef struct audio_mixer_name {
+ char name[MAX_AUDIO_DEV_LEN];
+ int msg_id;
+} audio_mixer_name_t;
+
+typedef struct mixer_devinfo {
+ int index;
+ audio_mixer_name_t label;
+ int type;
+#define AUDIO_MIXER_CLASS 0
+#define AUDIO_MIXER_ENUM 1
+#define AUDIO_MIXER_SET 2
+#define AUDIO_MIXER_VALUE 3
+ int mixer_class;
+ int next, prev;
+#define AUDIO_MIXER_LAST -1
+ union {
+ struct audio_mixer_enum {
+ int num_mem;
+ struct {
+ audio_mixer_name_t label;
+ int ord;
+ } member[32];
+ } e;
+ struct audio_mixer_set {
+ int num_mem;
+ struct {
+ audio_mixer_name_t label;
+ int mask;
+ } member[32];
+ } s;
+ struct audio_mixer_value {
+ audio_mixer_name_t units;
+ int num_channels;
+ int delta;
+ } v;
+ } un;
+} mixer_devinfo_t;
+
+
+typedef struct mixer_ctrl {
+ int dev;
+ int type;
+ union {
+ int ord; /* enum */
+ int mask; /* set */
+ mixer_level_t value; /* value */
+ } un;
+} mixer_ctrl_t;
+
+/*
+ * Mixer operations
+ */
+#define AUDIO_MIXER_READ _IOWR('M', 0, mixer_ctrl_t)
+#define AUDIO_MIXER_WRITE _IOWR('M', 1, mixer_ctrl_t)
+#define AUDIO_MIXER_DEVINFO _IOWR('M', 2, mixer_devinfo_t)
+
+/*
+ * Well known device names
+ */
+#define AudioNmicrophone "mic"
+#define AudioNline "line"
+#define AudioNcd "cd"
+#define AudioNdac "dac"
+#define AudioNaux "aux"
+#define AudioNrecord "record"
+#define AudioNvolume "volume"
+#define AudioNmonitor "monitor"
+#define AudioNtreble "treble"
+#define AudioNmid "mid"
+#define AudioNbass "bass"
+#define AudioNbassboost "bassboost"
+#define AudioNspeaker "spkr"
+#define AudioNheadphone "hp"
+#define AudioNoutput "output"
+#define AudioNinput "input"
+#define AudioNmaster "master"
+#define AudioNstereo "stereo"
+#define AudioNmono "mono"
+#define AudioNloudness "loudness"
+#define AudioNspatial "spatial"
+#define AudioNsurround "surround"
+#define AudioNpseudo "pseudo"
+#define AudioNmute "mute"
+#define AudioNenhanced "enhanced"
+#define AudioNpreamp "preamp"
+#define AudioNon "on"
+#define AudioNoff "off"
+#define AudioNmode "mode"
+#define AudioNsource "source"
+#define AudioNfmsynth "fmsynth"
+#define AudioNwave "wave"
+#define AudioNmidi "midi"
+#define AudioNmixerout "mixerout"
+#define AudioNswap "swap" /* swap left and right channels */
+#define AudioNagc "agc"
+#define AudioNdelay "delay"
+#define AudioNselect "select" /* select destination */
+#define AudioNvideo "video"
+#define AudioNcenter "center"
+#define AudioNdepth "depth"
+#define AudioNlfe "lfe"
+#define AudioNextamp "extamp"
+
+#define AudioCinputs "inputs"
+#define AudioCoutputs "outputs"
+#define AudioCrecord "record"
+#define AudioCmonitor "monitor"
+#define AudioCequalization "equalization"
+
+#endif /* !_SYS_AUDIOIO_H_ */
diff --git a/sys/sys/buf.h b/sys/sys/buf.h
new file mode 100644
index 0000000..ea01ac0
--- /dev/null
+++ b/sys/sys/buf.h
@@ -0,0 +1,374 @@
+/* $OpenBSD: buf.h,v 1.112 2019/11/29 01:04:08 beck Exp $ */
+/* $NetBSD: buf.h,v 1.25 1997/04/09 21:12:17 mycroft Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)buf.h 8.7 (Berkeley) 1/21/94
+ */
+
+#ifndef _SYS_BUF_H_
+#define _SYS_BUF_H_
+#include <sys/queue.h>
+#include <sys/tree.h>
+#include <sys/mutex.h>
+#include <uvm/uvm_extern.h>
+
+#define NOLIST ((struct buf *)0x87654321)
+
+struct buf;
+struct vnode;
+
+LIST_HEAD(bufhead, buf);
+
+/*
+ * To avoid including <ufs/ffs/softdep.h>
+ */
+
+LIST_HEAD(workhead, worklist);
+
+/*
+ * Buffer queues
+ */
+#define BUFQ_NSCAN_N 128
+#define BUFQ_FIFO 0
+#define BUFQ_NSCAN 1
+#define BUFQ_DEFAULT BUFQ_NSCAN
+#define BUFQ_HOWMANY 2
+
+/*
+ * Write limits for bufq - defines high and low water marks for how
+ * many kva slots are allowed to be consumed to parallelize writes from
+ * the buffer cache from any individual bufq.
+ */
+#define BUFQ_HI 128
+#define BUFQ_LOW 64
+
+struct bufq_impl;
+
+struct bufq {
+ SLIST_ENTRY(bufq) bufq_entries;
+ struct mutex bufq_mtx;
+ void *bufq_data;
+ u_int bufq_outstanding;
+ u_int bufq_hi;
+ u_int bufq_low;
+ int bufq_waiting;
+ int bufq_stop;
+ int bufq_type;
+ const struct bufq_impl *bufq_impl;
+};
+
+int bufq_init(struct bufq *, int);
+int bufq_switch(struct bufq *, int);
+void bufq_destroy(struct bufq *);
+
+void bufq_queue(struct bufq *, struct buf *);
+struct buf *bufq_dequeue(struct bufq *);
+void bufq_requeue(struct bufq *, struct buf *);
+int bufq_peek(struct bufq *);
+void bufq_drain(struct bufq *);
+
+void bufq_wait(struct bufq *);
+void bufq_done(struct bufq *, struct buf *);
+void bufq_quiesce(void);
+void bufq_restart(void);
+
+/* fifo */
+SIMPLEQ_HEAD(bufq_fifo_head, buf);
+struct bufq_fifo {
+ SIMPLEQ_ENTRY(buf) bqf_entries;
+};
+
+/* nscan */
+SIMPLEQ_HEAD(bufq_nscan_head, buf);
+struct bufq_nscan {
+ SIMPLEQ_ENTRY(buf) bqf_entries;
+};
+
+/* bufq link in struct buf */
+union bufq_data {
+ struct bufq_fifo bufq_data_fifo;
+ struct bufq_nscan bufq_data_nscan;
+};
+
+/*
+ * These are currently used only by the soft dependency code, hence
+ * are stored once in a global variable. If other subsystems wanted
+ * to use these hooks, a pointer to a set of bio_ops could be added
+ * to each buffer.
+ */
+extern struct bio_ops {
+ void (*io_start)(struct buf *);
+ void (*io_complete)(struct buf *);
+ void (*io_deallocate)(struct buf *);
+ void (*io_movedeps)(struct buf *, struct buf *);
+ int (*io_countdeps)(struct buf *, int, int);
+} bioops;
+
+/* The buffer header describes an I/O operation in the kernel. */
+struct buf {
+ RBT_ENTRY(buf) b_rbbufs; /* vnode "hash" tree */
+ LIST_ENTRY(buf) b_list; /* All allocated buffers. */
+ LIST_ENTRY(buf) b_vnbufs; /* Buffer's associated vnode. */
+ TAILQ_ENTRY(buf) b_freelist; /* Free list position if not active. */
+ int cache; /* which cache are we in */
+ struct proc *b_proc; /* Associated proc; NULL if kernel. */
+ volatile long b_flags; /* B_* flags. */
+ long b_bufsize; /* Allocated buffer size. */
+ long b_bcount; /* Valid bytes in buffer. */
+ size_t b_resid; /* Remaining I/O. */
+ int b_error; /* Errno value. */
+ dev_t b_dev; /* Device associated with buffer. */
+ caddr_t b_data; /* associated data */
+ void *b_saveaddr; /* Original b_data for physio. */
+
+ TAILQ_ENTRY(buf) b_valist; /* LRU of va to reuse. */
+
+ union bufq_data b_bufq;
+ struct bufq *b_bq; /* What bufq this buf is on */
+
+ struct uvm_object *b_pobj;
+ struct uvm_object b_uobj; /* Object containing the pages */
+ off_t b_poffs; /* Offset within object */
+
+ daddr_t b_lblkno; /* Logical block number. */
+ daddr_t b_blkno; /* Underlying physical block number. */
+ /* Function to call upon completion.
+ * Will be called at splbio(). */
+ void (*b_iodone)(struct buf *);
+ struct vnode *b_vp; /* Device vnode. */
+ int b_dirtyoff; /* Offset in buffer of dirty region. */
+ int b_dirtyend; /* Offset of end of dirty region. */
+ int b_validoff; /* Offset in buffer of valid region. */
+ int b_validend; /* Offset of end of valid region. */
+ struct workhead b_dep; /* List of filesystem dependencies. */
+};
+
+TAILQ_HEAD(bufqueue, buf);
+
+struct bufcache {
+ int64_t hotbufpages;
+ int64_t warmbufpages;
+ int64_t cachepages;
+ struct bufqueue hotqueue;
+ struct bufqueue coldqueue;
+ struct bufqueue warmqueue;
+};
+
+/* Device driver compatibility definitions. */
+#define b_active b_bcount /* Driver queue head: drive active. */
+
+/*
+ * These flags are kept in b_flags.
+ */
+#define B_WRITE 0x00000000 /* Write buffer (pseudo flag). */
+#define B_AGE 0x00000001 /* Move to age queue when I/O done. */
+#define B_NEEDCOMMIT 0x00000002 /* Needs committing to stable storage */
+#define B_ASYNC 0x00000004 /* Start I/O, do not wait. */
+#define B_BAD 0x00000008 /* Bad block revectoring in progress. */
+#define B_BUSY 0x00000010 /* I/O in progress. */
+#define B_CACHE 0x00000020 /* Bread found us in the cache. */
+#define B_CALL 0x00000040 /* Call b_iodone from biodone. */
+#define B_DELWRI 0x00000080 /* Delay I/O until buffer reused. */
+#define B_DONE 0x00000100 /* I/O completed. */
+#define B_EINTR 0x00000200 /* I/O was interrupted */
+#define B_ERROR 0x00000400 /* I/O error occurred. */
+#define B_INVAL 0x00000800 /* Does not contain valid info. */
+#define B_NOCACHE 0x00001000 /* Do not cache block after use. */
+#define B_PHYS 0x00002000 /* I/O to user memory. */
+#define B_RAW 0x00004000 /* Set by physio for raw transfers. */
+#define B_READ 0x00008000 /* Read buffer. */
+#define B_WANTED 0x00010000 /* Process wants this buffer. */
+#define B_WRITEINPROG 0x00020000 /* Write in progress. */
+#define B_XXX 0x00040000 /* Debugging flag. */
+#define B_DEFERRED 0x00080000 /* Skipped over for cleaning */
+#define B_SCANNED 0x00100000 /* Block already pushed during sync */
+#define B_PDAEMON 0x00200000 /* I/O started by pagedaemon */
+#define B_RELEASED 0x00400000 /* free this buffer after its kvm */
+#define B_WARM 0x00800000 /* buffer is or has been on the warm queue */
+#define B_COLD 0x01000000 /* buffer is on the cold queue */
+#define B_BC 0x02000000 /* buffer is managed by the cache */
+#define B_DMA 0x04000000 /* buffer is DMA reachable */
+
+#define B_BITS "\20\001AGE\002NEEDCOMMIT\003ASYNC\004BAD\005BUSY" \
+ "\006CACHE\007CALL\010DELWRI\011DONE\012EINTR\013ERROR" \
+ "\014INVAL\015NOCACHE\016PHYS\017RAW\020READ" \
+ "\021WANTED\022WRITEINPROG\023XXX(FORMAT)\024DEFERRED" \
+ "\025SCANNED\026DAEMON\027RELEASED\030WARM\031COLD\032BC\033DMA"
+
+/*
+ * Zero out the buffer's data area.
+ */
+#define clrbuf(bp) { \
+ bzero((bp)->b_data, (bp)->b_bcount); \
+ (bp)->b_resid = 0; \
+}
+
+
+/* Flags to low-level allocation routines. */
+#define B_CLRBUF 0x01 /* Request allocated buffer be cleared. */
+#define B_SYNC 0x02 /* Do all allocations synchronously. */
+
+struct cluster_info {
+ daddr_t ci_lastr; /* last read (read-ahead) */
+ daddr_t ci_lastw; /* last write (write cluster) */
+ daddr_t ci_cstart; /* start block of cluster */
+ daddr_t ci_lasta; /* last allocation */
+ int ci_clen; /* length of current cluster */
+ int ci_ralen; /* Read-ahead length */
+ daddr_t ci_maxra; /* last readahead block */
+};
+
+#ifdef _KERNEL
+__BEGIN_DECLS
+/* Kva slots (of size MAXPHYS) reserved for syncer and cleaner. */
+#define RESERVE_SLOTS 4
+/* Buffer cache pages reserved for syncer and cleaner. */
+#define RESERVE_PAGES (RESERVE_SLOTS * MAXPHYS / PAGE_SIZE)
+/* Minimum size of the buffer cache, in pages. */
+#define BCACHE_MIN (RESERVE_PAGES * 2)
+#define UNCLEAN_PAGES (bcstats.numbufpages - bcstats.numcleanpages)
+
+extern struct proc *cleanerproc;
+extern long bufpages; /* Max number of pages for buffers' data */
+extern struct pool bufpool;
+extern struct bufhead bufhead;
+
+void bawrite(struct buf *);
+void bdwrite(struct buf *);
+void biodone(struct buf *);
+int biowait(struct buf *);
+int bread(struct vnode *, daddr_t, int, struct buf **);
+int breadn(struct vnode *, daddr_t, int, daddr_t *, int *, int,
+ struct buf **);
+void brelse(struct buf *);
+#define bremfree bufcache_take
+void bufinit(void);
+void buf_dirty(struct buf *);
+void buf_undirty(struct buf *);
+void buf_adjcnt(struct buf *, long);
+int bwrite(struct buf *);
+struct buf *getblk(struct vnode *, daddr_t, int, int, uint64_t);
+struct buf *geteblk(size_t);
+struct buf *incore(struct vnode *, daddr_t);
+
+/*
+ * bufcache functions
+ */
+void bufcache_take(struct buf *);
+void bufcache_release(struct buf *);
+
+int buf_flip_high(struct buf *);
+void buf_flip_dma(struct buf *);
+struct buf *bufcache_getcleanbuf(int, int);
+struct buf *bufcache_getanycleanbuf(void);
+struct buf *bufcache_getdirtybuf(void);
+
+/*
+ * buf_kvm_init initializes the kvm handling for buffers.
+ * buf_acquire sets the B_BUSY flag and ensures that the buffer is
+ * mapped in the kvm.
+ * buf_release clears the B_BUSY flag and allows the buffer to become
+ * unmapped.
+ * buf_unmap is for internal use only. Unmaps the buffer from kvm.
+ */
+void buf_mem_init(vsize_t);
+void buf_acquire(struct buf *);
+void buf_acquire_unmapped(struct buf *);
+void buf_acquire_nomap(struct buf *);
+void buf_map(struct buf *);
+void buf_release(struct buf *);
+int buf_dealloc_mem(struct buf *);
+void buf_fix_mapping(struct buf *, vsize_t);
+void buf_alloc_pages(struct buf *, vsize_t);
+void buf_free_pages(struct buf *);
+
+void minphys(struct buf *bp);
+int physio(void (*strategy)(struct buf *), dev_t dev, int flags,
+ void (*minphys)(struct buf *), struct uio *uio);
+void brelvp(struct buf *);
+void reassignbuf(struct buf *);
+void bgetvp(struct vnode *, struct buf *);
+
+void buf_replacevnode(struct buf *, struct vnode *);
+void buf_daemon(void *);
+void buf_replacevnode(struct buf *, struct vnode *);
+int bread_cluster(struct vnode *, daddr_t, int, struct buf **);
+
+#ifdef DEBUG
+void buf_print(struct buf *);
+#endif
+
+static __inline void
+buf_start(struct buf *bp)
+{
+ if (bioops.io_start)
+ (*bioops.io_start)(bp);
+}
+
+static __inline void
+buf_complete(struct buf *bp)
+{
+ if (bioops.io_complete)
+ (*bioops.io_complete)(bp);
+}
+
+static __inline void
+buf_deallocate(struct buf *bp)
+{
+ if (bioops.io_deallocate)
+ (*bioops.io_deallocate)(bp);
+}
+
+static __inline void
+buf_movedeps(struct buf *bp, struct buf *bp2)
+{
+ if (bioops.io_movedeps)
+ (*bioops.io_movedeps)(bp, bp2);
+}
+
+static __inline int
+buf_countdeps(struct buf *bp, int i, int islocked)
+{
+ if (bioops.io_countdeps)
+ return ((*bioops.io_countdeps)(bp, i, islocked));
+ else
+ return (0);
+}
+
+void cluster_write(struct buf *, struct cluster_info *, u_quad_t);
+
+__END_DECLS
+#endif /* _KERNEL */
+#endif /* !_SYS_BUF_H_ */
diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h
new file mode 100644
index 0000000..ce9b811
--- /dev/null
+++ b/sys/sys/cdefs.h
@@ -0,0 +1,413 @@
+/* $OpenBSD: cdefs.h,v 1.43 2018/10/29 17:10:40 guenther Exp $ */
+/* $NetBSD: cdefs.h,v 1.16 1996/04/03 20:46:39 christos Exp $ */
+
+/*
+ * Copyright (c) 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Berkeley Software Design, Inc.
+ *
+ * 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.
+ *
+ * @(#)cdefs.h 8.7 (Berkeley) 1/21/94
+ */
+
+#ifndef _SYS_CDEFS_H_
+#define _SYS_CDEFS_H_
+
+#include <machine/cdefs.h>
+
+/*
+ * Macro to test if we're using a specific version of gcc or later.
+ */
+#ifdef __GNUC__
+#define __GNUC_PREREQ__(ma, mi) \
+ ((__GNUC__ > (ma)) || (__GNUC__ == (ma) && __GNUC_MINOR__ >= (mi)))
+#else
+#define __GNUC_PREREQ__(ma, mi) 0
+#endif
+
+/*
+ * The __CONCAT macro is used to concatenate parts of symbol names, e.g.
+ * with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
+ * The __CONCAT macro is a bit tricky -- make sure you don't put spaces
+ * in between its arguments. Do not use __CONCAT on double-quoted strings,
+ * such as those from the __STRING macro: to concatenate strings just put
+ * them next to each other.
+ */
+#if defined(__STDC__) || defined(__cplusplus)
+#define __P(protos) protos /* full-blown ANSI C */
+#define __CONCAT(x,y) x ## y
+#define __STRING(x) #x
+
+#define __const const /* define reserved names to standard */
+#define __signed signed
+#define __volatile volatile
+#if defined(__cplusplus) || defined(__PCC__)
+#define __inline inline /* convert to C++ keyword */
+#else
+#if !defined(__GNUC__)
+#define __inline /* delete GCC keyword */
+#endif /* !__GNUC__ */
+#endif /* !__cplusplus */
+
+#else /* !(__STDC__ || __cplusplus) */
+#define __P(protos) () /* traditional C preprocessor */
+#define __CONCAT(x,y) x/**/y
+#define __STRING(x) "x"
+
+#if !defined(__GNUC__)
+#define __const /* delete pseudo-ANSI C keywords */
+#define __inline
+#define __signed
+#define __volatile
+#endif /* !__GNUC__ */
+#endif /* !(__STDC__ || __cplusplus) */
+
+/*
+ * GCC1 and some versions of GCC2 declare dead (non-returning) and
+ * pure (no side effects) functions using "volatile" and "const";
+ * unfortunately, these then cause warnings under "-ansi -pedantic".
+ * GCC >= 2.5 uses the __attribute__((attrs)) style. All of these
+ * work for GNU C++ (modulo a slight glitch in the C++ grammar in
+ * the distribution version of 2.5.5).
+ */
+
+#if !__GNUC_PREREQ__(2, 5) && !defined(__PCC__)
+#define __attribute__(x) /* delete __attribute__ if non-gcc or gcc1 */
+#if defined(__GNUC__) && !defined(__STRICT_ANSI__)
+#define __dead __volatile
+#define __pure __const
+#endif
+#else
+#define __dead __attribute__((__noreturn__))
+#define __pure __attribute__((__const__))
+#endif
+
+#if __GNUC_PREREQ__(2, 7)
+#define __unused __attribute__((__unused__))
+#else
+#define __unused /* delete */
+#endif
+
+#if __GNUC_PREREQ__(3, 1)
+#define __used __attribute__((__used__))
+#else
+#define __used __unused /* suppress -Wunused warnings */
+#endif
+
+#if __GNUC_PREREQ__(3,4)
+# define __warn_unused_result __attribute__((__warn_unused_result__))
+#else
+# define __warn_unused_result /* delete */
+#endif
+
+#if __GNUC_PREREQ__(3,3) && !defined(__clang__)
+# define __bounded(args) __attribute__ ((__bounded__ args ))
+#else
+# define __bounded(args) /* delete */
+#endif
+
+/*
+ * __returns_twice makes the compiler not assume the function
+ * only returns once. This affects registerisation of variables:
+ * even local variables need to be in memory across such a call.
+ * Example: setjmp()
+ */
+#if __GNUC_PREREQ__(4, 1)
+#define __returns_twice __attribute__((returns_twice))
+#else
+#define __returns_twice
+#endif
+
+/*
+ * __only_inline makes the compiler only use this function definition
+ * for inlining; references that can't be inlined will be left as
+ * external references instead of generating a local copy. The
+ * matching library should include a simple extern definition for
+ * the function to handle those references. c.f. ctype.h
+ */
+#ifdef __GNUC__
+# if __GNUC_PREREQ__(4, 2)
+#define __only_inline extern __inline __attribute__((__gnu_inline__))
+# else
+#define __only_inline extern __inline
+# endif
+#else
+#define __only_inline static __inline
+#endif
+
+/*
+ * GNU C version 2.96 adds explicit branch prediction so that
+ * the CPU back-end can hint the processor and also so that
+ * code blocks can be reordered such that the predicted path
+ * sees a more linear flow, thus improving cache behavior, etc.
+ *
+ * The following two macros provide us with a way to utilize this
+ * compiler feature. Use __predict_true() if you expect the expression
+ * to evaluate to true, and __predict_false() if you expect the
+ * expression to evaluate to false.
+ *
+ * A few notes about usage:
+ *
+ * * Generally, __predict_false() error condition checks (unless
+ * you have some _strong_ reason to do otherwise, in which case
+ * document it), and/or __predict_true() `no-error' condition
+ * checks, assuming you want to optimize for the no-error case.
+ *
+ * * Other than that, if you don't know the likelihood of a test
+ * succeeding from empirical or other `hard' evidence, don't
+ * make predictions.
+ *
+ * * These are meant to be used in places that are run `a lot'.
+ * It is wasteful to make predictions in code that is run
+ * seldomly (e.g. at subsystem initialization time) as the
+ * basic block reordering that this affects can often generate
+ * larger code.
+ */
+#if __GNUC_PREREQ__(2, 96)
+#define __predict_true(exp) __builtin_expect(((exp) != 0), 1)
+#define __predict_false(exp) __builtin_expect(((exp) != 0), 0)
+#else
+#define __predict_true(exp) ((exp) != 0)
+#define __predict_false(exp) ((exp) != 0)
+#endif
+
+/* Delete pseudo-keywords wherever they are not available or needed. */
+#ifndef __dead
+#define __dead
+#define __pure
+#endif
+
+/*
+ * The __packed macro indicates that a variable or structure members
+ * should have the smallest possible alignment, despite any host CPU
+ * alignment requirements.
+ *
+ * The __aligned(x) macro specifies the minimum alignment of a
+ * variable or structure.
+ *
+ * These macros together are useful for describing the layout and
+ * alignment of messages exchanged with hardware or other systems.
+ */
+
+#if __GNUC_PREREQ__(2, 7) || defined(__PCC__)
+#define __packed __attribute__((__packed__))
+#define __aligned(x) __attribute__((__aligned__(x)))
+#endif
+
+#if !__GNUC_PREREQ__(2, 8)
+#define __extension__
+#endif
+
+#if __GNUC_PREREQ__(3, 0)
+#define __malloc __attribute__((__malloc__))
+#else
+#define __malloc
+#endif
+
+#if defined(__cplusplus)
+#define __BEGIN_EXTERN_C extern "C" {
+#define __END_EXTERN_C }
+#else
+#define __BEGIN_EXTERN_C
+#define __END_EXTERN_C
+#endif
+
+#if __GNUC_PREREQ__(4, 0)
+#define __dso_public __attribute__((__visibility__("default")))
+#define __dso_hidden __attribute__((__visibility__("hidden")))
+#define __BEGIN_PUBLIC_DECLS \
+ _Pragma("GCC visibility push(default)") __BEGIN_EXTERN_C
+#define __END_PUBLIC_DECLS __END_EXTERN_C _Pragma("GCC visibility pop")
+#define __BEGIN_HIDDEN_DECLS \
+ _Pragma("GCC visibility push(hidden)") __BEGIN_EXTERN_C
+#define __END_HIDDEN_DECLS __END_EXTERN_C _Pragma("GCC visibility pop")
+#else
+#define __dso_public
+#define __dso_hidden
+#define __BEGIN_PUBLIC_DECLS __BEGIN_EXTERN_C
+#define __END_PUBLIC_DECLS __END_EXTERN_C
+#define __BEGIN_HIDDEN_DECLS __BEGIN_EXTERN_C
+#define __END_HIDDEN_DECLS __END_EXTERN_C
+#endif
+
+#define __BEGIN_DECLS __BEGIN_EXTERN_C
+#define __END_DECLS __END_EXTERN_C
+
+/*
+ * "The nice thing about standards is that there are so many to choose from."
+ * There are a number of "feature test macros" specified by (different)
+ * standards that determine which interfaces and types the header files
+ * should expose.
+ *
+ * Because of inconsistencies in these macros, we define our own
+ * set in the private name space that end in _VISIBLE. These are
+ * always defined and so headers can test their values easily.
+ * Things can get tricky when multiple feature macros are defined.
+ * We try to take the union of all the features requested.
+ *
+ * The following macros are guaranteed to have a value after cdefs.h
+ * has been included:
+ * __POSIX_VISIBLE
+ * __XPG_VISIBLE
+ * __ISO_C_VISIBLE
+ * __BSD_VISIBLE
+ */
+
+/*
+ * X/Open Portability Guides and Single Unix Specifications.
+ * _XOPEN_SOURCE XPG3
+ * _XOPEN_SOURCE && _XOPEN_VERSION = 4 XPG4
+ * _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED = 1 XPG4v2
+ * _XOPEN_SOURCE == 500 XPG5
+ * _XOPEN_SOURCE == 520 XPG5v2
+ * _XOPEN_SOURCE == 600 POSIX 1003.1-2001 with XSI
+ * _XOPEN_SOURCE == 700 POSIX 1003.1-2008 with XSI
+ *
+ * The XPG spec implies a specific value for _POSIX_C_SOURCE.
+ */
+#ifdef _XOPEN_SOURCE
+# if (_XOPEN_SOURCE - 0 >= 700)
+# define __XPG_VISIBLE 700
+# undef _POSIX_C_SOURCE
+# define _POSIX_C_SOURCE 200809L
+# elif (_XOPEN_SOURCE - 0 >= 600)
+# define __XPG_VISIBLE 600
+# undef _POSIX_C_SOURCE
+# define _POSIX_C_SOURCE 200112L
+# elif (_XOPEN_SOURCE - 0 >= 520)
+# define __XPG_VISIBLE 520
+# undef _POSIX_C_SOURCE
+# define _POSIX_C_SOURCE 199506L
+# elif (_XOPEN_SOURCE - 0 >= 500)
+# define __XPG_VISIBLE 500
+# undef _POSIX_C_SOURCE
+# define _POSIX_C_SOURCE 199506L
+# elif (_XOPEN_SOURCE_EXTENDED - 0 == 1)
+# define __XPG_VISIBLE 420
+# elif (_XOPEN_VERSION - 0 >= 4)
+# define __XPG_VISIBLE 400
+# else
+# define __XPG_VISIBLE 300
+# endif
+#endif
+
+/*
+ * POSIX macros, these checks must follow the XOPEN ones above.
+ *
+ * _POSIX_SOURCE == 1 1003.1-1988 (superseded by _POSIX_C_SOURCE)
+ * _POSIX_C_SOURCE == 1 1003.1-1990
+ * _POSIX_C_SOURCE == 2 1003.2-1992
+ * _POSIX_C_SOURCE == 199309L 1003.1b-1993
+ * _POSIX_C_SOURCE == 199506L 1003.1c-1995, 1003.1i-1995,
+ * and the omnibus ISO/IEC 9945-1:1996
+ * _POSIX_C_SOURCE == 200112L 1003.1-2001
+ * _POSIX_C_SOURCE == 200809L 1003.1-2008
+ *
+ * The POSIX spec implies a specific value for __ISO_C_VISIBLE, though
+ * this may be overridden by the _ISOC99_SOURCE macro later.
+ */
+#ifdef _POSIX_C_SOURCE
+# if (_POSIX_C_SOURCE - 0 >= 200809)
+# define __POSIX_VISIBLE 200809
+# define __ISO_C_VISIBLE 1999
+# elif (_POSIX_C_SOURCE - 0 >= 200112)
+# define __POSIX_VISIBLE 200112
+# define __ISO_C_VISIBLE 1999
+# elif (_POSIX_C_SOURCE - 0 >= 199506)
+# define __POSIX_VISIBLE 199506
+# define __ISO_C_VISIBLE 1990
+# elif (_POSIX_C_SOURCE - 0 >= 199309)
+# define __POSIX_VISIBLE 199309
+# define __ISO_C_VISIBLE 1990
+# elif (_POSIX_C_SOURCE - 0 >= 2)
+# define __POSIX_VISIBLE 199209
+# define __ISO_C_VISIBLE 1990
+# else
+# define __POSIX_VISIBLE 199009
+# define __ISO_C_VISIBLE 1990
+# endif
+#elif defined(_POSIX_SOURCE)
+# define __POSIX_VISIBLE 198808
+# define __ISO_C_VISIBLE 0
+#endif
+
+/*
+ * _ANSI_SOURCE means to expose ANSI C89 interfaces only.
+ * If the user defines it in addition to one of the POSIX or XOPEN
+ * macros, assume the POSIX/XOPEN macro(s) should take precedence.
+ */
+#if defined(_ANSI_SOURCE) && !defined(__POSIX_VISIBLE) && \
+ !defined(__XPG_VISIBLE)
+# define __POSIX_VISIBLE 0
+# define __XPG_VISIBLE 0
+# define __ISO_C_VISIBLE 1990
+#endif
+
+/*
+ * _ISOC99_SOURCE, _ISOC11_SOURCE, __STDC_VERSION__, and __cplusplus
+ * override any of the other macros since they are non-exclusive.
+ */
+#if defined(_ISOC11_SOURCE) || \
+ (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112) || \
+ (defined(__cplusplus) && __cplusplus >= 201703)
+# undef __ISO_C_VISIBLE
+# define __ISO_C_VISIBLE 2011
+#elif defined(_ISOC99_SOURCE) || \
+ (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901) || \
+ (defined(__cplusplus) && __cplusplus >= 201103)
+# undef __ISO_C_VISIBLE
+# define __ISO_C_VISIBLE 1999
+#endif
+
+/*
+ * Finally deal with BSD-specific interfaces that are not covered
+ * by any standards. We expose these when none of the POSIX or XPG
+ * macros is defined or if the user explicitly asks for them.
+ */
+#if !defined(_BSD_SOURCE) && \
+ (defined(_ANSI_SOURCE) || defined(__XPG_VISIBLE) || defined(__POSIX_VISIBLE))
+# define __BSD_VISIBLE 0
+#endif
+
+/*
+ * Default values.
+ */
+#ifndef __XPG_VISIBLE
+# define __XPG_VISIBLE 700
+#endif
+#ifndef __POSIX_VISIBLE
+# define __POSIX_VISIBLE 200809
+#endif
+#ifndef __ISO_C_VISIBLE
+# define __ISO_C_VISIBLE 2011
+#endif
+#ifndef __BSD_VISIBLE
+# define __BSD_VISIBLE 1
+#endif
+
+#endif /* !_SYS_CDEFS_H_ */
diff --git a/sys/sys/cdio.h b/sys/sys/cdio.h
new file mode 100644
index 0000000..02069c4
--- /dev/null
+++ b/sys/sys/cdio.h
@@ -0,0 +1,435 @@
+/* $OpenBSD: cdio.h,v 1.17 2017/10/24 09:36:13 jsg Exp $ */
+/* $NetBSD: cdio.h,v 1.11 1996/02/19 18:29:04 scottr Exp $ */
+
+#ifndef _SYS_CDIO_H_
+#define _SYS_CDIO_H_
+
+#include <sys/types.h>
+#include <sys/ioccom.h>
+
+/* Shared between kernel & process */
+
+union msf_lba {
+ struct {
+ u_char unused;
+ u_char minute;
+ u_char second;
+ u_char frame;
+ } msf;
+ u_int32_t lba;
+ u_char addr[4];
+};
+
+struct cd_toc_entry {
+ u_char nothing1;
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+ u_int control:4;
+ u_int addr_type:4;
+#endif
+#if _BYTE_ORDER == _BIG_ENDIAN
+ u_int addr_type:4;
+ u_int control:4;
+#endif
+ u_char track;
+ u_char nothing2;
+ union msf_lba addr;
+};
+
+struct cd_sub_channel_header {
+ u_char nothing1;
+ u_char audio_status;
+#define CD_AS_AUDIO_INVALID 0x00
+#define CD_AS_PLAY_IN_PROGRESS 0x11
+#define CD_AS_PLAY_PAUSED 0x12
+#define CD_AS_PLAY_COMPLETED 0x13
+#define CD_AS_PLAY_ERROR 0x14
+#define CD_AS_NO_STATUS 0x15
+ u_char data_len[2];
+};
+
+struct cd_sub_channel_q_data {
+ u_char data_format;
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+ u_int control:4;
+ u_int addr_type:4;
+#endif
+#if _BYTE_ORDER == _BIG_ENDIAN
+ u_int addr_type:4;
+ u_int control:4;
+#endif
+ u_char track_number;
+ u_char index_number;
+ u_char absaddr[4];
+ u_char reladdr[4];
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+ u_int :7;
+ u_int mc_valid:1;
+#endif
+#if _BYTE_ORDER == _BIG_ENDIAN
+ u_int mc_valid:1;
+ u_int :7;
+#endif
+ u_char mc_number[15];
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+ u_int :7;
+ u_int ti_valid:1;
+#endif
+#if _BYTE_ORDER == _BIG_ENDIAN
+ u_int ti_valid:1;
+ u_int :7;
+#endif
+ u_char ti_number[15];
+};
+
+struct cd_sub_channel_position_data {
+ u_char data_format;
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+ u_int control:4;
+ u_int addr_type:4;
+#endif
+#if _BYTE_ORDER == _BIG_ENDIAN
+ u_int addr_type:4;
+ u_int control:4;
+#endif
+ u_char track_number;
+ u_char index_number;
+ union msf_lba absaddr;
+ union msf_lba reladdr;
+};
+
+struct cd_sub_channel_media_catalog {
+ u_char data_format;
+ u_char nothing1;
+ u_char nothing2;
+ u_char nothing3;
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+ u_int :7;
+ u_int mc_valid:1;
+#endif
+#if _BYTE_ORDER == _BIG_ENDIAN
+ u_int mc_valid:1;
+ u_int :7;
+#endif
+ u_char mc_number[15];
+};
+
+struct cd_sub_channel_track_info {
+ u_char data_format;
+ u_char nothing1;
+ u_char track_number;
+ u_char nothing2;
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+ u_int :7;
+ u_int ti_valid:1;
+#endif
+#if _BYTE_ORDER == _BIG_ENDIAN
+ u_int ti_valid:1;
+ u_int :7;
+#endif
+ u_char ti_number[15];
+};
+
+struct cd_sub_channel_info {
+ struct cd_sub_channel_header header;
+ union {
+ struct cd_sub_channel_q_data q_data;
+ struct cd_sub_channel_position_data position;
+ struct cd_sub_channel_media_catalog media_catalog;
+ struct cd_sub_channel_track_info track_info;
+ } what;
+};
+
+/*
+ * Ioctls for the CD drive
+ */
+struct ioc_play_track {
+ u_char start_track;
+ u_char start_index;
+ u_char end_track;
+ u_char end_index;
+};
+
+#define CDIOCPLAYTRACKS _IOW('c', 1, struct ioc_play_track)
+struct ioc_play_blocks {
+ int blk;
+ int len;
+};
+#define CDIOCPLAYBLOCKS _IOW('c', 2, struct ioc_play_blocks)
+
+struct ioc_read_subchannel {
+ u_char address_format;
+#define CD_LBA_FORMAT 1
+#define CD_MSF_FORMAT 2
+ u_char data_format;
+#define CD_SUBQ_DATA 0
+#define CD_CURRENT_POSITION 1
+#define CD_MEDIA_CATALOG 2
+#define CD_TRACK_INFO 3
+ u_char track;
+ int data_len;
+ struct cd_sub_channel_info *data;
+};
+#define CDIOCREADSUBCHANNEL _IOWR('c', 3, struct ioc_read_subchannel)
+
+struct ioc_toc_header {
+ u_short len;
+ u_char starting_track;
+ u_char ending_track;
+};
+
+#define CDIOREADTOCHEADER _IOR('c', 4, struct ioc_toc_header)
+
+struct ioc_read_toc_entry {
+ u_char address_format;
+ u_char starting_track;
+#define CD_TRACK_LEADOUT 0xaa
+ u_short data_len;
+ struct cd_toc_entry *data;
+};
+#define CDIOREADTOCENTRIES _IOWR('c', 5, struct ioc_read_toc_entry)
+#define CDIOREADTOCENTRYS CDIOREADTOCENTRIES
+
+/* read LBA start of a given session; 0=last, others not yet supported */
+#define CDIOREADMSADDR _IOWR('c', 6, int)
+
+struct ioc_patch {
+ u_char patch[4]; /* one for each channel */
+};
+#define CDIOCSETPATCH _IOW('c', 9, struct ioc_patch)
+
+struct ioc_vol {
+ u_char vol[4]; /* one for each channel */
+};
+#define CDIOCGETVOL _IOR('c', 10, struct ioc_vol)
+#define CDIOCSETVOL _IOW('c', 11, struct ioc_vol)
+#define CDIOCSETMONO _IO('c', 12)
+#define CDIOCSETSTEREO _IO('c', 13)
+#define CDIOCSETMUTE _IO('c', 14)
+#define CDIOCSETLEFT _IO('c', 15)
+#define CDIOCSETRIGHT _IO('c', 16)
+#define CDIOCSETDEBUG _IO('c', 17)
+#define CDIOCCLRDEBUG _IO('c', 18)
+#define CDIOCPAUSE _IO('c', 19)
+#define CDIOCRESUME _IO('c', 20)
+#define CDIOCRESET _IO('c', 21)
+#define CDIOCSTART _IO('c', 22)
+#define CDIOCSTOP _IO('c', 23)
+#define CDIOCEJECT _IO('c', 24)
+#define CDIOCALLOW _IO('c', 25)
+#define CDIOCPREVENT _IO('c', 26)
+#define CDIOCCLOSE _IO('c', 27)
+
+struct ioc_play_msf {
+ u_char start_m;
+ u_char start_s;
+ u_char start_f;
+ u_char end_m;
+ u_char end_s;
+ u_char end_f;
+};
+#define CDIOCPLAYMSF _IOW('c', 25, struct ioc_play_msf)
+
+struct ioc_load_unload {
+ u_char options;
+#define CD_LU_ABORT 0x1 /* NOTE: These are the same as the ATAPI */
+#define CD_LU_UNLOAD 0x2 /* op values for the LOAD_UNLOAD command */
+#define CD_LU_LOAD 0x3
+ u_char slot;
+};
+#define CDIOCLOADUNLOAD _IOW('c', 26, struct ioc_load_unload)
+
+/* DVD definitions */
+
+/* DVD-ROM Specific ioctls */
+#define DVD_READ_STRUCT _IOWR('d', 0, union dvd_struct)
+#define DVD_WRITE_STRUCT _IOWR('d', 1, union dvd_struct)
+#define DVD_AUTH _IOWR('d', 2, union dvd_authinfo)
+
+#define GPCMD_READ_DVD_STRUCTURE 0xad
+#define GPCMD_SEND_DVD_STRUCTURE 0xad
+#define GPCMD_REPORT_KEY 0xa4
+#define GPCMD_SEND_KEY 0xa3
+
+/* DVD struct types */
+#define DVD_STRUCT_PHYSICAL 0x00
+#define DVD_STRUCT_COPYRIGHT 0x01
+#define DVD_STRUCT_DISCKEY 0x02
+#define DVD_STRUCT_BCA 0x03
+#define DVD_STRUCT_MANUFACT 0x04
+
+struct dvd_layer {
+ u_int8_t book_version;
+ u_int8_t book_type;
+ u_int8_t min_rate;
+ u_int8_t disc_size;
+ u_int8_t layer_type;
+ u_int8_t track_path;
+ u_int8_t nlayers;
+ u_int8_t track_density;
+ u_int8_t linear_density;
+ u_int8_t bca;
+ u_int32_t start_sector;
+ u_int32_t end_sector;
+ u_int32_t end_sector_l0;
+};
+
+struct dvd_physical {
+ u_int8_t type;
+
+ u_int8_t layer_num;
+ struct dvd_layer layer[4];
+};
+
+struct dvd_copyright {
+ u_int8_t type;
+
+ u_int8_t layer_num;
+ u_int8_t cpst;
+ u_int8_t rmi;
+};
+
+struct dvd_disckey {
+ u_int8_t type;
+
+ u_int8_t agid;
+ u_int8_t value[2048];
+};
+
+struct dvd_bca {
+ u_int8_t type;
+
+ int len;
+ u_int8_t value[188];
+};
+
+struct dvd_manufact {
+ u_int8_t type;
+
+ u_int8_t layer_num;
+ int len;
+ u_int8_t value[2048];
+};
+
+union dvd_struct {
+ u_int8_t type;
+
+ struct dvd_physical physical;
+ struct dvd_copyright copyright;
+ struct dvd_disckey disckey;
+ struct dvd_bca bca;
+ struct dvd_manufact manufact;
+};
+
+/*
+ * DVD authentication ioctl
+ */
+
+/* Authentication states */
+#define DVD_LU_SEND_AGID 0
+#define DVD_HOST_SEND_CHALLENGE 1
+#define DVD_LU_SEND_KEY1 2
+#define DVD_LU_SEND_CHALLENGE 3
+#define DVD_HOST_SEND_KEY2 4
+
+/* Termination states */
+#define DVD_AUTH_ESTABLISHED 5
+#define DVD_AUTH_FAILURE 6
+
+/* Other functions */
+#define DVD_LU_SEND_TITLE_KEY 7
+#define DVD_LU_SEND_ASF 8
+#define DVD_INVALIDATE_AGID 9
+#define DVD_LU_SEND_RPC_STATE 10
+#define DVD_HOST_SEND_RPC_STATE 11
+
+#if 0
+/* State data */
+typedef u_int8_t dvd_key[5]; /* 40-bit value, MSB is first elem. */
+typedef u_int8_t dvd_challenge[10]; /* 80-bit value, MSB is first elem. */
+#endif
+
+#define DVD_KEY_SIZE 5
+#define DVD_CHALLENGE_SIZE 10
+
+struct dvd_lu_send_agid {
+ u_int8_t type;
+
+ u_int8_t agid;
+};
+
+struct dvd_host_send_challenge {
+ u_int8_t type;
+
+ u_int8_t agid;
+ u_int8_t chal[DVD_CHALLENGE_SIZE];
+};
+
+struct dvd_send_key {
+ u_int8_t type;
+
+ u_int8_t agid;
+ u_int8_t key[DVD_KEY_SIZE];
+};
+
+struct dvd_lu_send_challenge {
+ u_int8_t type;
+
+ u_int8_t agid;
+ u_int8_t chal[DVD_CHALLENGE_SIZE];
+};
+
+#define DVD_CPM_NO_COPYRIGHT 0
+#define DVD_CPM_COPYRIGHTED 1
+
+#define DVD_CP_SEC_NONE 0
+#define DVD_CP_SEC_EXIST 1
+
+#define DVD_CGMS_UNRESTRICTED 0
+#define DVD_CGMS_SINGLE 2
+#define DVD_CGMS_RESTRICTED 3
+
+struct dvd_lu_send_title_key {
+ u_int8_t type;
+
+ u_int8_t agid;
+ u_int8_t title_key[DVD_KEY_SIZE];
+ int lba;
+ u_int8_t cpm;
+ u_int8_t cp_sec;
+ u_int8_t cgms;
+};
+
+struct dvd_lu_send_asf {
+ u_int8_t type;
+
+ u_int8_t agid;
+ u_int8_t asf;
+};
+
+struct dvd_host_send_rpcstate {
+ u_int8_t type;
+ u_int8_t pdrc;
+};
+
+struct dvd_lu_send_rpcstate {
+ u_int8_t type;
+ u_int8_t vra;
+ u_int8_t ucca;
+ u_int8_t region_mask;
+ u_int8_t rpc_scheme;
+ };
+
+union dvd_authinfo {
+ u_int8_t type;
+
+ struct dvd_lu_send_agid lsa;
+ struct dvd_host_send_challenge hsc;
+ struct dvd_send_key lsk;
+ struct dvd_lu_send_challenge lsc;
+ struct dvd_send_key hsk;
+ struct dvd_lu_send_title_key lstk;
+ struct dvd_lu_send_asf lsasf;
+ struct dvd_host_send_rpcstate hrpcs;
+ struct dvd_lu_send_rpcstate lrpcs;
+};
+#endif /* !_SYS_CDIO_H_ */
diff --git a/sys/sys/chio.h b/sys/sys/chio.h
new file mode 100644
index 0000000..88afaa9
--- /dev/null
+++ b/sys/sys/chio.h
@@ -0,0 +1,176 @@
+/* $OpenBSD: chio.h,v 1.7 2006/05/31 03:01:44 beck Exp $ */
+/* $NetBSD: chio.h,v 1.8 1996/04/03 00:25:21 thorpej Exp $ */
+
+/*
+ * Copyright (c) 1996 Jason R. Thorpe <thorpej@and.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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgements:
+ * This product includes software developed by Jason R. Thorpe
+ * for And Communications, http://www.and.com/
+ * 4. 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.
+ */
+
+#ifndef _SYS_CHIO_H_
+#define _SYS_CHIO_H_
+
+/*
+ * Element types. Used as "to" and "from" type indicators in move
+ * and exchange operations.
+ *
+ * Note that code in sys/scsi/ch.c relies on these values (uses them
+ * as offsets in an array, and other evil), so don't muck with them
+ * unless you know what you're doing.
+ */
+#define CHET_MT 0 /* medium transport (picker) */
+#define CHET_ST 1 /* storage transport (slot) */
+#define CHET_IE 2 /* import/export (portal) */
+#define CHET_DT 3 /* data transfer (drive) */
+
+/*
+ * Maximum length of a volume identification string
+ */
+#define CH_VOLTAG_MAXLEN 32
+
+/*
+ * Structure used to execute a MOVE MEDIUM command.
+ */
+struct changer_move {
+ int cm_fromtype; /* element type to move from */
+ int cm_fromunit; /* logical unit of from element */
+ int cm_totype; /* element type to move to */
+ int cm_tounit; /* logical unit of to element */
+ int cm_flags; /* misc. flags */
+};
+
+/* cm_flags */
+#define CM_INVERT 0x01 /* invert media */
+
+/*
+ * Structure used to execute an EXCHANGE MEDIUM command. In an
+ * exchange operation, the following steps occur:
+ *
+ * - media from source is moved to first destination.
+ *
+ * - media previously occupying first destination is moved
+ * to the second destination.
+ *
+ * The second destination may or may not be the same as the source.
+ * In the case of a simple exchange, the source and second destination
+ * are the same.
+ */
+struct changer_exchange {
+ int ce_srctype; /* element type of source */
+ int ce_srcunit; /* logical unit of source */
+ int ce_fdsttype; /* element type of first destination */
+ int ce_fdstunit; /* logical unit of first destination */
+ int ce_sdsttype; /* element type of second destination */
+ int ce_sdstunit; /* logical unit of second destination */
+ int ce_flags; /* misc. flags */
+};
+
+/* ce_flags */
+#define CE_INVERT1 0x01 /* invert media 1 */
+#define CE_INVERT2 0x02 /* invert media 2 */
+
+/*
+ * Structure used to execute a POSITION TO ELEMENT command. This
+ * moves the current picker in front of the specified element.
+ */
+struct changer_position {
+ int cp_type; /* element type */
+ int cp_unit; /* logical unit of element */
+ int cp_flags; /* misc. flags */
+};
+
+/* cp_flags */
+#define CP_INVERT 0x01 /* invert picker */
+
+/*
+ * Data returned by CHIOGPARAMS.
+ */
+struct changer_params {
+ int cp_curpicker; /* current picker */
+ int cp_npickers; /* number of pickers */
+ int cp_nslots; /* number of slots */
+ int cp_nportals; /* number of import/export portals */
+ int cp_ndrives; /* number of drives */
+};
+
+struct changer_voltag {
+ u_char cv_volid[CH_VOLTAG_MAXLEN + 1];
+ u_int16_t cv_serial;
+};
+
+struct changer_element_status {
+ int ces_type; /* element type */
+ u_int8_t ces_flags; /* flags */
+ struct changer_voltag ces_pvoltag; /* primary voltag */
+ struct changer_voltag ces_avoltag; /* alternate voltag */
+};
+
+/*
+ * Command used to get element status.
+ */
+struct changer_element_status_request {
+ int cesr_type; /* element type */
+ int cesr_flags;
+#define CESR_VOLTAGS 0x01
+
+ struct changer_element_status *cesr_data; /* pre-allocated data storage */
+};
+
+/*
+ * Data returned by CHIOGSTATUS is an array of flags bytes.
+ * Not all flags have meaning for all element types.
+ */
+#define CESTATUS_FULL 0x01 /* element is full */
+#define CESTATUS_IMPEXP 0x02 /* media deposited by operator */
+#define CESTATUS_EXCEPT 0x04 /* element in abnormal state */
+#define CESTATUS_ACCESS 0x08 /* media accessible by picker */
+#define CESTATUS_EXENAB 0x10 /* element supports exporting */
+#define CESTATUS_INENAB 0x20 /* element supports importing */
+
+#define CESTATUS_PICKER_MASK 0x05 /* flags valid for pickers */
+#define CESTATUS_SLOT_MASK 0x0c /* flags valid for slots */
+#define CESTATUS_PORTAL_MASK 0x3f /* flags valid for portals */
+#define CESTATUS_DRIVE_MASK 0x0c /* flags valid for drives */
+
+#define CESTATUS_BITS \
+ "\20\6INEAB\5EXENAB\4ACCESS\3EXCEPT\2IMPEXP\1FULL"
+
+/*
+ * XXX we have to renumber this since it chashes w/ the
+ * cdio ioctls, O* interface goes away right after 3.3
+ */
+#define CHIOMOVE _IOW('c', 0x41, struct changer_move)
+#define CHIOEXCHANGE _IOW('c', 0x42, struct changer_exchange)
+#define CHIOPOSITION _IOW('c', 0x43, struct changer_position)
+#define CHIOGPICKER _IOR('c', 0x44, int)
+#define CHIOSPICKER _IOW('c', 0x45, int)
+#define CHIOGPARAMS _IOR('c', 0x46, struct changer_params)
+#define CHIOGSTATUS _IOW('c', 0x48, struct changer_element_status_request)
+
+#endif /* _SYS_CHIO_H_ */
diff --git a/sys/sys/conf.h b/sys/sys/conf.h
new file mode 100644
index 0000000..48470a0
--- /dev/null
+++ b/sys/sys/conf.h
@@ -0,0 +1,633 @@
+/* $OpenBSD: conf.h,v 1.150 2020/04/21 08:29:27 mpi Exp $ */
+/* $NetBSD: conf.h,v 1.33 1996/05/03 20:03:32 christos Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)conf.h 8.3 (Berkeley) 1/21/94
+ */
+
+
+#ifndef _SYS_CONF_H_
+#define _SYS_CONF_H_
+
+/*
+ * Definitions of device driver entry switches
+ */
+
+struct buf;
+struct proc;
+struct tty;
+struct uio;
+struct vnode;
+struct knote;
+
+/*
+ * Types for d_type
+ */
+#define D_DISK 1
+#define D_TTY 2
+
+/*
+ * Flags for d_flags
+ */
+#define D_CLONE 0x0001 /* clone upon open */
+
+#ifdef _KERNEL
+
+#define dev_type_open(n) int n(dev_t, int, int, struct proc *)
+#define dev_type_close(n) int n(dev_t, int, int, struct proc *)
+#define dev_type_strategy(n) void n(struct buf *)
+#define dev_type_ioctl(n) \
+ int n(dev_t, u_long, caddr_t, int, struct proc *)
+
+#define dev_decl(n,t) __CONCAT(dev_type_,t)(__CONCAT(n,t))
+#define dev_init(c,n,t) \
+ ((c) > 0 ? __CONCAT(n,t) : (__CONCAT(dev_type_,t)((*))) enxio)
+
+#endif /* _KERNEL */
+
+/*
+ * Block device switch table
+ */
+struct bdevsw {
+ int (*d_open)(dev_t dev, int oflags, int devtype,
+ struct proc *p);
+ int (*d_close)(dev_t dev, int fflag, int devtype,
+ struct proc *p);
+ void (*d_strategy)(struct buf *bp);
+ int (*d_ioctl)(dev_t dev, u_long cmd, caddr_t data,
+ int fflag, struct proc *p);
+ int (*d_dump)(dev_t dev, daddr_t blkno, caddr_t va,
+ size_t size);
+ daddr_t (*d_psize)(dev_t dev);
+ u_int d_type;
+ /* u_int d_flags; */
+};
+
+#ifdef _KERNEL
+
+extern struct bdevsw bdevsw[];
+
+/* bdevsw-specific types */
+#define dev_type_dump(n) int n(dev_t, daddr_t, caddr_t, size_t)
+#define dev_type_size(n) daddr_t n(dev_t)
+
+/* bdevsw-specific initializations */
+#define dev_size_init(c,n) (c > 0 ? __CONCAT(n,size) : 0)
+
+#define bdev_decl(n) \
+ dev_decl(n,open); dev_decl(n,close); dev_decl(n,strategy); \
+ dev_decl(n,ioctl); dev_decl(n,dump); dev_decl(n,size)
+
+#define bdev_disk_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), \
+ dev_init(c,n,strategy), dev_init(c,n,ioctl), \
+ dev_init(c,n,dump), dev_size_init(c,n), D_DISK }
+
+#define bdev_swap_init(c,n) { \
+ (dev_type_open((*))) enodev, (dev_type_close((*))) enodev, \
+ dev_init(c,n,strategy), (dev_type_ioctl((*))) enodev, \
+ (dev_type_dump((*))) enodev, 0 }
+
+#define bdev_notdef() { \
+ (dev_type_open((*))) enodev, (dev_type_close((*))) enodev, \
+ (dev_type_strategy((*))) enodev, (dev_type_ioctl((*))) enodev, \
+ (dev_type_dump((*))) enodev, 0 }
+
+#endif
+
+/*
+ * Character device switch table
+ */
+struct cdevsw {
+ int (*d_open)(dev_t dev, int oflags, int devtype,
+ struct proc *p);
+ int (*d_close)(dev_t dev, int fflag, int devtype,
+ struct proc *);
+ int (*d_read)(dev_t dev, struct uio *uio, int ioflag);
+ int (*d_write)(dev_t dev, struct uio *uio, int ioflag);
+ int (*d_ioctl)(dev_t dev, u_long cmd, caddr_t data,
+ int fflag, struct proc *p);
+ int (*d_stop)(struct tty *tp, int rw);
+ struct tty *
+ (*d_tty)(dev_t dev);
+ int (*d_poll)(dev_t dev, int events, struct proc *p);
+ paddr_t (*d_mmap)(dev_t, off_t, int);
+ u_int d_type;
+ u_int d_flags;
+ int (*d_kqfilter)(dev_t dev, struct knote *kn);
+};
+
+#ifdef _KERNEL
+
+extern struct cdevsw cdevsw[];
+
+/* cdevsw-specific types */
+#define dev_type_read(n) int n(dev_t, struct uio *, int)
+#define dev_type_write(n) int n(dev_t, struct uio *, int)
+#define dev_type_stop(n) int n(struct tty *, int)
+#define dev_type_tty(n) struct tty *n(dev_t)
+#define dev_type_poll(n) int n(dev_t, int, struct proc *)
+#define dev_type_mmap(n) paddr_t n(dev_t, off_t, int)
+#define dev_type_kqfilter(n) int n(dev_t, struct knote *)
+
+#define cdev_decl(n) \
+ dev_decl(n,open); dev_decl(n,close); dev_decl(n,read); \
+ dev_decl(n,write); dev_decl(n,ioctl); dev_decl(n,stop); \
+ dev_decl(n,tty); dev_decl(n,poll); dev_decl(n,mmap); \
+ dev_decl(n,kqfilter)
+
+/* open, close, read, write, ioctl */
+#define cdev_disk_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
+ 0, seltrue, (dev_type_mmap((*))) enodev, \
+ D_DISK, 0, seltrue_kqfilter }
+
+/* open, close, read, write, ioctl */
+#define cdev_tape_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
+ 0, seltrue, (dev_type_mmap((*))) enodev, \
+ 0, 0, seltrue_kqfilter }
+
+/* open, close, read, write, ioctl, stop, tty */
+#define cdev_tty_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), dev_init(c,n,stop), \
+ dev_init(c,n,tty), ttpoll, (dev_type_mmap((*))) enodev, \
+ D_TTY, 0, ttkqfilter }
+
+/* open, close, read, ioctl, poll, kqfilter */
+#define cdev_mouse_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, dev_init(c,n,poll), \
+ (dev_type_mmap((*))) enodev , 0, 0, dev_init(c,n,kqfilter) }
+
+#define cdev_notdef() { \
+ (dev_type_open((*))) enodev, (dev_type_close((*))) enodev, \
+ (dev_type_read((*))) enodev, (dev_type_write((*))) enodev, \
+ (dev_type_ioctl((*))) enodev, (dev_type_stop((*))) enodev, \
+ 0, seltrue, (dev_type_mmap((*))) enodev }
+
+/* open, close, read, write, ioctl, poll, kqfilter -- XXX should be a tty */
+#define cdev_cn_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), dev_init(c,n,stop), \
+ 0, dev_init(c,n,poll), (dev_type_mmap((*))) enodev, \
+ D_TTY, 0, dev_init(c,n,kqfilter) }
+
+/* open, read, write, ioctl, poll, kqfilter -- XXX should be a tty */
+#define cdev_ctty_init(c,n) { \
+ dev_init(c,n,open), (dev_type_close((*))) nullop, dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) nullop, \
+ 0, dev_init(c,n,poll), (dev_type_mmap((*))) enodev, \
+ D_TTY, 0, dev_init(c,n,kqfilter) }
+
+/* open, close, read, write, ioctl, mmap */
+#define cdev_mm_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, seltrue, dev_init(c,n,mmap), \
+ 0, 0, seltrue_kqfilter }
+
+/* open, close, read, write, ioctl, tty, poll, kqfilter */
+#define cdev_ptc_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) nullop, \
+ dev_init(c,n,tty), dev_init(c,n,poll), (dev_type_mmap((*))) enodev, \
+ D_TTY, 0, dev_init(c,n,kqfilter) }
+
+/* open, close, read, write, ioctl, mmap */
+#define cdev_ptm_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, (dev_type_mmap((*))) enodev }
+
+/* open, close, read, ioctl, poll, kqfilter XXX should be a generic device */
+#define cdev_log_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, dev_init(c,n,poll), \
+ (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,n,kqfilter) }
+
+/* open */
+#define cdev_fd_init(c,n) { \
+ dev_init(c,n,open), (dev_type_close((*))) enodev, \
+ (dev_type_read((*))) enodev, (dev_type_write((*))) enodev, \
+ (dev_type_ioctl((*))) enodev, (dev_type_stop((*))) enodev, \
+ 0, selfalse, (dev_type_mmap((*))) enodev }
+
+/* open, close, read, write, ioctl, poll, kqfilter -- XXX should be generic device */
+#define cdev_tun_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
+ 0, dev_init(c,n,poll), (dev_type_mmap((*))) enodev, \
+ 0, 0, dev_init(c,n,kqfilter) }
+
+/* open, close, read, write, ioctl, poll, kqfilter -- XXX should be generic device */
+#define cdev_switch_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
+ 0, dev_init(c,n,poll), (dev_type_mmap((*))) enodev, \
+ 0, 0, dev_init(c,n,kqfilter) }
+
+/* open, close, ioctl, poll, kqfilter -- XXX should be generic device */
+#define cdev_vscsi_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), \
+ (dev_type_read((*))) enodev, (dev_type_write((*))) enodev, \
+ dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
+ 0, dev_init(c,n,poll), (dev_type_mmap((*))) enodev, \
+ 0, 0, dev_init(c,n,kqfilter) }
+
+/* open, close, read, write, ioctl, poll, kqfilter -- XXX should be generic device */
+#define cdev_pppx_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
+ 0, dev_init(c,n,poll), (dev_type_mmap((*))) enodev, \
+ 0, 0, dev_init(c,n,kqfilter) }
+
+/* open, close, read, write, ioctl, poll, kqfilter, cloning -- XXX should be generic device */
+#define cdev_bpf_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
+ 0, dev_init(c,n,poll), (dev_type_mmap((*))) enodev, \
+ 0, D_CLONE, dev_init(c,n,kqfilter) }
+
+/* open, close, ioctl */
+#define cdev_ch_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_type_mmap((*))) enodev }
+
+/* open, close, ioctl */
+#define cdev_uk_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_type_mmap((*))) enodev }
+
+/* open, close, ioctl, mmap */
+#define cdev_fb_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ dev_init(c,n,mmap) }
+
+/* open, close, read, write, ioctl, poll, kqfilter */
+#define cdev_audio_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, dev_init(c,n,poll), \
+ (dev_type_mmap((*))) enodev }
+
+/* open, close, read, write, ioctl, poll, kqfilter */
+#define cdev_midi_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, dev_init(c,n,poll), \
+ (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,n,kqfilter) }
+
+/* open, close, read */
+#define cdev_ksyms_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ (dev_type_write((*))) enodev, (dev_type_ioctl((*))) enodev, \
+ (dev_type_stop((*))) enodev, 0, seltrue, \
+ (dev_type_mmap((*))) enodev, 0, 0, seltrue_kqfilter }
+
+/* open, close, read, write, ioctl, stop, tty, poll, mmap, kqfilter */
+#define cdev_wsdisplay_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), dev_init(c,n,stop), \
+ dev_init(c,n,tty), dev_init(c,n,poll), dev_init(c,n,mmap), \
+ D_TTY, 0, dev_init(c,n,kqfilter) }
+
+/* open, close, read, write, ioctl, poll, kqfilter */
+#define cdev_random_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
+ 0, seltrue, (dev_type_mmap((*))) enodev, \
+ 0, 0, dev_init(c,n,kqfilter) }
+
+/* open, close, ioctl, poll, nokqfilter */
+#define cdev_usb_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_type_mmap((*))) enodev }
+
+/* open, close, write */
+#define cdev_ulpt_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ dev_init(c,n,write), (dev_type_ioctl((*))) enodev, \
+ (dev_type_stop((*))) enodev, 0, selfalse, (dev_type_mmap((*))) enodev }
+
+/* open, close, ioctl */
+#define cdev_pf_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_type_mmap((*))) enodev }
+
+/* open, close, read, write, ioctl, poll, kqfilter */
+#define cdev_usbdev_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
+ 0, dev_init(c,n,poll), (dev_type_mmap((*))) enodev, 0, 0, \
+ dev_init(c,n,kqfilter) }
+
+/* open, close, read, write, ioctl, poll, kqfilter */
+#define cdev_fido_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,uhid,close), dev_init(c,uhid,read), \
+ dev_init(c,uhid,write), dev_init(c,fido,ioctl), \
+ (dev_type_stop((*))) enodev, 0, dev_init(c,uhid,poll), \
+ (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,uhid,kqfilter) }
+
+/* open, close, init */
+#define cdev_pci_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_type_mmap((*))) enodev }
+
+/* open, close, ioctl */
+#define cdev_radio_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_type_mmap((*))) enodev }
+
+/* open, close, ioctl, read, mmap, poll */
+#define cdev_video_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, dev_init(c,n,poll), \
+ dev_init(c,n,mmap) }
+
+/* open, close, write, ioctl */
+#define cdev_spkr_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ dev_init(c,n,write), dev_init(c,n,ioctl), (dev_type_stop((*))) enodev, \
+ 0, seltrue, (dev_type_mmap((*))) enodev, \
+ 0, 0, seltrue_kqfilter }
+
+/* open, close, write */
+#define cdev_lpt_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ dev_init(c,n,write), (dev_type_ioctl((*))) enodev, \
+ (dev_type_stop((*))) enodev, 0, seltrue, (dev_type_mmap((*))) enodev, \
+ 0, 0, seltrue_kqfilter }
+
+/* open, close, read, ioctl, mmap */
+#define cdev_bktr_init(c, n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, seltrue, dev_init(c,n,mmap), \
+ 0, 0, seltrue_kqfilter }
+
+/* open, close, read, ioctl, poll, kqfilter */
+#define cdev_hotplug_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, dev_init(c,n,poll), \
+ (dev_type_mmap((*))) enodev, 0, 0, dev_init(c,n,kqfilter) }
+
+/* open, close, ioctl */
+#define cdev_gpio_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_type_mmap((*))) enodev }
+
+/* open, close, ioctl */
+#define cdev_bio_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_type_mmap((*))) enodev }
+
+/* open, close, read, ioctl, poll, mmap, nokqfilter */
+#define cdev_drm_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c, n, read), \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, dev_init(c,n,poll), \
+ dev_init(c,n,mmap), 0, D_CLONE, dev_init(c,n,kqfilter) }
+
+/* open, close, ioctl */
+#define cdev_amdmsr_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_type_mmap((*))) enodev }
+
+/* open, close, read, write, poll, ioctl */
+#define cdev_fuse_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ dev_init(c,n,write), dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, dev_init(c,n,poll), \
+ (dev_type_mmap((*))) enodev, 0, D_CLONE, dev_init(c,n,kqfilter) }
+
+/* open, close, ioctl */
+#define cdev_pvbus_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), \
+ (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, \
+ dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_type_mmap((*))) enodev }
+
+/* open, close, ioctl */
+#define cdev_ipmi_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_type_mmap((*))) enodev, 0 }
+
+/* open, close, ioctl, mmap */
+#define cdev_kcov_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), (dev_type_read((*))) enodev, \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_init(c,n,mmap)), 0, D_CLONE }
+
+/* open, close, read, ioctl */
+#define cdev_dt_init(c,n) { \
+ dev_init(c,n,open), dev_init(c,n,close), dev_init(c,n,read), \
+ (dev_type_write((*))) enodev, dev_init(c,n,ioctl), \
+ (dev_type_stop((*))) enodev, 0, selfalse, \
+ (dev_type_mmap((*))) enodev, 0, D_CLONE }
+
+#endif
+
+/*
+ * Line discipline switch table
+ */
+struct linesw {
+ int (*l_open)(dev_t dev, struct tty *tp, struct proc *p);
+ int (*l_close)(struct tty *tp, int flags, struct proc *p);
+ int (*l_read)(struct tty *tp, struct uio *uio,
+ int flag);
+ int (*l_write)(struct tty *tp, struct uio *uio,
+ int flag);
+ int (*l_ioctl)(struct tty *tp, u_long cmd, caddr_t data,
+ int flag, struct proc *p);
+ int (*l_rint)(int c, struct tty *tp);
+ int (*l_start)(struct tty *tp);
+ int (*l_modem)(struct tty *tp, int flag);
+};
+
+#ifdef _KERNEL
+extern struct linesw linesw[];
+#endif
+
+/*
+ * Swap device table
+ */
+struct swdevt {
+ dev_t sw_dev;
+ int sw_flags;
+};
+#define SW_FREED 0x01
+#define SW_SEQUENTIAL 0x02
+#define sw_freed sw_flags /* XXX compat */
+
+#ifdef _KERNEL
+extern struct swdevt swdevt[];
+extern int chrtoblktbl[];
+extern int nchrtoblktbl;
+
+struct bdevsw *bdevsw_lookup(dev_t);
+struct cdevsw *cdevsw_lookup(dev_t);
+dev_t chrtoblk(dev_t);
+dev_t blktochr(dev_t);
+int iskmemdev(dev_t);
+int iszerodev(dev_t);
+dev_t getnulldev(void);
+
+cdev_decl(filedesc);
+
+cdev_decl(log);
+
+#define ptstty ptytty
+#define ptsioctl ptyioctl
+cdev_decl(pts);
+
+#define ptctty ptytty
+#define ptcioctl ptyioctl
+cdev_decl(ptc);
+
+cdev_decl(ptm);
+
+cdev_decl(ctty);
+
+cdev_decl(audio);
+cdev_decl(drm);
+cdev_decl(midi);
+cdev_decl(radio);
+cdev_decl(video);
+cdev_decl(cn);
+
+bdev_decl(sw);
+
+bdev_decl(vnd);
+cdev_decl(vnd);
+
+cdev_decl(ch);
+
+bdev_decl(sd);
+cdev_decl(sd);
+
+cdev_decl(ses);
+
+cdev_decl(st);
+
+bdev_decl(cd);
+cdev_decl(cd);
+
+bdev_decl(rd);
+cdev_decl(rd);
+
+bdev_decl(uk);
+cdev_decl(uk);
+
+cdev_decl(dt);
+
+cdev_decl(diskmap);
+
+cdev_decl(bpf);
+
+cdev_decl(pf);
+
+cdev_decl(tun);
+cdev_decl(tap);
+cdev_decl(switch);
+cdev_decl(pppx);
+cdev_decl(pppac);
+
+cdev_decl(random);
+
+cdev_decl(wsdisplay);
+cdev_decl(wskbd);
+cdev_decl(wsmouse);
+cdev_decl(wsmux);
+
+cdev_decl(ksyms);
+
+cdev_decl(bio);
+cdev_decl(vscsi);
+
+cdev_decl(gpr);
+cdev_decl(bktr);
+
+cdev_decl(usb);
+cdev_decl(ugen);
+cdev_decl(uhid);
+cdev_decl(fido);
+cdev_decl(ucom);
+cdev_decl(ulpt);
+cdev_decl(urio);
+
+cdev_decl(hotplug);
+cdev_decl(gpio);
+cdev_decl(amdmsr);
+cdev_decl(fuse);
+cdev_decl(pvbus);
+cdev_decl(ipmi);
+cdev_decl(kcov);
+
+#endif
+
+#endif /* _SYS_CONF_H_ */
diff --git a/sys/sys/core.h b/sys/sys/core.h
new file mode 100644
index 0000000..cd69b41
--- /dev/null
+++ b/sys/sys/core.h
@@ -0,0 +1,99 @@
+/* $OpenBSD: core.h,v 1.7 2016/09/17 06:09:08 guenther Exp $ */
+/* $NetBSD: core.h,v 1.4 1994/10/29 08:20:14 cgd Exp $ */
+
+/*
+ * Copyright (c) 1994 Paul Kranenburg
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Paul Kranenburg.
+ * 4. 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.
+ */
+
+#define COREMAGIC 0507
+#define CORESEGMAGIC 0510
+
+/*
+ * The core structure's c_midmag field (like exec's a_midmag) is a
+ * network-byteorder encoding of this int
+ * FFFFFFmmmmmmmmmmMMMMMMMMMMMMMMMM
+ * Where `F' is 6 bits of flag (currently unused),
+ * `m' is 10 bits of machine-id, and
+ * `M' is 16 bits worth of magic number, ie. COREMAGIC.
+ * The macros below will set/get the needed fields.
+ */
+#define CORE_GETMAGIC(c) ( ntohl(((c).c_midmag)) & 0xffff )
+#define CORE_GETMID(c) ( (ntohl(((c).c_midmag)) >> 16) & 0x03ff )
+#define CORE_GETFLAG(c) ( (ntohl(((c).c_midmag)) >> 26) & 0x03f )
+#define CORE_SETMAGIC(c,mag,mid,flag) ( (c).c_midmag = htonl ( \
+ ( ((flag) & 0x3f) << 26) | \
+ ( ((mid) & 0x03ff) << 16) | \
+ ( ((mag) & 0xffff) ) ) )
+
+/* Flag definitions */
+#define CORE_CPU 1
+#define CORE_DATA 2
+#define CORE_STACK 4
+
+#ifndef _KERNEL
+/*
+ * XXX OBSOLETE, NO LONGER USED
+ * XXX This header file exists to support binutils' netbsd-core format
+ * XXX which is still needed for the a.out-m88k-openbsd use in luna88k
+ * XXX boot block creation.
+ *
+ * A core file consists of a header followed by a number of segments.
+ * Each segment is preceded by a `coreseg' structure giving the
+ * segment's type, the virtual address where the bits resided in
+ * process address space and the size of the segment.
+ *
+ * The core header specifies the lengths of the core header itself and
+ * each of the following core segment headers to allow for any machine
+ * dependent alignment requirements.
+ */
+
+struct core {
+ u_int32_t c_midmag; /* magic, id, flags */
+ u_int16_t c_hdrsize; /* Size of this header (machdep algn) */
+ u_int16_t c_seghdrsize; /* Size of a segment header */
+ u_int32_t c_nseg; /* # of core segments */
+ char c_name[MAXCOMLEN+1]; /* Copy of p->p_comm */
+ u_int32_t c_signo; /* Killing signal */
+ u_long c_ucode; /* Hmm ? */
+ u_long c_cpusize; /* Size of machine dependent segment */
+ u_long c_tsize; /* Size of traditional text segment */
+ u_long c_dsize; /* Size of traditional data segment */
+ u_long c_ssize; /* Size of traditional stack segment */
+};
+
+struct coreseg {
+ u_int32_t c_midmag; /* magic, id, flags */
+ u_long c_addr; /* Virtual address of segment */
+ u_long c_size; /* Size of this segment */
+};
+
+#else
+int coredump_write(void *, enum uio_seg, const void *, size_t);
+void coredump_unmap(void *, vaddr_t, vaddr_t);
+#endif
diff --git a/sys/sys/ctf.h b/sys/sys/ctf.h
new file mode 100644
index 0000000..ece42df
--- /dev/null
+++ b/sys/sys/ctf.h
@@ -0,0 +1,186 @@
+/* $OpenBSD: ctf.h,v 1.5 2017/08/13 14:56:05 nayden Exp $ */
+
+/*
+ * Copyright (c) 2016 Martin Pieuchot <mpi@openbsd.org>
+ *
+ * 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.
+ */
+
+#ifndef _SYS_CTF_H_
+#define _SYS_CTF_H_
+
+/*
+ * CTF ``Compact ANSI-C Type Format'' ABI header file.
+ */
+
+struct ctf_header {
+ uint16_t cth_magic;
+ uint8_t cth_version;
+ uint8_t cth_flags;
+ uint32_t cth_parlabel;
+ uint32_t cth_parname;
+ uint32_t cth_lbloff;
+ uint32_t cth_objtoff;
+ uint32_t cth_funcoff;
+ uint32_t cth_typeoff;
+ uint32_t cth_stroff;
+ uint32_t cth_strlen;
+};
+
+#define CTF_F_COMPRESS (1 << 0) /* zlib compression */
+
+struct ctf_lblent {
+ uint32_t ctl_label;
+ uint32_t ctl_typeidx;
+};
+
+struct ctf_stype {
+ uint32_t cts_name;
+ uint16_t cts_info;
+ union {
+ uint16_t _size;
+ uint16_t _type;
+ } _ST;
+#define cts_size _ST._size
+#define cts_type _ST._type
+};
+
+struct ctf_type {
+ struct ctf_stype _ctt_stype;
+#define ctt_name _ctt_stype.cts_name
+#define ctt_info _ctt_stype.cts_info
+#define ctt_size _ctt_stype.cts_size
+#define ctt_type _ctt_stype.cts_type
+ uint32_t ctt_lsizehi;
+ uint32_t ctt_lsizelo;
+};
+
+struct ctf_array {
+ uint16_t cta_contents;
+ uint16_t cta_index;
+ uint32_t cta_nelems;
+};
+
+struct ctf_member {
+ uint32_t ctm_name;
+ uint16_t ctm_type;
+ uint16_t ctm_offset;
+};
+
+struct ctf_lmember {
+ struct ctf_member _ctlm_member;
+#define ctlm_name _ctlm_member.ctm_name
+#define ctlm_type _ctlm_member.ctm_type
+#define ctlm_pad0 _ctlm_member.ctm_offset
+ uint32_t ctlm_offsethi;
+ uint32_t ctlm_offsetlo;
+};
+
+#define CTF_LSTRUCT_THRESH 8192
+
+struct ctf_enum {
+ uint32_t cte_name;
+ int32_t cte_value;
+};
+
+#define CTF_MAGIC 0xcff1
+#define CTF_VERSION 2
+
+#define CTF_MAX_NAME 0x7fffffff
+#define CTF_MAX_VLEN 0x03ff
+#define CTF_MAX_SIZE 0xfffe
+#define CTF_LSIZE_SENT CTF_MAX_SIZE+1 /* sentinel for cts vs ctt */
+
+#define CTF_STRTAB_0 0
+#define CTF_STRTAB_1 1
+
+/*
+ * Info macro.
+ */
+#define CTF_INFO_VLEN(i) (((i) & CTF_MAX_VLEN))
+#define CTF_INFO_ISROOT(i) (((i) & 0x0400) >> 10)
+#define CTF_INFO_KIND(i) (((i) & 0xf800) >> 11)
+#define CTF_K_UNKNOWN 0
+#define CTF_K_INTEGER 1
+#define CTF_K_FLOAT 2
+#define CTF_K_POINTER 3
+#define CTF_K_ARRAY 4
+#define CTF_K_FUNCTION 5
+#define CTF_K_STRUCT 6
+#define CTF_K_UNION 7
+#define CTF_K_ENUM 8
+#define CTF_K_FORWARD 9
+#define CTF_K_TYPEDEF 10
+#define CTF_K_VOLATILE 11
+#define CTF_K_CONST 12
+#define CTF_K_RESTRICT 13
+#define CTF_K_MAX 31
+
+/*
+ * Integer/Float Encoding macro.
+ */
+#define _CTF_ENCODING(e) (((e) & 0xff000000) >> 24)
+#define _CTF_OFFSET(e) (((e) & 0x00ff0000) >> 16)
+#define _CTF_BITS(e) (((e) & 0x0000ffff))
+#define _CTF_DATA(encoding, offset, bits) \
+ (((encoding) << 24) | ((offset) << 16) | (bits))
+
+#define CTF_INT_ENCODING(e) _CTF_ENCODING(e)
+#define CTF_INT_SIGNED (1 << 0)
+#define CTF_INT_CHAR (1 << 1)
+#define CTF_INT_BOOL (1 << 2)
+#define CTF_INT_VARARGS (1 << 3)
+#define CTF_INT_OFFSET(e) _CTF_OFFSET(e)
+#define CTF_INT_BITS(e) _CTF_BITS(e)
+#define CTF_INT_DATA(e, o, b) _CTF_DATA(e, o, b)
+
+#define CTF_FP_ENCODING(e) _CTF_ENCODING(e)
+#define CTF_FP_SINGLE 1
+#define CTF_FP_DOUBLE 2
+#define CTF_FP_CPLX 3
+#define CTF_FP_DCPLX 4
+#define CTF_FP_LDCPLX 5
+#define CTF_FP_LDOUBLE 6
+#define CTF_FP_INTRVL 7
+#define CTF_FP_DINTRVL 8
+#define CTF_FP_LDINTRVL 9
+#define CTF_FP_IMAGRY 10
+#define CTF_FP_DIMAGRY 11
+#define CTF_FP_LDIMAGRY 12
+#define CTF_FP_OFFSET(e) _CTF_OFFSET(e)
+#define CTF_FP_BITS(e) _CTF_BITS(e)
+#define CTF_FP_DATA(e, o, b) _CTF_DATA(e, o, b)
+
+/*
+ * Name reference macro.
+ */
+#define CTF_NAME_STID(n) ((n) >> 31)
+#define CTF_NAME_OFFSET(n) ((n) & CTF_MAX_NAME)
+
+/*
+ * Type macro.
+ */
+#define CTF_SIZE_TO_LSIZE_HI(s) ((uint32_t)((uint64_t)(s) >> 32))
+#define CTF_SIZE_TO_LSIZE_LO(s) ((uint32_t)(s))
+#define CTF_TYPE_LSIZE(t) \
+ (((uint64_t)(t)->ctt_lsizehi) << 32 | (t)->ctt_lsizelo)
+
+/*
+ * Member macro.
+ */
+#define CTF_LMEM_OFFSET(m) \
+ (((uint64_t)(m)->ctlm_offsethi) << 32 | (m)->ctlm_offsetlo)
+#define CTF_OFFSET_TO_LMEMHI(off) ((uint32_t)((uint64_t)(off) >> 32))
+#define CTF_OFFSET_TO_LMEMLO(off) ((uint32_t)(off))
+
+#endif /* _SYS_CTF_H_ */
diff --git a/sys/sys/device.h b/sys/sys/device.h
new file mode 100644
index 0000000..1faa019
--- /dev/null
+++ b/sys/sys/device.h
@@ -0,0 +1,224 @@
+/* $OpenBSD: device.h,v 1.55 2018/09/10 16:18:34 sashan Exp $ */
+/* $NetBSD: device.h,v 1.15 1996/04/09 20:55:24 cgd Exp $ */
+
+/*
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Lawrence Berkeley Laboratory.
+ *
+ * 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.
+ *
+ * @(#)device.h 8.2 (Berkeley) 2/17/94
+ */
+
+#ifndef _SYS_DEVICE_H_
+#define _SYS_DEVICE_H_
+
+#include <sys/queue.h>
+
+/*
+ * Minimal device structures.
+ * Note that all ``system'' device types are listed here.
+ */
+enum devclass {
+ DV_DULL, /* generic, no special info */
+ DV_CPU, /* CPU (carries resource utilization) */
+ DV_DISK, /* disk drive (label, etc) */
+ DV_IFNET, /* network interface */
+ DV_TAPE, /* tape device */
+ DV_TTY /* serial line interface (???) */
+};
+
+/*
+ * Actions for ca_activate.
+ */
+#define DVACT_DEACTIVATE 1 /* deactivate the device */
+#define DVACT_QUIESCE 2 /* warn the device about suspend */
+#define DVACT_SUSPEND 3 /* suspend the device */
+#define DVACT_RESUME 4 /* resume the device */
+#define DVACT_WAKEUP 5 /* tell device to recover after resume */
+#define DVACT_POWERDOWN 6 /* power device down */
+
+struct device {
+ enum devclass dv_class; /* this device's classification */
+ TAILQ_ENTRY(device) dv_list; /* entry on list of all devices */
+ struct cfdata *dv_cfdata; /* config data that found us */
+ int dv_unit; /* device unit number */
+ char dv_xname[16]; /* external name (name + unit) */
+ struct device *dv_parent; /* pointer to parent device */
+ int dv_flags; /* misc. flags; see below */
+ int dv_ref; /* ref count */
+};
+
+/* dv_flags */
+#define DVF_ACTIVE 0x0001 /* device is activated */
+
+TAILQ_HEAD(devicelist, device);
+
+/*
+ * Configuration data (i.e., data placed in ioconf.c).
+ */
+struct cfdata {
+ struct cfattach *cf_attach; /* config attachment */
+ struct cfdriver *cf_driver; /* config driver */
+ short cf_unit; /* unit number */
+ short cf_fstate; /* finding state (below) */
+ long *cf_loc; /* locators (machine dependent) */
+ int cf_flags; /* flags from config */
+ short *cf_parents; /* potential parents */
+ int cf_locnames; /* start of names */
+ short cf_starunit1; /* 1st usable unit number by STAR */
+};
+extern struct cfdata cfdata[];
+#define FSTATE_NOTFOUND 0 /* has not been found */
+#define FSTATE_FOUND 1 /* has been found */
+#define FSTATE_STAR 2 /* duplicable */
+#define FSTATE_DNOTFOUND 3 /* has not been found, and is disabled */
+#define FSTATE_DSTAR 4 /* duplicable, and is disabled */
+
+typedef int (*cfmatch_t)(struct device *, void *, void *);
+typedef void (*cfscan_t)(struct device *, void *);
+
+/*
+ * `configuration' attachment and driver (what the machine-independent
+ * autoconf uses). As devices are found, they are applied against all
+ * the potential matches. The one with the best match is taken, and a
+ * device structure (plus any other data desired) is allocated. Pointers
+ * to these are placed into an array of pointers. The array itself must
+ * be dynamic since devices can be found long after the machine is up
+ * and running.
+ *
+ * Devices can have multiple configuration attachments if they attach
+ * to different attributes (busses, or whatever), to allow specification
+ * of multiple match and attach functions. There is only one configuration
+ * driver per driver, so that things like unit numbers and the device
+ * structure array will be shared.
+ */
+struct cfattach {
+ size_t ca_devsize; /* size of dev data (for malloc) */
+ cfmatch_t ca_match; /* returns a match level */
+ void (*ca_attach)(struct device *, struct device *, void *);
+ int (*ca_detach)(struct device *, int);
+ int (*ca_activate)(struct device *, int);
+};
+
+/* Flags given to config_detach(), and the ca_detach function. */
+#define DETACH_FORCE 0x01 /* force detachment; hardware gone */
+#define DETACH_QUIET 0x02 /* don't print a notice */
+
+struct cfdriver {
+ void **cd_devs; /* devices found */
+ char *cd_name; /* device name */
+ enum devclass cd_class; /* device classification */
+ int cd_indirect; /* indirectly configure subdevices */
+ int cd_ndevs; /* size of cd_devs array */
+};
+
+/*
+ * Configuration printing functions, and their return codes. The second
+ * argument is NULL if the device was configured; otherwise it is the name
+ * of the parent device. The return value is ignored if the device was
+ * configured, so most functions can return UNCONF unconditionally.
+ */
+typedef int (*cfprint_t)(void *, const char *);
+#define QUIET 0 /* print nothing */
+#define UNCONF 1 /* print " not configured\n" */
+#define UNSUPP 2 /* print " not supported\n" */
+
+/*
+ * Pseudo-device attach information (function + number of pseudo-devs).
+ */
+struct pdevinit {
+ void (*pdev_attach)(int);
+ int pdev_count;
+};
+
+#ifdef _KERNEL
+
+#ifdef DIAGNOSTIC
+extern int pdevinit_done;
+#endif
+
+extern struct devicelist alldevs; /* list of all devices */
+
+extern int autoconf_verbose;
+extern volatile int config_pending; /* semaphore for mountroot */
+
+void config_init(void);
+void *config_search(cfmatch_t, struct device *, void *);
+struct device *config_found_sm(struct device *, void *, cfprint_t,
+ cfmatch_t);
+struct device *config_rootfound(char *, void *);
+void config_scan(cfscan_t, struct device *);
+struct device *config_attach(struct device *, void *, void *, cfprint_t);
+int config_detach(struct device *, int);
+int config_detach_children(struct device *, int);
+int config_deactivate(struct device *);
+int config_suspend(struct device *, int);
+int config_suspend_all(int);
+int config_activate_children(struct device *, int);
+struct device *config_make_softc(struct device *parent,
+ struct cfdata *cf);
+void config_defer(struct device *, void (*)(struct device *));
+void config_pending_incr(void);
+void config_pending_decr(void);
+void config_mountroot(struct device *, void (*)(struct device *));
+void config_process_deferred_mountroot(void);
+
+struct device *device_mainbus(void);
+struct device *device_mpath(void);
+struct device *device_lookup(struct cfdriver *, int unit);
+void device_ref(struct device *);
+void device_unref(struct device *);
+
+struct nam2blk {
+ char *name;
+ int maj;
+};
+
+int findblkmajor(struct device *dv);
+char *findblkname(int);
+void setroot(struct device *, int, int);
+struct device *getdisk(char *str, int len, int defpart, dev_t *devp);
+struct device *parsedisk(char *str, int len, int defpart, dev_t *devp);
+void device_register(struct device *, void *);
+
+int loadfirmware(const char *name, u_char **bufp, size_t *buflen);
+#define FIRMWARE_MAX 5*1024*1024
+
+/* compatibility definitions */
+#define config_found(d, a, p) config_found_sm((d), (a), (p), NULL)
+
+#endif /* _KERNEL */
+
+#endif /* !_SYS_DEVICE_H_ */
diff --git a/sys/sys/dir.h b/sys/sys/dir.h
new file mode 100644
index 0000000..60587f0
--- /dev/null
+++ b/sys/sys/dir.h
@@ -0,0 +1,65 @@
+/* $OpenBSD: dir.h,v 1.5 2003/06/02 23:28:21 millert Exp $ */
+/* $NetBSD: dir.h,v 1.9 1996/10/27 19:27:54 gwr Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 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.
+ * 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.
+ *
+ * @(#)dir.h 8.2 (Berkeley) 1/4/94
+ */
+
+/*
+ * The information in this file should be obtained from <dirent.h>
+ * and is provided solely (and temporarily) for backward compatibility.
+ */
+
+#ifndef _SYS_DIR_H_
+#define _SYS_DIR_H_
+
+#ifdef _KERNEL
+/* This file should only be used by old user-level code. */
+#error "Please use <sys/dirent.h> instead"
+#endif
+
+#include <dirent.h>
+
+/*
+ * Backwards compatibility.
+ */
+#define direct dirent
+
+/*
+ * The DIRSIZ macro gives the minimum record length which will hold
+ * the directory entry. This requires the amount of space in struct direct
+ * without the d_name field, plus enough space for the name with a terminating
+ * null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
+ */
+#undef DIRSIZ
+#define DIRSIZ(dp) \
+ ((sizeof (struct direct) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
+
+#endif /* !_SYS_DIR_H_ */
diff --git a/sys/sys/dirent.h b/sys/sys/dirent.h
new file mode 100644
index 0000000..09ad39c
--- /dev/null
+++ b/sys/sys/dirent.h
@@ -0,0 +1,100 @@
+/* $OpenBSD: dirent.h,v 1.11 2013/12/13 18:09:27 zhuk Exp $ */
+/* $NetBSD: dirent.h,v 1.12 1996/04/09 20:55:25 cgd Exp $ */
+
+/*-
+ * 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.
+ * 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.
+ *
+ * @(#)dirent.h 8.3 (Berkeley) 8/10/94
+ */
+
+#ifndef _SYS_DIRENT_H_
+#define _SYS_DIRENT_H_
+
+#include <sys/cdefs.h>
+
+/*
+ * The dirent structure defines the format of directory entries returned by
+ * the getdents(2) system call.
+ *
+ * A directory entry has a struct dirent at the front of it, containing its
+ * inode number, the length of the entry, and the length of the name
+ * contained in the entry. These are followed by the name padded to a 4
+ * byte boundary with null bytes. All names are guaranteed null terminated.
+ * The maximum length of a name in a directory is MAXNAMLEN.
+ */
+
+struct dirent {
+ __ino_t d_fileno; /* file number of entry */
+ __off_t d_off; /* offset after this entry */
+ __uint16_t d_reclen; /* length of this record */
+ __uint8_t d_type; /* file type, see below */
+ __uint8_t d_namlen; /* length of string in d_name */
+ __uint8_t __d_padding[4]; /* suppress padding after d_name */
+#if __BSD_VISIBLE
+#define MAXNAMLEN 255
+ char d_name[MAXNAMLEN + 1]; /* name must be no longer than this */
+#else
+ char d_name[255 + 1]; /* name must be no longer than this */
+#endif
+};
+
+#if __BSD_VISIBLE
+/*
+ * File types
+ */
+#define DT_UNKNOWN 0
+#define DT_FIFO 1
+#define DT_CHR 2
+#define DT_DIR 4
+#define DT_BLK 6
+#define DT_REG 8
+#define DT_LNK 10
+#define DT_SOCK 12
+
+/*
+ * Convert between stat structure types and directory types.
+ */
+#define IFTODT(mode) (((mode) & 0170000) >> 12)
+#define DTTOIF(dirtype) ((dirtype) << 12)
+
+#ifdef _KERNEL
+/*
+ * The DIRENT_RECSIZE macro gives the minimum record length which will hold
+ * a directory entry with a name of the given length, including the terminating
+ * nul byte, rounded up to proper alignment.
+ * The DIRENT_SIZE macro does the same when given a pointer to a struct dirent
+ */
+#define DIRENT_RECSIZE(namelen) \
+ ((offsetof(struct dirent, d_name) + (namelen) + 1 + 7) &~ 7)
+#define DIRENT_SIZE(dp) \
+ DIRENT_RECSIZE((dp)->d_namlen)
+#endif
+
+#endif /* __BSD_VISIBLE */
+
+#endif /* _SYS_DIRENT_H_ */
diff --git a/sys/sys/disk.h b/sys/sys/disk.h
new file mode 100644
index 0000000..4dcd488
--- /dev/null
+++ b/sys/sys/disk.h
@@ -0,0 +1,160 @@
+/* $OpenBSD: disk.h,v 1.36 2017/05/04 22:47:27 deraadt Exp $ */
+/* $NetBSD: disk.h,v 1.11 1996/04/28 20:22:50 thorpej Exp $ */
+
+/*
+ * Copyright (c) 1995 Jason R. Thorpe. All rights reserved.
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This software was developed by the Computer Systems Engineering group
+ * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
+ * contributed to Berkeley.
+ *
+ * All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Lawrence Berkeley Laboratory.
+ *
+ * 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.
+ *
+ * from: Header: disk.h,v 1.5 92/11/19 04:33:03 torek Exp (LBL)
+ *
+ * @(#)disk.h 8.1 (Berkeley) 6/2/93
+ */
+
+/*
+ * Disk device structures.
+ */
+
+#include <sys/device.h>
+#include <sys/time.h>
+#include <sys/queue.h>
+#include <sys/rwlock.h>
+#include <sys/mutex.h>
+
+struct buf;
+struct disklabel;
+
+#define DS_DISKNAMELEN 16
+
+struct diskstats {
+ char ds_name[DS_DISKNAMELEN];
+ int ds_busy; /* busy counter */
+ u_int64_t ds_rxfer; /* total number of read transfers */
+ u_int64_t ds_wxfer; /* total number of write transfers */
+ u_int64_t ds_seek; /* total independent seek operations */
+ u_int64_t ds_rbytes; /* total bytes read */
+ u_int64_t ds_wbytes; /* total bytes written */
+ struct timeval ds_attachtime; /* time disk was attached */
+ struct timeval ds_timestamp; /* time of first busy or any unbusy */
+ struct timeval ds_time; /* total time spent busy */
+};
+
+struct disk {
+ TAILQ_ENTRY(disk) dk_link; /* link in global disklist */
+ struct rwlock dk_lock; /* disk lock */
+ struct mutex dk_mtx; /* busy/unbusy mtx */
+ char *dk_name; /* disk name */
+ struct device *dk_device; /* disk device structure. */
+ dev_t dk_devno; /* disk device number. */
+ int dk_flags; /* disk flags */
+#define DKF_CONSTRUCTED 0x0001
+#define DKF_OPENED 0x0002
+#define DKF_NOLABELREAD 0x0004
+#define DKF_LABELVALID 0x0008
+
+ /*
+ * Metrics data; note that some metrics may have no meaning
+ * on certain types of disks.
+ */
+ int dk_busy; /* busy counter */
+ u_int64_t dk_rxfer; /* total number of read transfers */
+ u_int64_t dk_wxfer; /* total number of write transfers */
+ u_int64_t dk_seek; /* total independent seek operations */
+ u_int64_t dk_rbytes; /* total bytes read */
+ u_int64_t dk_wbytes; /* total bytes written */
+ struct timeval dk_attachtime; /* time disk was attached */
+ struct timeval dk_timestamp; /* time of first busy or any unbusy */
+ struct timeval dk_time; /* total time spent busy */
+
+ int dk_bopenmask; /* block devices open */
+ int dk_copenmask; /* character devices open */
+ int dk_openmask; /* composite (bopen|copen) */
+ int dk_state; /* label state ### */
+ int dk_blkshift; /* shift to convert DEV_BSIZE to blks*/
+ int dk_byteshift; /* shift to convert bytes to blks */
+
+ /*
+ * Disk label information. Storage for the in-core disk label
+ * must be dynamically allocated, otherwise the size of this
+ * structure becomes machine-dependent.
+ */
+ struct disklabel *dk_label;
+};
+
+/* states */
+#define DK_CLOSED 0 /* drive is closed */
+#define DK_WANTOPEN 1 /* drive being opened */
+#define DK_WANTOPENRAW 2 /* drive being opened */
+#define DK_RDLABEL 3 /* label being read */
+#define DK_OPEN 4 /* label read, drive open */
+#define DK_OPENRAW 5 /* open without label */
+
+/* Disk map flags. */
+#define DM_OPENPART 0x1 /* Open raw partition. */
+#define DM_OPENBLCK 0x2 /* Open block device. */
+
+/*
+ * disklist_head is defined here so that user-land has access to it.
+ */
+TAILQ_HEAD(disklist_head, disk); /* the disklist is a TAILQ */
+
+#ifdef _KERNEL
+extern struct disklist_head disklist; /* list of disks attached to system */
+extern int disk_count; /* number of disks in global disklist */
+extern int disk_change; /* disk attached/detached */
+
+void disk_init(void);
+int disk_construct(struct disk *);
+void disk_attach(struct device *, struct disk *);
+void disk_detach(struct disk *);
+int disk_openpart(struct disk *, int, int, int);
+void disk_closepart(struct disk *, int, int);
+void disk_gone(int (*)(dev_t, int, int, struct proc *), int);
+void disk_busy(struct disk *);
+void disk_unbusy(struct disk *, long, daddr_t, int);
+
+int disk_lock(struct disk *);
+void disk_lock_nointr(struct disk *);
+void disk_unlock(struct disk *);
+struct device *disk_lookup(struct cfdriver *, int);
+
+char *disk_readlabel(struct disklabel *, dev_t, char *, size_t);
+
+int disk_map(char *, char *, int, int);
+
+int duid_iszero(u_char *);
+const char *duid_format(u_char *);
+#endif
diff --git a/sys/sys/disklabel.h b/sys/sys/disklabel.h
new file mode 100644
index 0000000..70c6cfe
--- /dev/null
+++ b/sys/sys/disklabel.h
@@ -0,0 +1,533 @@
+/* $OpenBSD: disklabel.h,v 1.75 2017/10/24 09:36:13 jsg Exp $ */
+/* $NetBSD: disklabel.h,v 1.41 1996/05/10 23:07:37 mark Exp $ */
+
+/*
+ * Copyright (c) 1987, 1988, 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.
+ *
+ * @(#)disklabel.h 8.2 (Berkeley) 7/10/94
+ */
+
+/*
+ * Disk description table, see disktab(5)
+ */
+#define _PATH_DISKTAB "/etc/disktab"
+#define DISKTAB "/etc/disktab" /* deprecated */
+
+/*
+ * Each disk has a label which includes information about the hardware
+ * disk geometry, filesystem partitions, and drive specific information.
+ * The location of the label, as well as the number of partitions the
+ * label can describe and the number of the "whole disk" (raw)
+ * partition are machine dependent.
+ */
+#include <machine/disklabel.h>
+
+#include <sys/uuid.h>
+
+/*
+ * The absolute maximum number of disk partitions allowed.
+ * This is the maximum value of MAXPARTITIONS for which 'struct disklabel'
+ * is <= DEV_BSIZE bytes long. If MAXPARTITIONS is greater than this, beware.
+ */
+#define MAXMAXPARTITIONS 22
+#if MAXPARTITIONS > MAXMAXPARTITIONS
+#warn beware: MAXPARTITIONS bigger than MAXMAXPARTITIONS
+#endif
+
+/*
+ * Translate between device numbers and major/disk unit/disk partition.
+ */
+#define DISKUNIT(dev) (minor(dev) / MAXPARTITIONS)
+#define DISKPART(dev) (minor(dev) % MAXPARTITIONS)
+#define RAW_PART 2 /* 'c' partition */
+#define DISKMINOR(unit, part) \
+ (((unit) * MAXPARTITIONS) + (part))
+#define MAKEDISKDEV(maj, unit, part) \
+ (makedev((maj), DISKMINOR((unit), (part))))
+#define DISKLABELDEV(dev) \
+ (MAKEDISKDEV(major(dev), DISKUNIT(dev), RAW_PART))
+
+#define DISKMAGIC ((u_int32_t)0x82564557) /* The disk magic number */
+
+#define MAXDISKSIZE 0x7fffffffffffLL /* 47 bits of reach */
+
+#ifndef _LOCORE
+struct disklabel {
+ u_int32_t d_magic; /* the magic number */
+ u_int16_t d_type; /* drive type */
+ u_int16_t d_subtype; /* controller/d_type specific */
+ char d_typename[16]; /* type name, e.g. "eagle" */
+ char d_packname[16]; /* pack identifier */
+
+ /* disk geometry: */
+ u_int32_t d_secsize; /* # of bytes per sector */
+ u_int32_t d_nsectors; /* # of data sectors per track */
+ u_int32_t d_ntracks; /* # of tracks per cylinder */
+ u_int32_t d_ncylinders; /* # of data cylinders per unit */
+ u_int32_t d_secpercyl; /* # of data sectors per cylinder */
+ u_int32_t d_secperunit; /* # of data sectors (low part) */
+
+ u_char d_uid[8]; /* Unique label identifier. */
+
+ /*
+ * Alternate cylinders include maintenance, replacement, configuration
+ * description areas, etc.
+ */
+ u_int32_t d_acylinders; /* # of alt. cylinders per unit */
+
+ /* hardware characteristics: */
+ u_int16_t d_bstarth; /* start of useable region (high part) */
+ u_int16_t d_bendh; /* size of useable region (high part) */
+ u_int32_t d_bstart; /* start of useable region */
+ u_int32_t d_bend; /* end of useable region */
+ u_int32_t d_flags; /* generic flags */
+#define NDDATA 5
+ u_int32_t d_drivedata[NDDATA]; /* drive-type specific information */
+ u_int16_t d_secperunith; /* # of data sectors (high part) */
+ u_int16_t d_version; /* version # (1=48 bit addressing) */
+#define NSPARE 4
+ u_int32_t d_spare[NSPARE]; /* reserved for future use */
+ u_int32_t d_magic2; /* the magic number (again) */
+ u_int16_t d_checksum; /* xor of data incl. partitions */
+
+ /* filesystem and partition information: */
+ u_int16_t d_npartitions; /* number of partitions in following */
+ u_int32_t d_bbsize; /* size of boot area at sn0, bytes */
+ u_int32_t d_sbsize; /* max size of fs superblock, bytes */
+ struct partition { /* the partition table */
+ u_int32_t p_size; /* number of sectors (low part) */
+ u_int32_t p_offset; /* starting sector (low part) */
+ u_int16_t p_offseth; /* starting sector (high part) */
+ u_int16_t p_sizeh; /* number of sectors (high part) */
+ u_int8_t p_fstype; /* filesystem type, see below */
+ u_int8_t p_fragblock; /* encoded filesystem frag/block */
+ u_int16_t p_cpg; /* UFS: FS cylinders per group */
+ } d_partitions[MAXPARTITIONS]; /* actually may be more */
+};
+
+
+struct __partitionv0 { /* old (v0) partition table entry */
+ u_int32_t p_size; /* number of sectors in partition */
+ u_int32_t p_offset; /* starting sector */
+ u_int32_t p_fsize; /* filesystem basic fragment size */
+ u_int8_t p_fstype; /* filesystem type, see below */
+ u_int8_t p_frag; /* filesystem fragments per block */
+ union {
+ u_int16_t cpg; /* UFS: FS cylinders per group */
+ u_int16_t sgs; /* LFS: FS segment shift */
+ } __partitionv0_u1;
+};
+#endif /* _LOCORE */
+
+
+#define DISKLABELV1_FFS_FRAGBLOCK(fsize, frag) \
+ ((fsize) * (frag) == 0 ? 0 : \
+ (((ffs((fsize) * (frag)) - 13) << 3) | (ffs(frag))))
+
+#define DISKLABELV1_FFS_BSIZE(i) ((i) == 0 ? 0 : (1 << (((i) >> 3) + 12)))
+#define DISKLABELV1_FFS_FRAG(i) ((i) == 0 ? 0 : (1 << (((i) & 0x07) - 1)))
+#define DISKLABELV1_FFS_FSIZE(i) (DISKLABELV1_FFS_FRAG(i) == 0 ? 0 : \
+ (DISKLABELV1_FFS_BSIZE(i) / DISKLABELV1_FFS_FRAG(i)))
+
+#define DL_GETPSIZE(p) (((u_int64_t)(p)->p_sizeh << 32) + (p)->p_size)
+#define DL_SETPSIZE(p, n) do { \
+ u_int64_t x = (n); \
+ (p)->p_sizeh = x >> 32; \
+ (p)->p_size = x; \
+ } while (0)
+#define DL_GETPOFFSET(p) (((u_int64_t)(p)->p_offseth << 32) + (p)->p_offset)
+#define DL_SETPOFFSET(p, n) do { \
+ u_int64_t x = (n); \
+ (p)->p_offseth = x >> 32; \
+ (p)->p_offset = x; \
+ } while (0)
+
+#define DL_GETDSIZE(d) (((u_int64_t)(d)->d_secperunith << 32) + \
+ (d)->d_secperunit)
+#define DL_SETDSIZE(d, n) do { \
+ u_int64_t x = (n); \
+ (d)->d_secperunith = x >> 32; \
+ (d)->d_secperunit = x; \
+ } while (0)
+#define DL_GETBSTART(d) (((u_int64_t)(d)->d_bstarth << 32) + \
+ (d)->d_bstart)
+#define DL_SETBSTART(d, n) do { \
+ u_int64_t x = (n); \
+ (d)->d_bstarth = x >> 32; \
+ (d)->d_bstart = x; \
+ } while (0)
+#define DL_GETBEND(d) (((u_int64_t)(d)->d_bendh << 32) + \
+ (d)->d_bend)
+#define DL_SETBEND(d, n) do { \
+ u_int64_t x = (n); \
+ (d)->d_bendh = x >> 32; \
+ (d)->d_bend = x; \
+ } while (0)
+
+#define DL_BLKSPERSEC(d) ((d)->d_secsize / DEV_BSIZE)
+#define DL_SECTOBLK(d, n) ((n) * DL_BLKSPERSEC(d))
+#define DL_BLKTOSEC(d, n) ((n) / DL_BLKSPERSEC(d))
+#define DL_BLKOFFSET(d, n) (((n) % DL_BLKSPERSEC(d)) * DEV_BSIZE)
+
+/* d_type values: */
+#define DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */
+#define DTYPE_MSCP 2 /* MSCP */
+#define DTYPE_DEC 3 /* other DEC (rk, rl) */
+#define DTYPE_SCSI 4 /* SCSI */
+#define DTYPE_ESDI 5 /* ESDI interface */
+#define DTYPE_ST506 6 /* ST506 etc. */
+#define DTYPE_HPIB 7 /* CS/80 on HP-IB */
+#define DTYPE_HPFL 8 /* HP Fiber-link */
+#define DTYPE_FLOPPY 10 /* floppy */
+#define DTYPE_CCD 11 /* was: concatenated disk device */
+#define DTYPE_VND 12 /* vnode pseudo-disk */
+#define DTYPE_ATAPI 13 /* ATAPI */
+#define DTYPE_RAID 14 /* was: RAIDframe */
+#define DTYPE_RDROOT 15 /* ram disk root */
+
+#ifdef DKTYPENAMES
+static char *dktypenames[] = {
+ "unknown",
+ "SMD",
+ "MSCP",
+ "old DEC",
+ "SCSI",
+ "ESDI",
+ "ST506",
+ "HP-IB",
+ "HP-FL",
+ "type 9",
+ "floppy",
+ "ccd", /* deprecated */
+ "vnd",
+ "ATAPI",
+ "RAID",
+ "rdroot",
+ NULL
+};
+#define DKMAXTYPES (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1)
+#endif
+
+/*
+ * Filesystem type and version.
+ * Used to interpret other filesystem-specific
+ * per-partition information.
+ */
+#define FS_UNUSED 0 /* unused */
+#define FS_SWAP 1 /* swap */
+#define FS_V6 2 /* Sixth Edition */
+#define FS_V7 3 /* Seventh Edition */
+#define FS_SYSV 4 /* System V */
+#define FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */
+#define FS_V8 6 /* Eighth Edition, 4K blocks */
+#define FS_BSDFFS 7 /* 4.2BSD fast file system */
+#define FS_MSDOS 8 /* MSDOS file system */
+#define FS_BSDLFS 9 /* 4.4BSD log-structured file system */
+#define FS_OTHER 10 /* in use, but unknown/unsupported */
+#define FS_HPFS 11 /* OS/2 high-performance file system */
+#define FS_ISO9660 12 /* ISO 9660, normally CD-ROM */
+#define FS_BOOT 13 /* partition contains bootstrap */
+#define FS_ADOS 14 /* AmigaDOS fast file system */
+#define FS_HFS 15 /* Macintosh HFS */
+#define FS_ADFS 16 /* Acorn Disk Filing System */
+#define FS_EXT2FS 17 /* ext2fs */
+#define FS_CCD 18 /* ccd component */
+#define FS_RAID 19 /* RAIDframe or softraid */
+#define FS_NTFS 20 /* Windows/NT file system */
+#define FS_UDF 21 /* UDF (DVD) filesystem */
+
+#ifdef DKTYPENAMES
+static char *fstypenames[] = {
+ "unused",
+ "swap",
+ "Version6",
+ "Version7",
+ "SystemV",
+ "4.1BSD",
+ "Eighth-Edition",
+ "4.2BSD",
+ "MSDOS",
+ "4.4LFS",
+ "unknown",
+ "HPFS",
+ "ISO9660",
+ "boot",
+ "ADOS",
+ "HFS",
+ "ADFS",
+ "ext2fs",
+ "ccd",
+ "RAID",
+ "NTFS",
+ "UDF",
+ NULL
+};
+
+/* Similar to the above, but used for things like the mount command. */
+static char *fstypesnames[] = {
+ "", /* 0 */
+ "", /* 1 */
+ "", /* 2 */
+ "", /* 3 */
+ "", /* 4 */
+ "", /* 5 */
+ "", /* 6 */
+ "ffs", /* 7 */
+ "msdos", /* 8 */
+ "lfs", /* 9 */
+ "", /* 10 */
+ "", /* 11 */
+ "cd9660", /* 12 */
+ "", /* 13 */
+ "ados", /* 14 */
+ "", /* 15 */
+ "", /* 16 */
+ "ext2fs", /* 17 */
+ "", /* 18 */
+ "", /* 19 */
+ "ntfs", /* 20 */
+ "udf", /* 21 */
+ NULL
+};
+
+#define FSMAXTYPES (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1)
+#endif
+
+/*
+ * flags shared by various drives:
+ */
+#define D_BADSECT 0x04 /* supports bad sector forw. */
+#define D_VENDOR 0x08 /* vendor disklabel */
+
+/*
+ * Drive data for SMD.
+ */
+#define d_smdflags d_drivedata[0]
+#define D_SSE 0x1 /* supports skip sectoring */
+#define d_mindist d_drivedata[1]
+#define d_maxdist d_drivedata[2]
+#define d_sdist d_drivedata[3]
+
+/*
+ * Drive data for ST506.
+ */
+#define d_precompcyl d_drivedata[0]
+#define d_gap3 d_drivedata[1] /* used only when formatting */
+
+/*
+ * Drive data for SCSI.
+ */
+#define d_blind d_drivedata[0]
+
+#ifndef _LOCORE
+/*
+ * Structure used internally to retrieve information about a partition
+ * on a disk.
+ */
+struct partinfo {
+ struct disklabel *disklab;
+ struct partition *part;
+};
+
+/* GUID partition table -- located at sector 1 of some disks. */
+#define GPTSECTOR 1 /* DOS boot block relative sector # */
+#define GPTSIGNATURE 0x5452415020494645LL
+ /* ASCII string "EFI PART" encoded as 64-bit */
+#define GPTREVISION 0x10000 /* GPT header version 1.0 */
+#define NGPTPARTITIONS 128
+#define GPTDOSACTIVE 0x2
+#define GPTMINHDRSIZE 92
+#define GPTMINPARTSIZE 128
+#define GPTPARTNAMESIZE 36
+
+/* all values in the GPT need to be little endian as per UEFI specification */
+struct gpt_header {
+ u_int64_t gh_sig; /* "EFI PART" */
+ u_int32_t gh_rev; /* GPT Version 1.0: 0x00000100 */
+ u_int32_t gh_size; /* Little-Endian */
+ u_int32_t gh_csum; /* CRC32: with this field as 0 */
+ u_int32_t gh_rsvd; /* always zero */
+ u_int64_t gh_lba_self; /* LBA of this header */
+ u_int64_t gh_lba_alt; /* LBA of alternate header */
+ u_int64_t gh_lba_start; /* first usable LBA */
+ u_int64_t gh_lba_end; /* last usable LBA */
+ struct uuid gh_guid; /* disk GUID used to identify the disk */
+ u_int64_t gh_part_lba; /* starting LBA of GPT partition entries */
+ u_int32_t gh_part_num; /* # of partition entries */
+ u_int32_t gh_part_size; /* size per entry, shall be 128*(2**n)
+ with n >= 0 */
+ u_int32_t gh_part_csum; /* CRC32 checksum of all partition entries:
+ * starts at gh_part_lba and is computed over
+ * a byte length of gh_part_num*gh_part_size */
+ /* the rest of the block is reserved by UEFI and must be zero */
+};
+
+struct gpt_partition {
+ struct uuid gp_type; /* partition type GUID */
+ struct uuid gp_guid; /* unique partition GUID */
+ u_int64_t gp_lba_start; /* starting LBA of this partition */
+ u_int64_t gp_lba_end; /* ending LBA of this partition, inclusive,
+ usually odd */
+ u_int64_t gp_attrs; /* attribute flags */
+ u_int16_t gp_name[GPTPARTNAMESIZE]; /* partition name, utf-16le */
+ /* the rest of the GPT partition entry, if any, is reserved by UEFI
+ and must be zero */
+};
+
+#define GPT_UUID_UNUSED \
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
+#define GPT_UUID_MSDOS \
+ { 0xeb, 0xd0, 0xa0, 0xa2, 0xb9, 0xe5, 0x44, 0x33, \
+ 0x87, 0xc0, 0x68, 0xb6, 0xb7, 0x26, 0x99, 0xc7 }
+#define GPT_UUID_EFI_SYSTEM \
+ { 0xc1, 0x2a, 0x73, 0x28, 0xf8, 0x1f, 0x11, 0xd2, \
+ 0xba, 0x4b, 0x00, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b }
+#define GPT_UUID_LEGACY_MBR \
+ { 0x02, 0x4d, 0xee, 0x41, 0x33, 0x37, 0x11, 0xd3, \
+ 0x9d, 0x69, 0x00, 0x08, 0xc7, 0x81, 0xf3, 0x9f }
+#define GPT_UUID_OPENBSD \
+ { 0x82, 0x4c, 0xc7, 0xa0, 0x36, 0xa8, 0x11, 0xe3, \
+ 0x89, 0x0a, 0x95, 0x25, 0x19, 0xad, 0x3f, 0x61 }
+#define GPT_UUID_CHROMEROOTFS \
+ { 0x3c, 0xb8, 0xe2, 0x02, 0x3b, 0x7e, 0x47, 0xdd, \
+ 0x8a, 0x3c, 0x7f, 0xf2, 0xa1, 0x3c, 0xfc, 0xec }
+#define GPT_UUID_LINUX \
+ { 0x0f, 0xc6, 0x3d, 0xaf, 0x84, 0x83, 0x47, 0x72, \
+ 0x8e, 0x79, 0x3d, 0x69, 0xd8, 0x47, 0x7d, 0xe4 }
+#define GPT_UUID_LINUX_HOME \
+ { 0x93, 0x3a, 0xc7, 0xe1, 0x2e, 0xb4, 0x4f, 0x13, \
+ 0xb8, 0x44, 0x0e, 0x14, 0xe2, 0xae, 0xf9, 0x15 }
+#define GPT_UUID_LINUX_SRV \
+ { 0x3b, 0x8f, 0x84, 0x25, 0x20, 0xe0, 0x4f, 0x3b, \
+ 0x90, 0x7f, 0x1a, 0x25, 0xa7, 0x6f, 0x98, 0xe8 }
+#define GPT_UUID_FBSD_DATA \
+ { 0x51, 0x6e, 0x7c, 0xb4, 0x6e, 0xcf, 0x11, 0xd6, \
+ 0x8f, 0xf8, 0x00, 0x02, 0x2d, 0x09, 0x71, 0x2b }
+#define GPT_UUID_FBSD_UFS \
+ { 0x51, 0x6e, 0x7c, 0xb6, 0x6e, 0xcf, 0x11, 0xd6, \
+ 0x8f, 0xf8, 0x00, 0x02, 0x2d, 0x09, 0x71, 0x2b }
+#define GPT_UUID_NBSD_UFS \
+ { 0x49, 0xf4, 0x8d, 0x5a, 0xb1, 0x0e, 0x11, 0xdc, \
+ 0xb9, 0x9b, 0x00, 0x19, 0xd1, 0x87, 0x96, 0x48 }
+#define GPT_UUID_APPLE_HFS \
+ { 0x48, 0x46, 0x53, 0x00, 0x00, 0x00, 0x11, 0xaa, \
+ 0xaa, 0x11, 0x00, 0x30, 0x65, 0x43, 0xec, 0xac }
+#define GPT_UUID_APPLE_UFS \
+ { 0x55, 0x46, 0x53, 0x00, 0x00, 0x00, 0x11, 0xaa, \
+ 0xaa, 0x11, 0x00, 0x30, 0x65, 0x43, 0xec, 0xac }
+
+/* DOS partition table -- located at start of some disks. */
+#define DOS_LABELSECTOR 1
+#define DOSBBSECTOR 0 /* DOS boot block relative sector # */
+#define DOSPARTOFF 446
+#define DOSDISKOFF 444
+#define NDOSPART 4
+#define DOSACTIVE 0x80 /* active partition */
+
+#define DOSMBR_SIGNATURE (0xaa55)
+#define DOSMBR_SIGNATURE_OFF (0x1fe)
+
+/* Maximum number of Extended Boot Records (EBRs) to traverse. */
+#define DOS_MAXEBR 256
+
+struct dos_partition {
+ u_int8_t dp_flag; /* bootstrap flags */
+ u_int8_t dp_shd; /* starting head */
+ u_int8_t dp_ssect; /* starting sector */
+ u_int8_t dp_scyl; /* starting cylinder */
+ u_int8_t dp_typ; /* partition type (see below) */
+ u_int8_t dp_ehd; /* end head */
+ u_int8_t dp_esect; /* end sector */
+ u_int8_t dp_ecyl; /* end cylinder */
+ u_int32_t dp_start; /* absolute starting sector number */
+ u_int32_t dp_size; /* partition size in sectors */
+};
+
+/* Isolate the relevant bits to get sector and cylinder. */
+#define DPSECT(s) ((s) & 0x3f)
+#define DPCYL(c, s) ((c) + (((s) & 0xc0) << 2))
+
+/* Known DOS partition types. */
+#define DOSPTYP_UNUSED 0x00 /* Unused partition */
+#define DOSPTYP_FAT12 0x01 /* 12-bit FAT */
+#define DOSPTYP_FAT16S 0x04 /* 16-bit FAT, less than 32M */
+#define DOSPTYP_EXTEND 0x05 /* Extended; contains sub-partitions */
+#define DOSPTYP_FAT16B 0x06 /* 16-bit FAT, more than 32M */
+#define DOSPTYP_NTFS 0x07 /* NTFS */
+#define DOSPTYP_FAT32 0x0b /* 32-bit FAT */
+#define DOSPTYP_FAT32L 0x0c /* 32-bit FAT, LBA-mapped */
+#define DOSPTYP_FAT16L 0x0e /* 16-bit FAT, LBA-mapped */
+#define DOSPTYP_EXTENDL 0x0f /* Extended, LBA-mapped; (sub-partitions) */
+#define DOSPTYP_ONTRACK 0x54
+#define DOSPTYP_LINUX 0x83 /* That other thing */
+#define DOSPTYP_FREEBSD 0xa5 /* FreeBSD partition type */
+#define DOSPTYP_OPENBSD 0xa6 /* OpenBSD partition type */
+#define DOSPTYP_NETBSD 0xa9 /* NetBSD partition type */
+#define DOSPTYP_EFI 0xee /* EFI Protective Partition */
+#define DOSPTYP_EFISYS 0xef /* EFI System Partition */
+
+struct dos_mbr {
+ u_int8_t dmbr_boot[DOSPARTOFF];
+ struct dos_partition dmbr_parts[NDOSPART];
+ u_int16_t dmbr_sign;
+} __packed;
+
+#ifdef _KERNEL
+void diskerr(struct buf *, char *, char *, int, int, struct disklabel *);
+u_int dkcksum(struct disklabel *);
+int initdisklabel(struct disklabel *);
+int checkdisklabel(void *, struct disklabel *, u_int64_t, u_int64_t);
+int setdisklabel(struct disklabel *, struct disklabel *, u_int);
+int readdisklabel(dev_t, void (*)(struct buf *), struct disklabel *, int);
+int writedisklabel(dev_t, void (*)(struct buf *), struct disklabel *);
+int bounds_check_with_label(struct buf *, struct disklabel *);
+int readdisksector(struct buf *, void (*)(struct buf *),
+ struct disklabel *, u_int64_t);
+int readdoslabel(struct buf *, void (*)(struct buf *),
+ struct disklabel *, daddr_t *, int);
+#ifdef CD9660
+int iso_disklabelspoof(dev_t dev, void (*strat)(struct buf *),
+ struct disklabel *lp);
+#endif
+#ifdef UDF
+int udf_disklabelspoof(dev_t dev, void (*strat)(struct buf *),
+ struct disklabel *lp);
+#endif
+#endif
+#endif /* _LOCORE */
+
+#if !defined(_KERNEL) && !defined(_LOCORE)
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+struct disklabel *getdiskbyname(const char *);
+__END_DECLS
+
+#endif
diff --git a/sys/sys/dkio.h b/sys/sys/dkio.h
new file mode 100644
index 0000000..94d56ec
--- /dev/null
+++ b/sys/sys/dkio.h
@@ -0,0 +1,80 @@
+/* $OpenBSD: dkio.h,v 1.12 2017/10/24 09:36:13 jsg Exp $ */
+/* $NetBSD: dkio.h,v 1.1 1996/01/30 18:21:48 thorpej Exp $ */
+
+/*
+ * Copyright (c) 1987, 1988, 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 _SYS_DKIO_H_
+#define _SYS_DKIO_H_
+
+#include <sys/ioccom.h>
+
+/*
+ * Disk-specific ioctls.
+ */
+ /* get and set disklabel; DIOCGPART used internally */
+#define DIOCGDINFO _IOR('d', 101, struct disklabel)/* get */
+#define DIOCSDINFO _IOW('d', 102, struct disklabel)/* set */
+#define DIOCWDINFO _IOW('d', 103, struct disklabel)/* set, update disk */
+#define DIOCGPART _IOW('d', 104, struct partinfo) /* get partition */
+
+#define DIOCEJECT _IO('d', 112) /* eject removable disk */
+#define DIOCLOCK _IOW('d', 113, int) /* lock/unlock pack */
+
+#define DIOCGPDINFO _IOR('d', 114, struct disklabel)/* get physical */
+#define DIOCRLDINFO _IO('d', 115) /* reload disklabel */
+
+struct dk_inquiry {
+ char vendor[64];
+ char product[128];
+ char revision[64];
+ char serial[64];
+};
+
+#define DIOCINQ _IOR('d', 116, struct dk_inquiry)
+
+struct dk_cache {
+ unsigned int wrcache;
+ unsigned int rdcache;
+};
+
+#define DIOCGCACHE _IOR('d', 117, struct dk_cache) /* get cache enabled */
+#define DIOCSCACHE _IOW('d', 118, struct dk_cache) /* set cache enabled */
+
+struct dk_diskmap {
+ char *device;
+ int fd;
+ int flags;
+};
+
+#define DIOCMAP _IOWR('d', 119, struct dk_diskmap)
+
+#define DIOCCACHESYNC _IOW('d', 120, int) /* sync cache (force?) */
+
+#endif /* _SYS_DKIO_H_ */
diff --git a/sys/sys/domain.h b/sys/sys/domain.h
new file mode 100644
index 0000000..7614cfa
--- /dev/null
+++ b/sys/sys/domain.h
@@ -0,0 +1,78 @@
+/* $OpenBSD: domain.h,v 1.20 2019/06/13 08:12:11 claudio Exp $ */
+/* $NetBSD: domain.h,v 1.10 1996/02/09 18:25:07 christos 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.
+ * 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.
+ *
+ * @(#)domain.h 8.1 (Berkeley) 6/2/93
+ */
+
+/*
+ * Structure per communications domain.
+ */
+
+#ifndef _SOCKLEN_T_DEFINED_
+#define _SOCKLEN_T_DEFINED_
+typedef __socklen_t socklen_t; /* length type for network syscalls */
+#endif
+
+/*
+ * Forward structure declarations for function prototypes [sic].
+ */
+struct mbuf;
+struct ifnet;
+
+struct domain {
+ int dom_family; /* AF_xxx */
+ char *dom_name;
+ void (*dom_init)(void); /* initialize domain data structures */
+ /* externalize access rights */
+ int (*dom_externalize)(struct mbuf *, socklen_t, int);
+ /* dispose of internalized rights */
+ void (*dom_dispose)(struct mbuf *);
+ const struct protosw *dom_protosw, *dom_protoswNPROTOSW;
+ /* initialize routing table */
+ unsigned int dom_sasize; /* size of sockaddr structure */
+ unsigned int dom_rtoffset; /* offset of the key, in bytes */
+ unsigned int dom_maxplen; /* maxium prefix length, in bits */
+ void *(*dom_ifattach)(struct ifnet *);
+ void (*dom_ifdetach)(struct ifnet *, void *);
+ /* af-dependent data on ifnet */
+};
+
+#ifdef _KERNEL
+extern struct domain *domains[];
+void domaininit(void);
+
+extern struct domain inetdomain;
+
+#ifdef INET6
+extern struct domain inet6domain;
+#endif
+
+#endif /* _KERNEL */
diff --git a/sys/sys/endian.h b/sys/sys/endian.h
new file mode 100644
index 0000000..29d5955
--- /dev/null
+++ b/sys/sys/endian.h
@@ -0,0 +1,124 @@
+/* $OpenBSD: endian.h,v 1.25 2014/12/21 04:49:00 guenther Exp $ */
+
+/*-
+ * Copyright (c) 1997 Niklas Hallqvist. 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.
+ */
+
+/*
+ * Public definitions for little- and big-endian systems.
+ * This file should be included as <endian.h> in userspace and as
+ * <sys/endian.h> in the kernel.
+ *
+ * System headers that need endian information but that can't or don't
+ * want to export the public names here should include <sys/_endian.h>
+ * and use the internal names: _BYTE_ORDER, _*_ENDIAN, etc.
+ */
+
+#ifndef _SYS_ENDIAN_H_
+#define _SYS_ENDIAN_H_
+
+#include <sys/cdefs.h>
+#include <sys/_endian.h>
+
+/* Public names */
+#define LITTLE_ENDIAN _LITTLE_ENDIAN
+#define BIG_ENDIAN _BIG_ENDIAN
+#define PDP_ENDIAN _PDP_ENDIAN
+#define BYTE_ORDER _BYTE_ORDER
+
+
+/*
+ * These are specified to be function-like macros to match the spec
+ */
+#define htobe16(x) __htobe16(x)
+#define htobe32(x) __htobe32(x)
+#define htobe64(x) __htobe64(x)
+#define htole16(x) __htole16(x)
+#define htole32(x) __htole32(x)
+#define htole64(x) __htole64(x)
+
+/* POSIX names */
+#define be16toh(x) __htobe16(x)
+#define be32toh(x) __htobe32(x)
+#define be64toh(x) __htobe64(x)
+#define le16toh(x) __htole16(x)
+#define le32toh(x) __htole32(x)
+#define le64toh(x) __htole64(x)
+
+
+#if __BSD_VISIBLE
+#define swap16(x) __swap16(x)
+#define swap32(x) __swap32(x)
+#define swap64(x) __swap64(x)
+
+#define swap16_multi(v, n) do { \
+ __size_t __swap16_multi_n = (n); \
+ __uint16_t *__swap16_multi_v = (v); \
+ \
+ while (__swap16_multi_n) { \
+ *__swap16_multi_v = swap16(*__swap16_multi_v); \
+ __swap16_multi_v++; \
+ __swap16_multi_n--; \
+ } \
+} while (0)
+
+/* original BSD names */
+#define betoh16(x) __htobe16(x)
+#define betoh32(x) __htobe32(x)
+#define betoh64(x) __htobe64(x)
+#define letoh16(x) __htole16(x)
+#define letoh32(x) __htole32(x)
+#define letoh64(x) __htole64(x)
+
+#ifndef htons
+/* these were exposed here before */
+#define htons(x) __htobe16(x)
+#define htonl(x) __htobe32(x)
+#define ntohs(x) __htobe16(x)
+#define ntohl(x) __htobe32(x)
+#endif
+
+/* ancient stuff */
+#define NTOHL(x) (x) = ntohl((u_int32_t)(x))
+#define NTOHS(x) (x) = ntohs((u_int16_t)(x))
+#define HTONL(x) (x) = htonl((u_int32_t)(x))
+#define HTONS(x) (x) = htons((u_int16_t)(x))
+#endif /* __BSD_VISIBLE */
+
+#ifdef _KERNEL
+/* to/from memory conversions */
+#define bemtoh16 __bemtoh16
+#define bemtoh32 __bemtoh32
+#define bemtoh64 __bemtoh64
+#define htobem16 __htobem16
+#define htobem32 __htobem32
+#define htobem64 __htobem64
+#define lemtoh16 __lemtoh16
+#define lemtoh32 __lemtoh32
+#define lemtoh64 __lemtoh64
+#define htolem16 __htolem16
+#define htolem32 __htolem32
+#define htolem64 __htolem64
+#endif /* _KERNEL */
+
+#endif /* _SYS_ENDIAN_H_ */
diff --git a/sys/sys/errno.h b/sys/sys/errno.h
new file mode 100644
index 0000000..cf86be7
--- /dev/null
+++ b/sys/sys/errno.h
@@ -0,0 +1,182 @@
+/* $OpenBSD: errno.h,v 1.25 2017/09/05 03:06:26 jsg Exp $ */
+/* $NetBSD: errno.h,v 1.10 1996/01/20 01:33:53 jtc Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)errno.h 8.5 (Berkeley) 1/21/94
+ */
+
+#include <sys/cdefs.h>
+
+#define EPERM 1 /* Operation not permitted */
+#define ENOENT 2 /* No such file or directory */
+#define ESRCH 3 /* No such process */
+#define EINTR 4 /* Interrupted system call */
+#define EIO 5 /* Input/output error */
+#define ENXIO 6 /* Device not configured */
+#define E2BIG 7 /* Argument list too long */
+#define ENOEXEC 8 /* Exec format error */
+#define EBADF 9 /* Bad file descriptor */
+#define ECHILD 10 /* No child processes */
+#define EDEADLK 11 /* Resource deadlock avoided */
+ /* 11 was EAGAIN */
+#define ENOMEM 12 /* Cannot allocate memory */
+#define EACCES 13 /* Permission denied */
+#define EFAULT 14 /* Bad address */
+#if __BSD_VISIBLE
+#define ENOTBLK 15 /* Block device required */
+#endif
+#define EBUSY 16 /* Device busy */
+#define EEXIST 17 /* File exists */
+#define EXDEV 18 /* Cross-device link */
+#define ENODEV 19 /* Operation not supported by device */
+#define ENOTDIR 20 /* Not a directory */
+#define EISDIR 21 /* Is a directory */
+#define EINVAL 22 /* Invalid argument */
+#define ENFILE 23 /* Too many open files in system */
+#define EMFILE 24 /* Too many open files */
+#define ENOTTY 25 /* Inappropriate ioctl for device */
+#define ETXTBSY 26 /* Text file busy */
+#define EFBIG 27 /* File too large */
+#define ENOSPC 28 /* No space left on device */
+#define ESPIPE 29 /* Illegal seek */
+#define EROFS 30 /* Read-only file system */
+#define EMLINK 31 /* Too many links */
+#define EPIPE 32 /* Broken pipe */
+
+/* math software */
+#define EDOM 33 /* Numerical argument out of domain */
+#define ERANGE 34 /* Result too large */
+
+/* non-blocking and interrupt i/o */
+#define EAGAIN 35 /* Resource temporarily unavailable */
+#define EWOULDBLOCK EAGAIN /* Operation would block */
+#define EINPROGRESS 36 /* Operation now in progress */
+#define EALREADY 37 /* Operation already in progress */
+
+/* ipc/network software -- argument errors */
+#define ENOTSOCK 38 /* Socket operation on non-socket */
+#define EDESTADDRREQ 39 /* Destination address required */
+#define EMSGSIZE 40 /* Message too long */
+#define EPROTOTYPE 41 /* Protocol wrong type for socket */
+#define ENOPROTOOPT 42 /* Protocol not available */
+#define EPROTONOSUPPORT 43 /* Protocol not supported */
+#if __BSD_VISIBLE
+#define ESOCKTNOSUPPORT 44 /* Socket type not supported */
+#endif
+#define EOPNOTSUPP 45 /* Operation not supported */
+#if __BSD_VISIBLE
+#define EPFNOSUPPORT 46 /* Protocol family not supported */
+#endif
+#define EAFNOSUPPORT 47 /* Address family not supported by protocol family */
+#define EADDRINUSE 48 /* Address already in use */
+#define EADDRNOTAVAIL 49 /* Can't assign requested address */
+
+/* ipc/network software -- operational errors */
+#define ENETDOWN 50 /* Network is down */
+#define ENETUNREACH 51 /* Network is unreachable */
+#define ENETRESET 52 /* Network dropped connection on reset */
+#define ECONNABORTED 53 /* Software caused connection abort */
+#define ECONNRESET 54 /* Connection reset by peer */
+#define ENOBUFS 55 /* No buffer space available */
+#define EISCONN 56 /* Socket is already connected */
+#define ENOTCONN 57 /* Socket is not connected */
+#if __BSD_VISIBLE
+#define ESHUTDOWN 58 /* Can't send after socket shutdown */
+#define ETOOMANYREFS 59 /* Too many references: can't splice */
+#endif /* __BSD_VISIBLE */
+#define ETIMEDOUT 60 /* Operation timed out */
+#define ECONNREFUSED 61 /* Connection refused */
+
+#define ELOOP 62 /* Too many levels of symbolic links */
+#define ENAMETOOLONG 63 /* File name too long */
+
+/* should be rearranged */
+#if __BSD_VISIBLE
+#define EHOSTDOWN 64 /* Host is down */
+#endif /* __BSD_VISIBLE */
+#define EHOSTUNREACH 65 /* No route to host */
+#define ENOTEMPTY 66 /* Directory not empty */
+
+/* quotas & mush */
+#if __BSD_VISIBLE
+#define EPROCLIM 67 /* Too many processes */
+#define EUSERS 68 /* Too many users */
+#endif /* __BSD_VISIBLE */
+#define EDQUOT 69 /* Disk quota exceeded */
+
+/* Network File System */
+#define ESTALE 70 /* Stale NFS file handle */
+#if __BSD_VISIBLE
+#define EREMOTE 71 /* Too many levels of remote in path */
+#define EBADRPC 72 /* RPC struct is bad */
+#define ERPCMISMATCH 73 /* RPC version wrong */
+#define EPROGUNAVAIL 74 /* RPC program not available */
+#define EPROGMISMATCH 75 /* Program version wrong */
+#define EPROCUNAVAIL 76 /* Bad procedure for program */
+#endif /* __BSD_VISIBLE */
+
+#define ENOLCK 77 /* No locks available */
+#define ENOSYS 78 /* Function not implemented */
+
+#if __BSD_VISIBLE
+#define EFTYPE 79 /* Inappropriate file type or format */
+#define EAUTH 80 /* Authentication error */
+#define ENEEDAUTH 81 /* Need authenticator */
+#define EIPSEC 82 /* IPsec processing failure */
+#define ENOATTR 83 /* Attribute not found */
+#endif /* __BSD_VISIBLE */
+#define EILSEQ 84 /* Illegal byte sequence */
+#if __BSD_VISIBLE
+#define ENOMEDIUM 85 /* No medium found */
+#define EMEDIUMTYPE 86 /* Wrong medium type */
+#endif /* __BSD_VISIBLE */
+#define EOVERFLOW 87 /* Value too large to be stored in data type */
+#define ECANCELED 88 /* Operation canceled */
+#define EIDRM 89 /* Identifier removed */
+#define ENOMSG 90 /* No message of desired type */
+#define ENOTSUP 91 /* Not supported */
+#define EBADMSG 92 /* Bad message */
+#define ENOTRECOVERABLE 93 /* State not recoverable */
+#define EOWNERDEAD 94 /* Previous owner died */
+#define EPROTO 95 /* Protocol error */
+#if __BSD_VISIBLE
+#define ELAST 95 /* Must be equal largest errno */
+#endif /* __BSD_VISIBLE */
+
+#ifdef _KERNEL
+/* pseudo-errors returned inside kernel to modify return to process */
+#define ERESTART -1 /* restart syscall */
+#define EJUSTRETURN -2 /* don't modify regs, just return */
+#endif
diff --git a/sys/sys/evcount.h b/sys/sys/evcount.h
new file mode 100644
index 0000000..9124e94
--- /dev/null
+++ b/sys/sys/evcount.h
@@ -0,0 +1,50 @@
+/* $OpenBSD: evcount.h,v 1.3 2010/09/20 06:33:46 matthew Exp $ */
+/*
+ * Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
+ * Copyright (c) 2004 Aaron Campbell <aaron@openbsd.org>
+ * 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. 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 __SYS_EVCOUNT_H__
+#define __SYS_EVCOUNT_H__
+
+#ifdef _KERNEL
+
+#include <sys/queue.h>
+
+struct evcount {
+ u_int64_t ec_count; /* main counter */
+ int ec_id; /* counter ID */
+ const char *ec_name; /* counter name */
+ void *ec_data; /* user data */
+
+ TAILQ_ENTRY(evcount) next;
+};
+
+void evcount_attach(struct evcount *, const char *, void *);
+void evcount_detach(struct evcount *);
+int evcount_sysctl(int *, u_int, void *, size_t *, void *, size_t);
+
+#endif /* _KERNEL */
+
+#endif
diff --git a/sys/sys/event.h b/sys/sys/event.h
new file mode 100644
index 0000000..2c345f3
--- /dev/null
+++ b/sys/sys/event.h
@@ -0,0 +1,224 @@
+/* $OpenBSD: event.h,v 1.35 2020/04/07 13:27:52 visa Exp $ */
+
+/*-
+ * Copyright (c) 1999,2000,2001 Jonathan Lemon <jlemon@FreeBSD.org>
+ * 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: src/sys/sys/event.h,v 1.11 2001/02/24 01:41:31 jlemon Exp $
+ */
+
+#ifndef _SYS_EVENT_H_
+#define _SYS_EVENT_H_
+
+#define EVFILT_READ (-1)
+#define EVFILT_WRITE (-2)
+#define EVFILT_AIO (-3) /* attached to aio requests */
+#define EVFILT_VNODE (-4) /* attached to vnodes */
+#define EVFILT_PROC (-5) /* attached to struct process */
+#define EVFILT_SIGNAL (-6) /* attached to struct process */
+#define EVFILT_TIMER (-7) /* timers */
+#define EVFILT_DEVICE (-8) /* devices */
+
+#define EVFILT_SYSCOUNT 8
+
+#define EV_SET(kevp, a, b, c, d, e, f) do { \
+ struct kevent *__kevp = (kevp); \
+ (__kevp)->ident = (a); \
+ (__kevp)->filter = (b); \
+ (__kevp)->flags = (c); \
+ (__kevp)->fflags = (d); \
+ (__kevp)->data = (e); \
+ (__kevp)->udata = (f); \
+} while(0)
+
+struct kevent {
+ __uintptr_t ident; /* identifier for this event */
+ short filter; /* filter for event */
+ unsigned short flags; /* action flags for kqueue */
+ unsigned int fflags; /* filter flag value */
+ __int64_t data; /* filter data value */
+ void *udata; /* opaque user data identifier */
+};
+
+/* actions */
+#define EV_ADD 0x0001 /* add event to kq (implies enable) */
+#define EV_DELETE 0x0002 /* delete event from kq */
+#define EV_ENABLE 0x0004 /* enable event */
+#define EV_DISABLE 0x0008 /* disable event (not reported) */
+
+/* flags */
+#define EV_ONESHOT 0x0010 /* only report one occurrence */
+#define EV_CLEAR 0x0020 /* clear event state after reporting */
+#define EV_RECEIPT 0x0040 /* force EV_ERROR on success, data=0 */
+#define EV_DISPATCH 0x0080 /* disable event after reporting */
+
+#define EV_SYSFLAGS 0xF000 /* reserved by system */
+#define EV_FLAG1 0x2000 /* filter-specific flag */
+
+/* returned values */
+#define EV_EOF 0x8000 /* EOF detected */
+#define EV_ERROR 0x4000 /* error, data contains errno */
+
+/*
+ * data/hint flags for EVFILT_{READ|WRITE}, shared with userspace
+ */
+#define NOTE_LOWAT 0x0001 /* low water mark */
+#define NOTE_EOF 0x0002 /* return on EOF */
+
+/*
+ * data/hint flags for EVFILT_VNODE, shared with userspace
+ */
+#define NOTE_DELETE 0x0001 /* vnode was removed */
+#define NOTE_WRITE 0x0002 /* data contents changed */
+#define NOTE_EXTEND 0x0004 /* size increased */
+#define NOTE_ATTRIB 0x0008 /* attributes changed */
+#define NOTE_LINK 0x0010 /* link count changed */
+#define NOTE_RENAME 0x0020 /* vnode was renamed */
+#define NOTE_REVOKE 0x0040 /* vnode access was revoked */
+#define NOTE_TRUNCATE 0x0080 /* vnode was truncated */
+
+/*
+ * data/hint flags for EVFILT_PROC, shared with userspace
+ */
+#define NOTE_EXIT 0x80000000 /* process exited */
+#define NOTE_FORK 0x40000000 /* process forked */
+#define NOTE_EXEC 0x20000000 /* process exec'd */
+#define NOTE_PCTRLMASK 0xf0000000 /* mask for hint bits */
+#define NOTE_PDATAMASK 0x000fffff /* mask for pid */
+
+/* additional flags for EVFILT_PROC */
+#define NOTE_TRACK 0x00000001 /* follow across forks */
+#define NOTE_TRACKERR 0x00000002 /* could not track child */
+#define NOTE_CHILD 0x00000004 /* am a child process */
+
+/* data/hint flags for EVFILT_DEVICE, shared with userspace */
+#define NOTE_CHANGE 0x00000001 /* device change event */
+
+/*
+ * This is currently visible to userland to work around broken
+ * programs which pull in <sys/proc.h> or <sys/selinfo.h>.
+ */
+#include <sys/queue.h>
+struct knote;
+SLIST_HEAD(knlist, knote);
+
+struct klist {
+ struct knlist kl_list;
+};
+
+#ifdef _KERNEL
+
+#define EVFILT_MARKER 0xf /* placemarker for tailq */
+
+/*
+ * hint flag for in-kernel use - must not equal any existing note
+ */
+#define NOTE_SUBMIT 0x01000000 /* initial knote submission */
+
+#define KNOTE(list_, hint) do { \
+ struct klist *list = (list_); \
+ if ((list) != NULL) \
+ knote((list), (hint)); \
+ } while (0)
+
+#define KN_HASHSIZE 64 /* XXX should be tunable */
+
+/*
+ * Flag indicating hint is a signal. Used by EVFILT_SIGNAL, and also
+ * shared by EVFILT_PROC (all knotes attached to p->p_klist)
+ */
+#define NOTE_SIGNAL 0x08000000
+
+#define FILTEROP_ISFD 0x00000001 /* ident == filedescriptor */
+
+struct filterops {
+ int f_flags;
+ int (*f_attach)(struct knote *kn);
+ void (*f_detach)(struct knote *kn);
+ int (*f_event)(struct knote *kn, long hint);
+};
+
+struct knote {
+ SLIST_ENTRY(knote) kn_link; /* for fd */
+ SLIST_ENTRY(knote) kn_selnext; /* for struct selinfo */
+ TAILQ_ENTRY(knote) kn_tqe;
+ struct kqueue *kn_kq; /* which queue we are on */
+ struct kevent kn_kevent;
+ int kn_status;
+ int kn_sfflags; /* saved filter flags */
+ __int64_t kn_sdata; /* saved data field */
+ union {
+ struct file *p_fp; /* file data pointer */
+ struct process *p_process; /* process pointer */
+ } kn_ptr;
+ const struct filterops *kn_fop;
+ void *kn_hook;
+#define KN_ACTIVE 0x0001 /* event has been triggered */
+#define KN_QUEUED 0x0002 /* event is on queue */
+#define KN_DISABLED 0x0004 /* event is disabled */
+#define KN_DETACHED 0x0008 /* knote is detached */
+#define KN_PROCESSING 0x0010 /* knote is being processed */
+#define KN_WAITING 0x0020 /* waiting on processing */
+
+#define kn_id kn_kevent.ident
+#define kn_filter kn_kevent.filter
+#define kn_flags kn_kevent.flags
+#define kn_fflags kn_kevent.fflags
+#define kn_data kn_kevent.data
+#define kn_fp kn_ptr.p_fp
+};
+
+struct proc;
+
+extern const struct filterops sig_filtops;
+
+extern void knote(struct klist *list, long hint);
+extern void knote_activate(struct knote *);
+extern void knote_remove(struct proc *p, struct knlist *list);
+extern void knote_fdclose(struct proc *p, int fd);
+extern void knote_processexit(struct proc *);
+extern int kqueue_register(struct kqueue *kq,
+ struct kevent *kev, struct proc *p);
+extern int filt_seltrue(struct knote *kn, long hint);
+extern int seltrue_kqfilter(dev_t, struct knote *);
+extern void klist_insert(struct klist *, struct knote *);
+extern void klist_remove(struct klist *, struct knote *);
+extern int klist_empty(struct klist *);
+extern void klist_invalidate(struct klist *);
+
+#else /* !_KERNEL */
+
+#include <sys/cdefs.h>
+struct timespec;
+
+__BEGIN_DECLS
+int kqueue(void);
+int kevent(int kq, const struct kevent *changelist, int nchanges,
+ struct kevent *eventlist, int nevents,
+ const struct timespec *timeout);
+__END_DECLS
+
+#endif /* !_KERNEL */
+
+#endif /* !_SYS_EVENT_H_ */
diff --git a/sys/sys/eventvar.h b/sys/sys/eventvar.h
new file mode 100644
index 0000000..44338c5
--- /dev/null
+++ b/sys/sys/eventvar.h
@@ -0,0 +1,64 @@
+/* $OpenBSD: eventvar.h,v 1.9 2020/04/07 13:27:52 visa Exp $ */
+
+/*-
+ * Copyright (c) 1999,2000 Jonathan Lemon <jlemon@FreeBSD.org>
+ * 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: src/sys/sys/eventvar.h,v 1.3 2000/05/26 02:06:54 jake Exp $
+ */
+
+#ifndef _SYS_EVENTVAR_H_
+#define _SYS_EVENTVAR_H_
+
+#include <sys/task.h>
+
+#define KQ_NEVENTS 8 /* minimize copy{in,out} calls */
+#define KQEXTENT 256 /* linear growth by this amount */
+
+/*
+ * Locking:
+ * a atomic operations
+ */
+struct kqueue {
+ TAILQ_HEAD(, knote) kq_head; /* list of pending event */
+ int kq_count; /* number of pending events */
+ u_int kq_refs; /* [a] number of references */
+ struct selinfo kq_sel;
+ struct filedesc *kq_fdp;
+
+ LIST_ENTRY(kqueue) kq_next;
+
+ int kq_knlistsize; /* size of kq_knlist */
+ struct knlist *kq_knlist; /* list of attached knotes */
+ u_long kq_knhashmask; /* size of kq_knhash */
+ struct knlist *kq_knhash; /* hash table for attached knotes */
+ struct task kq_task; /* deferring of activation */
+
+ int kq_state;
+#define KQ_SEL 0x01
+#define KQ_SLEEP 0x02
+#define KQ_DYING 0x04
+};
+
+#endif /* !_SYS_EVENTVAR_H_ */
diff --git a/sys/sys/exec.h b/sys/sys/exec.h
new file mode 100644
index 0000000..ecaef3e
--- /dev/null
+++ b/sys/sys/exec.h
@@ -0,0 +1,386 @@
+/* $OpenBSD: exec.h,v 1.40 2019/11/29 06:34:46 deraadt Exp $ */
+/* $NetBSD: exec.h,v 1.59 1996/02/09 18:25:09 christos Exp $ */
+
+/*-
+ * Copyright (c) 1994 Christopher G. Demetriou
+ * Copyright (c) 1993 Theo de Raadt
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)exec.h 8.3 (Berkeley) 1/21/94
+ */
+
+#ifndef _SYS_EXEC_H_
+#define _SYS_EXEC_H_
+
+/*
+ * The following structure is found at the top of the user stack of each
+ * user process. The ps program uses it to locate argv and environment
+ * strings. Programs that wish ps to display other information may modify
+ * it; normally ps_argvstr points to argv[0], and ps_nargvstr is the same
+ * as the program's argc. The fields ps_envstr and ps_nenvstr are the
+ * equivalent for the environment.
+ */
+struct ps_strings {
+ char **ps_argvstr; /* first of 0 or more argument strings */
+ int ps_nargvstr; /* the number of argument strings */
+ char **ps_envstr; /* first of 0 or more environment strings */
+ int ps_nenvstr; /* the number of environment strings */
+};
+
+/*
+ * Below the PS_STRINGS and sigtramp, we may require a gap on the stack
+ * (used to copyin/copyout various emulation data structures).
+ */
+#define STACKGAPLEN (2*1024) /* plenty enough for now */
+
+/*
+ * the following structures allow execve() to put together processes
+ * in a more extensible and cleaner way.
+ *
+ * the exec_package struct defines an executable being execve()'d.
+ * it contains the header, the vmspace-building commands, the vnode
+ * information, and the arguments associated with the newly-execve'd
+ * process.
+ *
+ * the exec_vmcmd struct defines a command description to be used
+ * in creating the new process's vmspace.
+ */
+
+struct proc;
+struct exec_package;
+
+typedef int (*exec_makecmds_fcn)(struct proc *, struct exec_package *);
+
+struct execsw {
+ u_int es_hdrsz; /* size of header for this format */
+ exec_makecmds_fcn es_check; /* function to check exec format */
+};
+
+struct exec_vmcmd {
+ int (*ev_proc)(struct proc *p, struct exec_vmcmd *cmd);
+ /* procedure to run for region of vmspace */
+ u_long ev_len; /* length of the segment to map */
+ u_long ev_addr; /* address in the vmspace to place it at */
+ struct vnode *ev_vp; /* vnode pointer for the file w/the data */
+ u_long ev_offset; /* offset in the file for the data */
+ u_int ev_prot; /* protections for segment */
+ int ev_flags;
+#define VMCMD_RELATIVE 0x0001 /* ev_addr is relative to base entry */
+#define VMCMD_BASE 0x0002 /* marks a base entry */
+#define VMCMD_STACK 0x0004 /* create with UVM_FLAG_STACK */
+#define VMCMD_SYSCALL 0x0008 /* create with UVM_FLAG_SYSCALL */
+};
+
+#define EXEC_DEFAULT_VMCMD_SETSIZE 8 /* # of cmds in set to start */
+
+/* exec vmspace-creation command set; see below */
+struct exec_vmcmd_set {
+ u_int evs_cnt;
+ u_int evs_used;
+ struct exec_vmcmd *evs_cmds;
+ struct exec_vmcmd evs_start[EXEC_DEFAULT_VMCMD_SETSIZE];
+};
+
+struct exec_package {
+ char *ep_name; /* file's name */
+ void *ep_hdr; /* file's exec header */
+ u_int ep_hdrlen; /* length of ep_hdr */
+ u_int ep_hdrvalid; /* bytes of ep_hdr that are valid */
+ struct nameidata *ep_ndp; /* namei data pointer for lookups */
+ struct exec_vmcmd_set ep_vmcmds; /* vmcmds used to build vmspace */
+ struct vnode *ep_vp; /* executable's vnode */
+ struct vattr *ep_vap; /* executable's attributes */
+ u_long ep_taddr; /* process's text address */
+ u_long ep_tsize; /* size of process's text */
+ u_long ep_daddr; /* process's data(+bss) address */
+ u_long ep_dsize; /* size of process's data(+bss) */
+ u_long ep_maxsaddr; /* proc's max stack addr ("top") */
+ u_long ep_minsaddr; /* proc's min stack addr ("bottom") */
+ u_long ep_ssize; /* size of process's stack */
+ u_long ep_entry; /* process's entry point */
+ u_int ep_flags; /* flags; see below. */
+ char **ep_fa; /* a fake args vector for scripts */
+ int ep_fd; /* a file descriptor we're holding */
+ struct emul *ep_emul; /* os emulation */
+ void *ep_emul_arg; /* emulation argument */
+ size_t ep_emul_argsize; /* emulation argument size */
+ void *ep_emul_argp; /* emulation argument pointer */
+ char *ep_interp; /* name of interpreter if any */
+};
+#define EXEC_INDIR 0x0001 /* script handling already done */
+#define EXEC_HASFD 0x0002 /* holding a shell script */
+#define EXEC_HASARGL 0x0004 /* has fake args vector */
+#define EXEC_SKIPARG 0x0008 /* don't copy user-supplied argv[0] */
+#define EXEC_DESTR 0x0010 /* destructive ops performed */
+#define EXEC_WXNEEDED 0x0020 /* executable will violate W^X */
+
+#ifdef _KERNEL
+/*
+ * functions used either by execve() or the various cpu-dependent execve()
+ * hooks.
+ */
+int exec_makecmds(struct proc *, struct exec_package *);
+int exec_runcmds(struct proc *, struct exec_package *);
+void vmcmdset_extend(struct exec_vmcmd_set *);
+void kill_vmcmds(struct exec_vmcmd_set *evsp);
+int vmcmd_map_pagedvn(struct proc *, struct exec_vmcmd *);
+int vmcmd_map_readvn(struct proc *, struct exec_vmcmd *);
+int vmcmd_map_zero(struct proc *, struct exec_vmcmd *);
+int vmcmd_randomize(struct proc *, struct exec_vmcmd *);
+void *copyargs(struct exec_package *,
+ struct ps_strings *,
+ void *, void *);
+void setregs(struct proc *, struct exec_package *,
+ u_long, register_t *);
+int check_exec(struct proc *, struct exec_package *);
+int exec_setup_stack(struct proc *, struct exec_package *);
+int exec_process_vmcmds(struct proc *, struct exec_package *);
+
+#ifdef DEBUG
+void new_vmcmd(struct exec_vmcmd_set *evsp,
+ int (*proc)(struct proc *p, struct exec_vmcmd *),
+ u_long len, u_long addr, struct vnode *vp, u_long offset,
+ u_int prot, int flags);
+#define NEW_VMCMD(evsp,proc,len,addr,vp,offset,prot) \
+ new_vmcmd(evsp,proc,len,addr,vp,offset,prot, 0);
+#define NEW_VMCMD2(evsp,proc,len,addr,vp,offset,prot,flags) \
+ new_vmcmd(evsp,proc,len,addr,vp,offset,prot,flags)
+#else /* DEBUG */
+#define NEW_VMCMD(evsp,proc,len,addr,vp,offset,prot) \
+ NEW_VMCMD2(evsp,proc,len,addr,vp,offset,prot,0)
+#define NEW_VMCMD2(evsp,proc,len,addr,vp,offset,prot,flags) do { \
+ struct exec_vmcmd *vcp; \
+ if ((evsp)->evs_used >= (evsp)->evs_cnt) \
+ vmcmdset_extend(evsp); \
+ vcp = &(evsp)->evs_cmds[(evsp)->evs_used++]; \
+ vcp->ev_proc = (proc); \
+ vcp->ev_len = (len); \
+ vcp->ev_addr = (addr); \
+ if ((vcp->ev_vp = (vp)) != NULLVP) \
+ vref(vp); \
+ vcp->ev_offset = (offset); \
+ vcp->ev_prot = (prot); \
+ vcp->ev_flags = (flags); \
+} while (0)
+
+#endif /* DEBUG */
+
+/* Initialize an empty vmcmd set */
+#define VMCMDSET_INIT(vmc) do { \
+ (vmc)->evs_cnt = EXEC_DEFAULT_VMCMD_SETSIZE; \
+ (vmc)->evs_cmds = (vmc)->evs_start; \
+ (vmc)->evs_used = 0; \
+} while (0)
+
+/*
+ * Exec function switch:
+ *
+ * Note that each makecmds function is responsible for loading the
+ * exec package with the necessary functions for any exec-type-specific
+ * handling.
+ *
+ * Functions for specific exec types should be defined in their own
+ * header file.
+ */
+extern struct execsw execsw[];
+extern int nexecs;
+extern int exec_maxhdrsz;
+
+/*
+ * If non-zero, stackgap_random specifies the upper limit of the random gap size
+ * added to the fixed stack position. Must be n^2.
+ */
+extern int stackgap_random;
+
+/* Limit on total PT_OPENBSD_RANDOMIZE bytes. */
+#define ELF_RANDOMIZE_LIMIT 1024*1024
+
+#endif /* _KERNEL */
+
+#ifndef N_PAGSIZ
+#define N_PAGSIZ(ex) (__LDPGSZ)
+#endif
+
+/*
+ * Legacy a.out structures and defines; start deleting these when
+ * external use no longer exist.
+ */
+
+
+/*
+ * Header prepended to each a.out file.
+ * only manipulate the a_midmag field via the
+ * N_SETMAGIC/N_GET{MAGIC,MID,FLAG} macros below.
+ */
+struct exec {
+ u_int32_t a_midmag; /* htonl(flags<<26|mid<<16|magic) */
+ u_int32_t a_text; /* text segment size */
+ u_int32_t a_data; /* initialized data size */
+ u_int32_t a_bss; /* uninitialized data size */
+ u_int32_t a_syms; /* symbol table size */
+ u_int32_t a_entry; /* entry point */
+ u_int32_t a_trsize; /* text relocation size */
+ u_int32_t a_drsize; /* data relocation size */
+};
+
+/* a_magic */
+#define OMAGIC 0407 /* old impure format */
+#define NMAGIC 0410 /* read-only text */
+#define ZMAGIC 0413 /* demand load format */
+#define QMAGIC 0314 /* "compact" demand load format; deprecated */
+
+/*
+ * a_mid - keep sorted in numerical order for sanity's sake
+ * ensure that: 0 < mid < 0x3ff
+ */
+#define MID_ZERO 0 /* unknown - implementation dependent */
+#define MID_SUN010 1 /* sun 68010/68020 binary */
+#define MID_SUN020 2 /* sun 68020-only binary */
+#define MID_PC386 100 /* 386 PC binary. (so quoth BFD) */
+#define MID_ROMPAOS 104 /* old IBM RT */
+#define MID_I386 134 /* i386 BSD binary */
+#define MID_M68K 135 /* m68k BSD binary with 8K page sizes */
+#define MID_M68K4K 136 /* DO NOT USE: m68k BSD binary with 4K page sizes */
+#define MID_NS32532 137 /* ns32532 */
+#define MID_SPARC 138 /* sparc */
+#define MID_PMAX 139 /* pmax */
+#define MID_VAX1K 140 /* vax 1k page size */
+#define MID_ALPHA 141 /* Alpha BSD binary */
+#define MID_MIPS 142 /* big-endian MIPS */
+#define MID_ARM6 143 /* ARM6 */
+#define MID_SH3 145 /* SH3 */
+#define MID_POWERPC 149 /* big-endian PowerPC */
+#define MID_VAX 150 /* vax */
+#define MID_SPARC64 151 /* LP64 sparc */
+#define MID_MIPS2 152 /* MIPS2 */
+#define MID_M88K 153 /* m88k BSD binary */
+#define MID_HPPA 154 /* hppa */
+#define MID_AMD64 157 /* AMD64 */
+#define MID_MIPS64 158 /* big-endian MIPS64 */
+#define MID_ARM64 159 /* ARM64 */
+#define MID_HP200 200 /* hp200 (68010) BSD binary */
+#define MID_HP300 300 /* hp300 (68020+68881) BSD binary */
+#define MID_HPUX 0x20C /* hp200/300 HP-UX binary */
+#define MID_HPUX800 0x20B /* hp800 HP-UX binary pa1.0 */
+#define MID_HPPA11 0x210 /* hp700 HP-UX binary pa1.1 */
+#define MID_HPPA20 0x214 /* hp700 HP-UX binary pa2.0 */
+
+/*
+ * a_flags
+ */
+#define EX_DYNAMIC 0x20
+#define EX_PIC 0x10
+#define EX_DPMASK 0x30
+/*
+ * Interpretation of the (a_flags & EX_DPMASK) bits:
+ *
+ * 00 traditional executable or object file
+ * 01 object file contains PIC code (set by `as -k')
+ * 10 dynamic executable
+ * 11 position independent executable image
+ * (eg. a shared library)
+ *
+ */
+
+/*
+ * The a.out structure's a_midmag field is a network-byteorder encoding
+ * of this int
+ * FFFFFFmmmmmmmmmmMMMMMMMMMMMMMMMM
+ * Where `F' is 6 bits of flag like EX_DYNAMIC,
+ * `m' is 10 bits of machine-id like MID_I386, and
+ * `M' is 16 bits worth of magic number, ie. ZMAGIC.
+ * The macros below will set/get the needed fields.
+ */
+#define N_GETMAGIC(ex) \
+ ( (((ex).a_midmag)&0xffff0000) ? (ntohl(((ex).a_midmag))&0xffff) : ((ex).a_midmag))
+#define N_GETMAGIC2(ex) \
+ ( (((ex).a_midmag)&0xffff0000) ? (ntohl(((ex).a_midmag))&0xffff) : \
+ (((ex).a_midmag) | 0x10000) )
+#define N_GETMID(ex) \
+ ( (((ex).a_midmag)&0xffff0000) ? ((ntohl(((ex).a_midmag))>>16)&0x03ff) : MID_ZERO )
+#define N_GETFLAG(ex) \
+ ( (((ex).a_midmag)&0xffff0000) ? ((ntohl(((ex).a_midmag))>>26)&0x3f) : 0 )
+#define N_SETMAGIC(ex,mag,mid,flag) \
+ ( (ex).a_midmag = htonl( (((flag)&0x3f)<<26) | (((mid)&0x03ff)<<16) | \
+ (((mag)&0xffff)) ) )
+
+#define N_ALIGN(ex,x) \
+ (N_GETMAGIC(ex) == ZMAGIC || N_GETMAGIC(ex) == QMAGIC ? \
+ ((x) + __LDPGSZ - 1) & ~(__LDPGSZ - 1) : (x))
+
+/* Valid magic number check. */
+#define N_BADMAG(ex) \
+ (N_GETMAGIC(ex) != NMAGIC && N_GETMAGIC(ex) != OMAGIC && \
+ N_GETMAGIC(ex) != ZMAGIC && N_GETMAGIC(ex) != QMAGIC)
+
+/* Address of the bottom of the text segment. */
+#define N_TXTADDR(ex) (N_GETMAGIC2(ex) == (ZMAGIC|0x10000) ? 0 : __LDPGSZ)
+
+/* Address of the bottom of the data segment. */
+#define N_DATADDR(ex) \
+ (N_GETMAGIC(ex) == OMAGIC ? N_TXTADDR(ex) + (ex).a_text : \
+ (N_TXTADDR(ex) + (ex).a_text + __LDPGSZ - 1) & ~(__LDPGSZ - 1))
+
+/* Address of the bottom of the bss segment. */
+#define N_BSSADDR(ex) \
+ (N_DATADDR(ex) + (ex).a_data)
+
+/* Text segment offset. */
+#define N_TXTOFF(ex) \
+ ( N_GETMAGIC2(ex)==ZMAGIC || N_GETMAGIC2(ex)==(QMAGIC|0x10000) ? \
+ 0 : (N_GETMAGIC2(ex)==(ZMAGIC|0x10000) ? __LDPGSZ : \
+ sizeof(struct exec)) )
+
+/* Data segment offset. */
+#define N_DATOFF(ex) \
+ N_ALIGN(ex, N_TXTOFF(ex) + (ex).a_text)
+
+/* Text relocation table offset. */
+#define N_TRELOFF(ex) \
+ (N_DATOFF(ex) + (ex).a_data)
+
+/* Data relocation table offset. */
+#define N_DRELOFF(ex) \
+ (N_TRELOFF(ex) + (ex).a_trsize)
+
+/* Symbol table offset. */
+#define N_SYMOFF(ex) \
+ (N_DRELOFF(ex) + (ex).a_drsize)
+
+/* String table offset. */
+#define N_STROFF(ex) \
+ (N_SYMOFF(ex) + (ex).a_syms)
+
+#include <machine/exec.h>
+
+#endif /* !_SYS_EXEC_H_ */
diff --git a/sys/sys/exec_elf.h b/sys/sys/exec_elf.h
new file mode 100644
index 0000000..a40e051
--- /dev/null
+++ b/sys/sys/exec_elf.h
@@ -0,0 +1,785 @@
+/* $OpenBSD: exec_elf.h,v 1.87 2019/12/01 13:10:51 jsg Exp $ */
+/*
+ * Copyright (c) 1995, 1996 Erik Theisen. 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.
+ */
+
+/*
+ * This is the ELF ABI header file
+ * formerly known as "elf_abi.h".
+ */
+
+#ifndef _SYS_EXEC_ELF_H_
+#define _SYS_EXEC_ELF_H_
+
+#include <sys/types.h>
+#include <machine/exec.h>
+
+typedef __uint32_t Elf32_Addr; /* Unsigned program address */
+typedef __uint32_t Elf32_Off; /* Unsigned file offset */
+typedef __int32_t Elf32_Sword; /* Signed large integer */
+typedef __uint32_t Elf32_Word; /* Unsigned large integer */
+typedef __uint16_t Elf32_Half; /* Unsigned medium integer */
+typedef __uint64_t Elf32_Lword;
+
+typedef __uint64_t Elf64_Addr;
+typedef __uint64_t Elf64_Off;
+typedef __int32_t Elf64_Shalf;
+
+typedef __int32_t Elf64_Sword;
+typedef __uint32_t Elf64_Word;
+
+typedef __int64_t Elf64_Sxword;
+typedef __uint64_t Elf64_Xword;
+typedef __uint64_t Elf64_Lword;
+
+typedef __uint16_t Elf64_Half;
+
+/*
+ * e_ident[] identification indexes
+ * See http://www.sco.com/developers/gabi/latest/ch4.eheader.html
+ */
+#define EI_MAG0 0 /* file ID */
+#define EI_MAG1 1 /* file ID */
+#define EI_MAG2 2 /* file ID */
+#define EI_MAG3 3 /* file ID */
+#define EI_CLASS 4 /* file class */
+#define EI_DATA 5 /* data encoding */
+#define EI_VERSION 6 /* ELF header version */
+#define EI_OSABI 7 /* OS/ABI ID */
+#define EI_ABIVERSION 8 /* ABI version */
+#define EI_PAD 9 /* start of pad bytes */
+#define EI_NIDENT 16 /* Size of e_ident[] */
+
+/* e_ident[] magic number */
+#define ELFMAG0 0x7f /* e_ident[EI_MAG0] */
+#define ELFMAG1 'E' /* e_ident[EI_MAG1] */
+#define ELFMAG2 'L' /* e_ident[EI_MAG2] */
+#define ELFMAG3 'F' /* e_ident[EI_MAG3] */
+#define ELFMAG "\177ELF" /* magic */
+#define SELFMAG 4 /* size of magic */
+
+/* e_ident[] file class */
+#define ELFCLASSNONE 0 /* invalid */
+#define ELFCLASS32 1 /* 32-bit objs */
+#define ELFCLASS64 2 /* 64-bit objs */
+#define ELFCLASSNUM 3 /* number of classes */
+
+/* e_ident[] data encoding */
+#define ELFDATANONE 0 /* invalid */
+#define ELFDATA2LSB 1 /* Little-Endian */
+#define ELFDATA2MSB 2 /* Big-Endian */
+#define ELFDATANUM 3 /* number of data encode defines */
+
+/* e_ident[] Operating System/ABI */
+#define ELFOSABI_SYSV 0 /* UNIX System V ABI */
+#define ELFOSABI_HPUX 1 /* HP-UX operating system */
+#define ELFOSABI_NETBSD 2 /* NetBSD */
+#define ELFOSABI_LINUX 3 /* GNU/Linux */
+#define ELFOSABI_HURD 4 /* GNU/Hurd */
+#define ELFOSABI_86OPEN 5 /* 86Open common IA32 ABI */
+#define ELFOSABI_SOLARIS 6 /* Solaris */
+#define ELFOSABI_MONTEREY 7 /* Monterey */
+#define ELFOSABI_IRIX 8 /* IRIX */
+#define ELFOSABI_FREEBSD 9 /* FreeBSD */
+#define ELFOSABI_TRU64 10 /* TRU64 UNIX */
+#define ELFOSABI_MODESTO 11 /* Novell Modesto */
+#define ELFOSABI_OPENBSD 12 /* OpenBSD */
+#define ELFOSABI_ARM 97 /* ARM */
+#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
+
+/* e_ident */
+#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
+ (ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
+ (ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
+ (ehdr).e_ident[EI_MAG3] == ELFMAG3)
+
+/* ELF Header */
+typedef struct elfhdr {
+ unsigned char e_ident[EI_NIDENT]; /* ELF Identification */
+ Elf32_Half e_type; /* object file type */
+ Elf32_Half e_machine; /* machine */
+ Elf32_Word e_version; /* object file version */
+ Elf32_Addr e_entry; /* virtual entry point */
+ Elf32_Off e_phoff; /* program header table offset */
+ Elf32_Off e_shoff; /* section header table offset */
+ Elf32_Word e_flags; /* processor-specific flags */
+ Elf32_Half e_ehsize; /* ELF header size */
+ Elf32_Half e_phentsize; /* program header entry size */
+ Elf32_Half e_phnum; /* number of program header entries */
+ Elf32_Half e_shentsize; /* section header entry size */
+ Elf32_Half e_shnum; /* number of section header entries */
+ Elf32_Half e_shstrndx; /* section header table's "section
+ header string table" entry offset */
+} Elf32_Ehdr;
+
+typedef struct {
+ unsigned char e_ident[EI_NIDENT]; /* Id bytes */
+ Elf64_Half e_type; /* file type */
+ Elf64_Half e_machine; /* machine type */
+ Elf64_Word e_version; /* version number */
+ Elf64_Addr e_entry; /* entry point */
+ Elf64_Off e_phoff; /* Program hdr offset */
+ Elf64_Off e_shoff; /* Section hdr offset */
+ Elf64_Word e_flags; /* Processor flags */
+ Elf64_Half e_ehsize; /* sizeof ehdr */
+ Elf64_Half e_phentsize; /* Program header entry size */
+ Elf64_Half e_phnum; /* Number of program headers */
+ Elf64_Half e_shentsize; /* Section header entry size */
+ Elf64_Half e_shnum; /* Number of section headers */
+ Elf64_Half e_shstrndx; /* String table index */
+} Elf64_Ehdr;
+
+/* e_type */
+#define ET_NONE 0 /* No file type */
+#define ET_REL 1 /* relocatable file */
+#define ET_EXEC 2 /* executable file */
+#define ET_DYN 3 /* shared object file */
+#define ET_CORE 4 /* core file */
+#define ET_NUM 5 /* number of types */
+#define ET_LOPROC 0xff00 /* reserved range for processor */
+#define ET_HIPROC 0xffff /* specific e_type */
+
+/* e_machine */
+#define EM_NONE 0 /* No Machine */
+#define EM_M32 1 /* AT&T WE 32100 */
+#define EM_SPARC 2 /* SPARC */
+#define EM_386 3 /* Intel 80386 */
+#define EM_68K 4 /* Motorola 68000 */
+#define EM_88K 5 /* Motorola 88000 */
+#define EM_486 6 /* Intel 80486 - unused? */
+#define EM_860 7 /* Intel 80860 */
+#define EM_MIPS 8 /* MIPS R3000 Big-Endian only */
+/*
+ * Don't know if EM_MIPS_RS4_BE,
+ * EM_SPARC64, EM_PARISC,
+ * or EM_PPC are ABI compliant
+ */
+#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */
+#define EM_SPARC64 11 /* SPARC v9 64-bit unofficial */
+#define EM_PARISC 15 /* HPPA */
+#define EM_SPARC32PLUS 18 /* Enhanced instruction set SPARC */
+#define EM_PPC 20 /* PowerPC */
+#define EM_PPC64 21 /* PowerPC 64 */
+#define EM_ARM 40 /* Advanced RISC Machines ARM */
+#define EM_ALPHA 41 /* DEC ALPHA */
+#define EM_SH 42 /* Hitachi/Renesas Super-H */
+#define EM_SPARCV9 43 /* SPARC version 9 */
+#define EM_IA_64 50 /* Intel IA-64 Processor */
+#define EM_AMD64 62 /* AMD64 architecture */
+#define EM_X86_64 EM_AMD64
+#define EM_VAX 75 /* DEC VAX */
+#define EM_AARCH64 183 /* ARM 64-bit architecture (AArch64) */
+
+/* Non-standard */
+#define EM_ALPHA_EXP 0x9026 /* DEC ALPHA */
+#define EM__LAST__ (EM_ALPHA_EXP + 1)
+
+#define EM_NUM 22 /* number of machine types */
+
+/* Version */
+#define EV_NONE 0 /* Invalid */
+#define EV_CURRENT 1 /* Current */
+#define EV_NUM 2 /* number of versions */
+
+/* Magic for e_phnum: get real value from sh_info of first section header */
+#define PN_XNUM 0xffff
+
+/* Section Header */
+typedef struct {
+ Elf32_Word sh_name; /* name - index into section header
+ string table section */
+ Elf32_Word sh_type; /* type */
+ Elf32_Word sh_flags; /* flags */
+ Elf32_Addr sh_addr; /* address */
+ Elf32_Off sh_offset; /* file offset */
+ Elf32_Word sh_size; /* section size */
+ Elf32_Word sh_link; /* section header table index link */
+ Elf32_Word sh_info; /* extra information */
+ Elf32_Word sh_addralign; /* address alignment */
+ Elf32_Word sh_entsize; /* section entry size */
+} Elf32_Shdr;
+
+typedef struct {
+ Elf64_Word sh_name; /* section name */
+ Elf64_Word sh_type; /* section type */
+ Elf64_Xword sh_flags; /* section flags */
+ Elf64_Addr sh_addr; /* virtual address */
+ Elf64_Off sh_offset; /* file offset */
+ Elf64_Xword sh_size; /* section size */
+ Elf64_Word sh_link; /* link to another */
+ Elf64_Word sh_info; /* misc info */
+ Elf64_Xword sh_addralign; /* memory alignment */
+ Elf64_Xword sh_entsize; /* table entry size */
+} Elf64_Shdr;
+
+/* Special Section Indexes */
+#define SHN_UNDEF 0 /* undefined */
+#define SHN_LORESERVE 0xff00 /* lower bounds of reserved indexes */
+#define SHN_LOPROC 0xff00 /* reserved range for processor */
+#define SHN_HIPROC 0xff1f /* specific section indexes */
+#define SHN_ABS 0xfff1 /* absolute value */
+#define SHN_COMMON 0xfff2 /* common symbol */
+#define SHN_XINDEX 0xffff /* Escape -- index stored elsewhere. */
+#define SHN_HIRESERVE 0xffff /* upper bounds of reserved indexes */
+
+/* sh_type */
+#define SHT_NULL 0 /* inactive */
+#define SHT_PROGBITS 1 /* program defined information */
+#define SHT_SYMTAB 2 /* symbol table section */
+#define SHT_STRTAB 3 /* string table section */
+#define SHT_RELA 4 /* relocation section with addends*/
+#define SHT_HASH 5 /* symbol hash table section */
+#define SHT_DYNAMIC 6 /* dynamic section */
+#define SHT_NOTE 7 /* note section */
+#define SHT_NOBITS 8 /* no space section */
+#define SHT_REL 9 /* relation section without addends */
+#define SHT_SHLIB 10 /* reserved - purpose unknown */
+#define SHT_DYNSYM 11 /* dynamic symbol table section */
+#define SHT_NUM 12 /* number of section types */
+#define SHT_INIT_ARRAY 14 /* pointers to init functions */
+#define SHT_FINI_ARRAY 15 /* pointers to termination functions */
+#define SHT_PREINIT_ARRAY 16 /* ptrs to funcs called before init */
+#define SHT_GROUP 17 /* defines a section group */
+#define SHT_SYMTAB_SHNDX 18 /* Section indexes (see SHN_XINDEX). */
+#define SHT_LOOS 0x60000000 /* reserved range for OS specific */
+#define SHT_SUNW_dof 0x6ffffff4 /* used by dtrace */
+#define SHT_GNU_LIBLIST 0x6ffffff7 /* libraries to be prelinked */
+#define SHT_SUNW_move 0x6ffffffa /* inf for partially init'ed symbols */
+#define SHT_SUNW_syminfo 0x6ffffffc /* ad symbol information */
+#define SHT_SUNW_verdef 0x6ffffffd /* symbol versioning inf */
+#define SHT_SUNW_verneed 0x6ffffffe /* symbol versioning req */
+#define SHT_SUNW_versym 0x6fffffff /* symbol versioning table */
+#define SHT_HIOS 0x6fffffff /* section header types */
+#define SHT_LOPROC 0x70000000 /* reserved range for processor */
+#define SHT_HIPROC 0x7fffffff /* specific section header types */
+#define SHT_LOUSER 0x80000000 /* reserved range for application */
+#define SHT_HIUSER 0xffffffff /* specific indexes */
+
+#define SHT_GNU_HASH 0x6ffffff6 /* GNU-style hash table section */
+
+/* Section names */
+#define ELF_BSS ".bss" /* uninitialized data */
+#define ELF_DATA ".data" /* initialized data */
+#define ELF_CTF ".SUNW_ctf" /* CTF data */
+#define ELF_DEBUG ".debug" /* debug */
+#define ELF_DYNAMIC ".dynamic" /* dynamic linking information */
+#define ELF_DYNSTR ".dynstr" /* dynamic string table */
+#define ELF_DYNSYM ".dynsym" /* dynamic symbol table */
+#define ELF_FINI ".fini" /* termination code */
+#define ELF_GOT ".got" /* global offset table */
+#define ELF_HASH ".hash" /* symbol hash table */
+#define ELF_INIT ".init" /* initialization code */
+#define ELF_REL_DATA ".rel.data" /* relocation data */
+#define ELF_REL_FINI ".rel.fini" /* relocation termination code */
+#define ELF_REL_INIT ".rel.init" /* relocation initialization code */
+#define ELF_REL_DYN ".rel.dyn" /* relocation dynamic link info */
+#define ELF_REL_RODATA ".rel.rodata" /* relocation read-only data */
+#define ELF_REL_TEXT ".rel.text" /* relocation code */
+#define ELF_RODATA ".rodata" /* read-only data */
+#define ELF_SHSTRTAB ".shstrtab" /* section header string table */
+#define ELF_STRTAB ".strtab" /* string table */
+#define ELF_SYMTAB ".symtab" /* symbol table */
+#define ELF_TEXT ".text" /* code */
+#define ELF_OPENBSDRANDOMDATA ".openbsd.randomdata" /* constant randomdata */
+
+
+/* Section Attribute Flags - sh_flags */
+#define SHF_WRITE 0x1 /* Writable */
+#define SHF_ALLOC 0x2 /* occupies memory */
+#define SHF_EXECINSTR 0x4 /* executable */
+#define SHF_MERGE 0x10 /* may be merged */
+#define SHF_STRINGS 0x20 /* contains strings */
+#define SHF_INFO_LINK 0x40 /* sh_info holds section index */
+#define SHF_LINK_ORDER 0x80 /* ordering requirements */
+#define SHF_OS_NONCONFORMING 0x100 /* OS-specific processing required */
+#define SHF_GROUP 0x200 /* member of section group */
+#define SHF_TLS 0x400 /* thread local storage */
+#define SHF_COMPRESSED 0x800 /* contains compressed data */
+#define SHF_MASKOS 0x0ff00000 /* OS-specific semantics */
+#define SHF_MASKPROC 0xf0000000 /* reserved bits for processor */
+ /* specific section attributes */
+
+/* Symbol Table Entry */
+typedef struct elf32_sym {
+ Elf32_Word st_name; /* name - index into string table */
+ Elf32_Addr st_value; /* symbol value */
+ Elf32_Word st_size; /* symbol size */
+ unsigned char st_info; /* type and binding */
+ unsigned char st_other; /* 0 - no defined meaning */
+ Elf32_Half st_shndx; /* section header index */
+} Elf32_Sym;
+
+typedef struct {
+ Elf64_Word st_name; /* Symbol name index in str table */
+ unsigned char st_info; /* type / binding attrs */
+ unsigned char st_other; /* unused */
+ Elf64_Half st_shndx; /* section index of symbol */
+ Elf64_Addr st_value; /* value of symbol */
+ Elf64_Xword st_size; /* size of symbol */
+} Elf64_Sym;
+
+/* Symbol table index */
+#define STN_UNDEF 0 /* undefined */
+
+/* Extract symbol info - st_info */
+#define ELF32_ST_BIND(x) ((x) >> 4)
+#define ELF32_ST_TYPE(x) (((unsigned int) x) & 0xf)
+#define ELF32_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))
+
+#define ELF64_ST_BIND(x) ((x) >> 4)
+#define ELF64_ST_TYPE(x) (((unsigned int) x) & 0xf)
+#define ELF64_ST_INFO(b,t) (((b) << 4) + ((t) & 0xf))
+
+/* Symbol Binding - ELF32_ST_BIND - st_info */
+#define STB_LOCAL 0 /* Local symbol */
+#define STB_GLOBAL 1 /* Global symbol */
+#define STB_WEAK 2 /* like global - lower precedence */
+#define STB_NUM 3 /* number of symbol bindings */
+#define STB_LOPROC 13 /* reserved range for processor */
+#define STB_HIPROC 15 /* specific symbol bindings */
+
+/* Symbol type - ELF32_ST_TYPE - st_info */
+#define STT_NOTYPE 0 /* not specified */
+#define STT_OBJECT 1 /* data object */
+#define STT_FUNC 2 /* function */
+#define STT_SECTION 3 /* section */
+#define STT_FILE 4 /* file */
+#define STT_TLS 6 /* thread local storage */
+#define STT_LOPROC 13 /* reserved range for processor */
+#define STT_HIPROC 15 /* specific symbol types */
+
+/* Extract symbol visibility - st_other */
+#define ELF_ST_VISIBILITY(v) ((v) & 0x3)
+#define ELF32_ST_VISIBILITY ELF_ST_VISIBILITY
+#define ELF64_ST_VISIBILITY ELF_ST_VISIBILITY
+
+#define STV_DEFAULT 0 /* Visibility set by binding type */
+#define STV_INTERNAL 1 /* OS specific version of STV_HIDDEN */
+#define STV_HIDDEN 2 /* can only be seen inside own .so */
+#define STV_PROTECTED 3 /* HIDDEN inside, DEFAULT outside */
+
+/* Relocation entry with implicit addend */
+typedef struct {
+ Elf32_Addr r_offset; /* offset of relocation */
+ Elf32_Word r_info; /* symbol table index and type */
+} Elf32_Rel;
+
+/* Relocation entry with explicit addend */
+typedef struct {
+ Elf32_Addr r_offset; /* offset of relocation */
+ Elf32_Word r_info; /* symbol table index and type */
+ Elf32_Sword r_addend;
+} Elf32_Rela;
+
+/* Extract relocation info - r_info */
+#define ELF32_R_SYM(i) ((i) >> 8)
+#define ELF32_R_TYPE(i) ((unsigned char) (i))
+#define ELF32_R_INFO(s,t) (((s) << 8) + (unsigned char)(t))
+
+typedef struct {
+ Elf64_Addr r_offset; /* where to do it */
+ Elf64_Xword r_info; /* index & type of relocation */
+} Elf64_Rel;
+
+typedef struct {
+ Elf64_Addr r_offset; /* where to do it */
+ Elf64_Xword r_info; /* index & type of relocation */
+ Elf64_Sxword r_addend; /* adjustment value */
+} Elf64_Rela;
+
+#define ELF64_R_SYM(info) ((info) >> 32)
+#define ELF64_R_TYPE(info) ((info) & 0xFFFFFFFF)
+#define ELF64_R_INFO(s,t) (((s) << 32) + (__uint32_t)(t))
+
+#if defined(__mips64__) && defined(__MIPSEL__)
+/*
+ * The 64-bit MIPS ELF ABI uses a slightly different relocation format
+ * than the regular ELF ABI: the r_info field is split into several
+ * pieces (see gnu/usr.bin/binutils-2.17/include/elf/mips.h for details).
+ */
+#undef ELF64_R_SYM
+#undef ELF64_R_TYPE
+#undef ELF64_R_INFO
+#define ELF64_R_TYPE(info) ((__uint64_t)swap32((info) >> 32))
+#define ELF64_R_SYM(info) ((info) & 0xFFFFFFFF)
+#define ELF64_R_INFO(s,t) (((__uint64_t)swap32(t) << 32) + (__uint32_t)(s))
+#endif /* __mips64__ && __MIPSEL__ */
+
+/* Program Header */
+typedef struct {
+ Elf32_Word p_type; /* segment type */
+ Elf32_Off p_offset; /* segment offset */
+ Elf32_Addr p_vaddr; /* virtual address of segment */
+ Elf32_Addr p_paddr; /* physical address - ignored? */
+ Elf32_Word p_filesz; /* number of bytes in file for seg. */
+ Elf32_Word p_memsz; /* number of bytes in mem. for seg. */
+ Elf32_Word p_flags; /* flags */
+ Elf32_Word p_align; /* memory alignment */
+} Elf32_Phdr;
+
+typedef struct {
+ Elf64_Word p_type; /* entry type */
+ Elf64_Word p_flags; /* flags */
+ Elf64_Off p_offset; /* offset */
+ Elf64_Addr p_vaddr; /* virtual address */
+ Elf64_Addr p_paddr; /* physical address */
+ Elf64_Xword p_filesz; /* file size */
+ Elf64_Xword p_memsz; /* memory size */
+ Elf64_Xword p_align; /* memory & file alignment */
+} Elf64_Phdr;
+
+/* Segment types - p_type */
+#define PT_NULL 0 /* unused */
+#define PT_LOAD 1 /* loadable segment */
+#define PT_DYNAMIC 2 /* dynamic linking section */
+#define PT_INTERP 3 /* the RTLD */
+#define PT_NOTE 4 /* auxiliary information */
+#define PT_SHLIB 5 /* reserved - purpose undefined */
+#define PT_PHDR 6 /* program header */
+#define PT_TLS 7 /* thread local storage */
+#define PT_LOOS 0x60000000 /* reserved range for OS */
+#define PT_HIOS 0x6fffffff /* specific segment types */
+#define PT_LOPROC 0x70000000 /* reserved range for processor */
+#define PT_HIPROC 0x7fffffff /* specific segment types */
+
+#define PT_GNU_EH_FRAME 0x6474e550 /* Exception handling info */
+#define PT_GNU_RELRO 0x6474e552 /* Read-only after relocation */
+
+#define PT_OPENBSD_RANDOMIZE 0x65a3dbe6 /* fill with random data */
+#define PT_OPENBSD_WXNEEDED 0x65a3dbe7 /* program performs W^X violations */
+#define PT_OPENBSD_BOOTDATA 0x65a41be6 /* section for boot arguments */
+
+/* Segment flags - p_flags */
+#define PF_X 0x1 /* Executable */
+#define PF_W 0x2 /* Writable */
+#define PF_R 0x4 /* Readable */
+#define PF_MASKPROC 0xf0000000 /* reserved bits for processor */
+ /* specific segment flags */
+
+/* Dynamic structure */
+typedef struct {
+ Elf32_Sword d_tag; /* controls meaning of d_val */
+ union {
+ Elf32_Word d_val; /* Multiple meanings - see d_tag */
+ Elf32_Addr d_ptr; /* program virtual address */
+ } d_un;
+} Elf32_Dyn;
+
+typedef struct {
+ Elf64_Xword d_tag; /* controls meaning of d_val */
+ union {
+ Elf64_Addr d_ptr;
+ Elf64_Xword d_val;
+ } d_un;
+} Elf64_Dyn;
+
+/* Dynamic Array Tags - d_tag */
+#define DT_NULL 0 /* marks end of _DYNAMIC array */
+#define DT_NEEDED 1 /* string table offset of needed lib */
+#define DT_PLTRELSZ 2 /* size of relocation entries in PLT */
+#define DT_PLTGOT 3 /* address PLT/GOT */
+#define DT_HASH 4 /* address of symbol hash table */
+#define DT_STRTAB 5 /* address of string table */
+#define DT_SYMTAB 6 /* address of symbol table */
+#define DT_RELA 7 /* address of relocation table */
+#define DT_RELASZ 8 /* size of relocation table */
+#define DT_RELAENT 9 /* size of relocation entry */
+#define DT_STRSZ 10 /* size of string table */
+#define DT_SYMENT 11 /* size of symbol table entry */
+#define DT_INIT 12 /* address of initialization func. */
+#define DT_FINI 13 /* address of termination function */
+#define DT_SONAME 14 /* string table offset of shared obj */
+#define DT_RPATH 15 /* string table offset of library
+ search path */
+#define DT_SYMBOLIC 16 /* start sym search in shared obj. */
+#define DT_REL 17 /* address of rel. tbl. w addends */
+#define DT_RELSZ 18 /* size of DT_REL relocation table */
+#define DT_RELENT 19 /* size of DT_REL relocation entry */
+#define DT_PLTREL 20 /* PLT referenced relocation entry */
+#define DT_DEBUG 21 /* bugger */
+#define DT_TEXTREL 22 /* Allow rel. mod. to unwritable seg */
+#define DT_JMPREL 23 /* add. of PLT's relocation entries */
+#define DT_BIND_NOW 24 /* Bind now regardless of env setting */
+#define DT_INIT_ARRAY 25 /* address of array of init func */
+#define DT_FINI_ARRAY 26 /* address of array of term func */
+#define DT_INIT_ARRAYSZ 27 /* size of array of init func */
+#define DT_FINI_ARRAYSZ 28 /* size of array of term func */
+#define DT_RUNPATH 29 /* strtab offset of lib search path */
+#define DT_FLAGS 30 /* Set of DF_* flags */
+#define DT_ENCODING 31 /* further DT_* follow encoding rules */
+#define DT_PREINIT_ARRAY 32 /* address of array of preinit func */
+#define DT_PREINIT_ARRAYSZ 33 /* size of array of preinit func */
+#define DT_LOOS 0x6000000d /* reserved range for OS */
+#define DT_HIOS 0x6ffff000 /* specific dynamic array tags */
+#define DT_LOPROC 0x70000000 /* reserved range for processor */
+#define DT_HIPROC 0x7fffffff /* specific dynamic array tags */
+
+/* some other useful tags */
+#define DT_GNU_HASH 0x6ffffef5 /* address of GNU hash table */
+#define DT_RELACOUNT 0x6ffffff9 /* if present, number of RELATIVE */
+#define DT_RELCOUNT 0x6ffffffa /* relocs, which must come first */
+#define DT_FLAGS_1 0x6ffffffb
+
+/* Dynamic Flags - DT_FLAGS .dynamic entry */
+#define DF_ORIGIN 0x00000001
+#define DF_SYMBOLIC 0x00000002
+#define DF_TEXTREL 0x00000004
+#define DF_BIND_NOW 0x00000008
+#define DF_STATIC_TLS 0x00000010
+
+/* Dynamic Flags - DT_FLAGS_1 .dynamic entry */
+#define DF_1_NOW 0x00000001
+#define DF_1_GLOBAL 0x00000002
+#define DF_1_GROUP 0x00000004
+#define DF_1_NODELETE 0x00000008
+#define DF_1_LOADFLTR 0x00000010
+#define DF_1_INITFIRST 0x00000020
+#define DF_1_NOOPEN 0x00000040
+#define DF_1_ORIGIN 0x00000080
+#define DF_1_DIRECT 0x00000100
+#define DF_1_TRANS 0x00000200
+#define DF_1_INTERPOSE 0x00000400
+#define DF_1_NODEFLIB 0x00000800
+#define DF_1_NODUMP 0x00001000
+#define DF_1_CONLFAT 0x00002000
+
+/*
+ * Note header
+ */
+typedef struct {
+ Elf32_Word n_namesz;
+ Elf32_Word n_descsz;
+ Elf32_Word n_type;
+} Elf32_Nhdr;
+
+typedef struct {
+ Elf64_Word n_namesz;
+ Elf64_Word n_descsz;
+ Elf64_Word n_type;
+} Elf64_Nhdr;
+
+/*
+ * Note Definitions
+ */
+typedef struct {
+ Elf32_Word namesz;
+ Elf32_Word descsz;
+ Elf32_Word type;
+} Elf32_Note;
+
+typedef struct {
+ Elf64_Word namesz;
+ Elf64_Word descsz;
+ Elf64_Word type;
+} Elf64_Note;
+
+/* Values for n_type. */
+#define NT_PRSTATUS 1 /* Process status. */
+#define NT_FPREGSET 2 /* Floating point registers. */
+#define NT_PRPSINFO 3 /* Process state info. */
+
+/*
+ * OpenBSD-specific core file information.
+ *
+ * OpenBSD ELF core files use notes to provide information about
+ * the process's state. The note name is "OpenBSD" for information
+ * that is global to the process, and "OpenBSD@nn", where "nn" is the
+ * thread ID of the thread that the information belongs to (such as
+ * register state).
+ *
+ * We use the following note identifiers:
+ *
+ * NT_OPENBSD_PROCINFO
+ * Note is a "elfcore_procinfo" structure.
+ * NT_OPENBSD_AUXV
+ * Note is a a bunch of Auxilliary Vectors, terminated by
+ * an AT_NULL entry.
+ * NT_OPENBSD_REGS
+ * Note is a "reg" structure.
+ * NT_OPENBSD_FPREGS
+ * Note is a "fpreg" structure.
+ *
+ * Please try to keep the members of the "elfcore_procinfo" structure
+ * nicely aligned, and if you add elements, add them to the end and
+ * bump the version.
+ */
+
+#define NT_OPENBSD_PROCINFO 10
+#define NT_OPENBSD_AUXV 11
+
+#define NT_OPENBSD_REGS 20
+#define NT_OPENBSD_FPREGS 21
+#define NT_OPENBSD_XFPREGS 22
+#define NT_OPENBSD_WCOOKIE 23
+
+struct elfcore_procinfo {
+ /* Version 1 fields start here. */
+ uint32_t cpi_version; /* netbsd_elfcore_procinfo version */
+#define ELFCORE_PROCINFO_VERSION 1
+ uint32_t cpi_cpisize; /* sizeof(netbsd_elfcore_procinfo) */
+ uint32_t cpi_signo; /* killing signal */
+ uint32_t cpi_sigcode; /* signal code */
+ uint32_t cpi_sigpend; /* pending signals */
+ uint32_t cpi_sigmask; /* blocked signals */
+ uint32_t cpi_sigignore; /* ignored signals */
+ uint32_t cpi_sigcatch; /* signals being caught by user */
+ int32_t cpi_pid; /* process ID */
+ int32_t cpi_ppid; /* parent process ID */
+ int32_t cpi_pgrp; /* process group ID */
+ int32_t cpi_sid; /* session ID */
+ uint32_t cpi_ruid; /* real user ID */
+ uint32_t cpi_euid; /* effective user ID */
+ uint32_t cpi_svuid; /* saved user ID */
+ uint32_t cpi_rgid; /* real group ID */
+ uint32_t cpi_egid; /* effective group ID */
+ uint32_t cpi_svgid; /* saved group ID */
+ int8_t cpi_name[32]; /* copy of pr->ps_comm */
+};
+
+/*
+ * XXX - these _KERNEL items aren't part of the ABI!
+ */
+#if defined(_KERNEL) || defined(_DYN_LOADER)
+
+#define ELF32_NO_ADDR ((uint32_t) ~0) /* Indicates addr. not yet filled in */
+
+typedef struct {
+ Elf32_Sword au_id; /* 32-bit id */
+ Elf32_Word au_v; /* 32-bit value */
+} Aux32Info;
+
+#define ELF64_NO_ADDR ((__uint64_t) ~0)/* Indicates addr. not yet filled in */
+
+typedef struct {
+ Elf64_Shalf au_id; /* 32-bit id */
+ Elf64_Xword au_v; /* 64-bit value */
+} Aux64Info;
+
+enum AuxID {
+ AUX_null = 0,
+ AUX_ignore = 1,
+ AUX_execfd = 2,
+ AUX_phdr = 3, /* &phdr[0] */
+ AUX_phent = 4, /* sizeof(phdr[0]) */
+ AUX_phnum = 5, /* # phdr entries */
+ AUX_pagesz = 6, /* PAGESIZE */
+ AUX_base = 7, /* ld.so base addr */
+ AUX_flags = 8, /* processor flags */
+ AUX_entry = 9, /* a.out entry */
+ AUX_sun_uid = 2000, /* euid */
+ AUX_sun_ruid = 2001, /* ruid */
+ AUX_sun_gid = 2002, /* egid */
+ AUX_sun_rgid = 2003 /* rgid */
+};
+
+struct elf_args {
+ u_long arg_entry; /* program entry point */
+ u_long arg_interp; /* Interpreter load address */
+ u_long arg_phaddr; /* program header address */
+ u_long arg_phentsize; /* Size of program header */
+ u_long arg_phnum; /* Number of program headers */
+};
+
+#endif
+
+#if !defined(ELFSIZE) && defined(ARCH_ELFSIZE)
+#define ELFSIZE ARCH_ELFSIZE
+#endif
+
+#if defined(ELFSIZE)
+#define CONCAT(x,y) __CONCAT(x,y)
+#define ELFNAME(x) CONCAT(elf,CONCAT(ELFSIZE,CONCAT(_,x)))
+#define ELFDEFNNAME(x) CONCAT(ELF,CONCAT(ELFSIZE,CONCAT(_,x)))
+#endif
+
+#if defined(ELFSIZE) && (ELFSIZE == 32)
+#define Elf_Ehdr Elf32_Ehdr
+#define Elf_Phdr Elf32_Phdr
+#define Elf_Shdr Elf32_Shdr
+#define Elf_Sym Elf32_Sym
+#define Elf_Rel Elf32_Rel
+#define Elf_RelA Elf32_Rela
+#define Elf_Dyn Elf32_Dyn
+#define Elf_Half Elf32_Half
+#define Elf_Word Elf32_Word
+#define Elf_Sword Elf32_Sword
+#define Elf_Addr Elf32_Addr
+#define Elf_Off Elf32_Off
+#define Elf_Nhdr Elf32_Nhdr
+#define Elf_Note Elf32_Note
+
+#define ELF_R_SYM ELF32_R_SYM
+#define ELF_R_TYPE ELF32_R_TYPE
+#define ELF_R_INFO ELF32_R_INFO
+#define ELFCLASS ELFCLASS32
+
+#define ELF_ST_BIND ELF32_ST_BIND
+#define ELF_ST_TYPE ELF32_ST_TYPE
+#define ELF_ST_INFO ELF32_ST_INFO
+
+#define ELF_NO_ADDR ELF32_NO_ADDR
+#define AuxInfo Aux32Info
+#elif defined(ELFSIZE) && (ELFSIZE == 64)
+#define Elf_Ehdr Elf64_Ehdr
+#define Elf_Phdr Elf64_Phdr
+#define Elf_Shdr Elf64_Shdr
+#define Elf_Sym Elf64_Sym
+#define Elf_Rel Elf64_Rel
+#define Elf_RelA Elf64_Rela
+#define Elf_Dyn Elf64_Dyn
+#define Elf_Half Elf64_Half
+#define Elf_Word Elf64_Word
+#define Elf_Sword Elf64_Sword
+#define Elf_Addr Elf64_Addr
+#define Elf_Off Elf64_Off
+#define Elf_Nhdr Elf64_Nhdr
+#define Elf_Note Elf64_Note
+
+#define ELF_R_SYM ELF64_R_SYM
+#define ELF_R_TYPE ELF64_R_TYPE
+#define ELF_R_INFO ELF64_R_INFO
+#define ELFCLASS ELFCLASS64
+
+#define ELF_ST_BIND ELF64_ST_BIND
+#define ELF_ST_TYPE ELF64_ST_TYPE
+#define ELF_ST_INFO ELF64_ST_INFO
+
+#define ELF_NO_ADDR ELF64_NO_ADDR
+#define AuxInfo Aux64Info
+#endif
+
+#ifndef _KERNEL
+extern Elf_Dyn _DYNAMIC[];
+#endif
+
+#ifdef _KERNEL
+struct exec_package;
+
+int exec_elf_makecmds(struct proc *, struct exec_package *);
+#endif /* _KERNEL */
+
+#define ELF_TARG_VER 1 /* The ver for which this code is intended */
+
+#endif /* _SYS_EXEC_ELF_H_ */
diff --git a/sys/sys/exec_script.h b/sys/sys/exec_script.h
new file mode 100644
index 0000000..4f099a5
--- /dev/null
+++ b/sys/sys/exec_script.h
@@ -0,0 +1,43 @@
+/* $OpenBSD: exec_script.h,v 1.6 2018/02/07 20:31:57 tedu Exp $ */
+/* $NetBSD: exec_script.h,v 1.6 1995/03/26 20:24:11 jtc Exp $ */
+
+/*
+ * Copyright (c) 1994 Christopher G. Demetriou
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Christopher G. Demetriou.
+ * 4. 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.
+ */
+
+#define EXEC_SCRIPT_MAGIC "#!"
+#define EXEC_SCRIPT_MAGICLEN 2
+#define EXEC_SCRIPT_HDRSZ (EXEC_SCRIPT_MAGICLEN + 1 + MAXINTERP + 1)
+
+#ifdef _KERNEL
+
+/* the shell script handler's entry in the exec switch */
+int exec_script_makecmds(struct proc *, struct exec_package *);
+
+#endif /* _KERNEL */
diff --git a/sys/sys/extent.h b/sys/sys/extent.h
new file mode 100644
index 0000000..21be296
--- /dev/null
+++ b/sys/sys/extent.h
@@ -0,0 +1,130 @@
+/* $OpenBSD: extent.h,v 1.14 2014/02/08 20:29:01 kettenis Exp $ */
+/* $NetBSD: extent.h,v 1.6 1997/10/09 07:43:05 jtc Exp $ */
+
+/*-
+ * Copyright (c) 1996 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * 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.
+ */
+
+#ifndef _SYS_EXTENT_H_
+#define _SYS_EXTENT_H_
+
+#include <sys/queue.h>
+
+struct extent_region {
+ LIST_ENTRY(extent_region) er_link; /* link in region list */
+ u_long er_start; /* start of region */
+ u_long er_end; /* end of region */
+ int er_flags; /* misc. flags */
+};
+
+/* er_flags */
+#define ER_ALLOC 0x01 /* region descriptor dynamically allocated */
+#define ER_DISCARD 0x02 /* discard region descriptor after use */
+
+struct extent {
+ char *ex_name; /* name of extent */
+ /* allocated regions in extent */
+ LIST_HEAD(, extent_region) ex_regions;
+ u_long ex_start; /* start of extent */
+ u_long ex_end; /* end of extent */
+ int ex_mtype; /* memory type */
+ int ex_flags; /* misc. information */
+
+ LIST_ENTRY(extent) ex_link;
+};
+
+struct extent_fixed {
+ struct extent fex_extent; /* MUST BE FIRST */
+ /* freelist of region descriptors */
+ LIST_HEAD(, extent_region) fex_freelist;
+ caddr_t fex_storage; /* storage space for descriptors */
+ size_t fex_storagesize; /* size of storage space */
+};
+
+/* ex_flags; for internal use only */
+#define EXF_FIXED 0x01 /* extent uses fixed storage */
+#define EXF_NOCOALESCE 0x02 /* coalescing of regions not allowed */
+#define EXF_WANTED 0x04 /* someone asleep on extent */
+#define EXF_FLWANTED 0x08 /* someone asleep on freelist */
+
+#define EXF_BITS "\20\4FLWANTED\3WANTED\2NOCOALESCE\1FIXED"
+
+/* misc. flags passed to extent functions */
+#define EX_NOWAIT 0x0000 /* not safe to sleep */
+#define EX_WAITOK 0x0001 /* safe to sleep */
+#define EX_FAST 0x0002 /* take first fit in extent_alloc() */
+#define EX_CATCH 0x0004 /* catch signals while sleeping */
+#define EX_NOCOALESCE 0x0008 /* create a non-coalescing extent */
+#define EX_MALLOCOK 0x0010 /* safe to call malloc() */
+#define EX_WAITSPACE 0x0020 /* wait for space to become free */
+#define EX_BOUNDZERO 0x0040 /* boundary lines start at 0 */
+#define EX_CONFLICTOK 0x0080 /* allow conflicts */
+#define EX_FILLED 0x0100 /* create a filled extent */
+
+/*
+ * Special place holders for "alignment" and "boundary" arguments,
+ * in the event the caller doesn't wish to use those features.
+ */
+#define EX_NOALIGN 1 /* don't do alignment */
+#define EX_NOBOUNDARY 0 /* don't do boundary checking */
+
+#if defined(_KERNEL) || defined(_EXTENT_TESTING)
+#define EXTENT_FIXED_STORAGE_SIZE(_nregions) \
+ (ALIGN(sizeof(struct extent_fixed)) + \
+ ((ALIGN(sizeof(struct extent_region))) * \
+ (_nregions)))
+
+void extent_print_all(void);
+
+struct extent *extent_create(char *, u_long, u_long, int,
+ caddr_t, size_t, int);
+void extent_destroy(struct extent *);
+int extent_alloc_subregion(struct extent *, u_long, u_long,
+ u_long, u_long, u_long, u_long, int, u_long *);
+int extent_alloc_subregion_with_descr(struct extent *, u_long, u_long,
+ u_long, u_long, u_long, u_long, int, struct extent_region *,
+ u_long *);
+int extent_alloc_region(struct extent *, u_long, u_long, int);
+int extent_free(struct extent *, u_long, u_long, int);
+void extent_print(struct extent *);
+
+/* Simple case of extent_alloc_subregion() */
+#define extent_alloc(_ex, _size, _alignment, _skew, _boundary, \
+ _flags, _result) \
+ extent_alloc_subregion((_ex), (_ex)->ex_start, (_ex)->ex_end, \
+ (_size), (_alignment), (_skew), (_boundary), (_flags), (_result))
+
+/* Simple case of extent_alloc_subregion_with_descr() */
+#define extent_alloc_with_descr(_ex, _size, _alignment, _skew, _boundary, \
+ _flags, _region, _result) \
+ extent_alloc_subregion_with_descr((_ex), (_ex)->ex_start, \
+ (_ex)->ex_end, (_size), (_alignment), (_skew), (_boundary), \
+ (_flags), (_region), (_result))
+#endif /* _KERNEL || _EXTENT_TESTING */
+
+#endif /* ! _SYS_EXTENT_H_ */
diff --git a/sys/sys/fcntl.h b/sys/sys/fcntl.h
new file mode 100644
index 0000000..e964ea4
--- /dev/null
+++ b/sys/sys/fcntl.h
@@ -0,0 +1,220 @@
+/* $OpenBSD: fcntl.h,v 1.22 2019/01/21 18:09:21 anton Exp $ */
+/* $NetBSD: fcntl.h,v 1.8 1995/03/26 20:24:12 jtc Exp $ */
+
+/*-
+ * Copyright (c) 1983, 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)fcntl.h 8.3 (Berkeley) 1/21/94
+ */
+
+#ifndef _SYS_FCNTL_H_
+#define _SYS_FCNTL_H_
+
+/*
+ * This file includes the definitions for open and fcntl
+ * described by POSIX for <fcntl.h>; it also includes
+ * related kernel definitions.
+ */
+
+#include <sys/cdefs.h>
+#ifndef _KERNEL
+#include <sys/types.h>
+#endif
+
+/*
+ * File status flags: these are used by open(2), fcntl(2).
+ * They are also used (indirectly) in the kernel file structure f_flags,
+ * which is a superset of the open/fcntl flags. Open flags and f_flags
+ * are inter-convertible using OFLAGS(fflags) and FFLAGS(oflags).
+ * Open/fcntl flags begin with O_; kernel-internal flags begin with F.
+ */
+/* open-only flags */
+#define O_RDONLY 0x0000 /* open for reading only */
+#define O_WRONLY 0x0001 /* open for writing only */
+#define O_RDWR 0x0002 /* open for reading and writing */
+#define O_ACCMODE 0x0003 /* mask for above modes */
+
+/*
+ * Kernel encoding of open mode; separate read and write bits that are
+ * independently testable: 1 greater than the above.
+ *
+ * XXX
+ * FREAD and FWRITE are excluded from the #ifdef _KERNEL so that TIOCFLUSH,
+ * which was documented to use FREAD/FWRITE, continues to work.
+ */
+#if __BSD_VISIBLE
+#define FREAD 0x0001
+#define FWRITE 0x0002
+#endif
+#define O_NONBLOCK 0x0004 /* no delay */
+#define O_APPEND 0x0008 /* set append mode */
+#if __BSD_VISIBLE
+#define O_SHLOCK 0x0010 /* open with shared file lock */
+#define O_EXLOCK 0x0020 /* open with exclusive file lock */
+#define O_ASYNC 0x0040 /* signal pgrp when data ready */
+#define O_FSYNC 0x0080 /* backwards compatibility */
+#define O_NOFOLLOW 0x0100 /* if path is a symlink, don't follow */
+#endif
+#if __POSIX_VISIBLE >= 199309 || __XPG_VISIBLE >= 420
+#define O_SYNC 0x0080 /* synchronous writes */
+#endif
+#define O_CREAT 0x0200 /* create if nonexistent */
+#define O_TRUNC 0x0400 /* truncate to zero length */
+#define O_EXCL 0x0800 /* error if already exists */
+
+/*
+ * POSIX 1003.1 specifies a higher granularity for synchronous operations
+ * than we support. Since synchronicity is all or nothing in OpenBSD
+ * we just define these to be the same as O_SYNC.
+ */
+#define O_DSYNC O_SYNC /* synchronous data writes */
+#define O_RSYNC O_SYNC /* synchronous reads */
+
+/* defined by POSIX 1003.1; BSD default, this bit is not required */
+#define O_NOCTTY 0x8000 /* don't assign controlling terminal */
+
+/* defined by POSIX Issue 7 */
+#define O_CLOEXEC 0x10000 /* atomically set FD_CLOEXEC */
+#define O_DIRECTORY 0x20000 /* fail if not a directory */
+
+#ifdef _KERNEL
+/*
+ * convert from open() flags to/from fflags; convert O_RD/WR to FREAD/FWRITE.
+ * For out-of-range values for the flags, be slightly careful (but lossy).
+ */
+#define FFLAGS(oflags) (((oflags) & ~O_ACCMODE) | (((oflags) + 1) & O_ACCMODE))
+#define OFLAGS(fflags) (((fflags) & ~O_ACCMODE) | (((fflags) - 1) & O_ACCMODE))
+
+/* bits to save after open */
+#define FMASK (FREAD|FWRITE|FAPPEND|FASYNC|FFSYNC|FNONBLOCK)
+/* bits settable by fcntl(F_SETFL, ...) */
+#define FCNTLFLAGS (FAPPEND|FASYNC|FFSYNC|FNONBLOCK)
+#endif
+
+/*
+ * The O_* flags used to have only F* names, which were used in the kernel
+ * and by fcntl. We retain the F* names for the kernel f_flags field
+ * and for backward compatibility for fcntl.
+ */
+#if __BSD_VISIBLE
+#define FAPPEND O_APPEND /* kernel/compat */
+#define FASYNC O_ASYNC /* kernel/compat */
+#define FFSYNC O_SYNC /* kernel */
+#define FNONBLOCK O_NONBLOCK /* kernel */
+#define FNDELAY O_NONBLOCK /* compat */
+#define O_NDELAY O_NONBLOCK /* compat */
+#endif
+
+/*
+ * Constants used for fcntl(2)
+ */
+
+/* command values */
+#define F_DUPFD 0 /* duplicate file descriptor */
+#define F_GETFD 1 /* get file descriptor flags */
+#define F_SETFD 2 /* set file descriptor flags */
+#define F_GETFL 3 /* get file status flags */
+#define F_SETFL 4 /* set file status flags */
+#if __POSIX_VISIBLE >= 200112 || __XPG_VISIBLE >= 500
+#define F_GETOWN 5 /* get SIGIO/SIGURG proc/pgrp */
+#define F_SETOWN 6 /* set SIGIO/SIGURG proc/pgrp */
+#endif
+#define F_GETLK 7 /* get record locking information */
+#define F_SETLK 8 /* set record locking information */
+#define F_SETLKW 9 /* F_SETLK; wait if blocked */
+#if __POSIX_VISIBLE >= 200809
+#define F_DUPFD_CLOEXEC 10 /* duplicate with FD_CLOEXEC set */
+#endif
+#if __BSD_VISIBLE
+#define F_ISATTY 11 /* used by isatty(3) */
+#endif
+
+/* file descriptor flags (F_GETFD, F_SETFD) */
+#define FD_CLOEXEC 1 /* close-on-exec flag */
+
+/* record locking flags (F_GETLK, F_SETLK, F_SETLKW) */
+#define F_RDLCK 1 /* shared or read lock */
+#define F_UNLCK 2 /* unlock */
+#define F_WRLCK 3 /* exclusive or write lock */
+#ifdef _KERNEL
+#define F_WAIT 0x010 /* Wait until lock is granted */
+#define F_FLOCK 0x020 /* Use flock(2) semantics for lock */
+#define F_POSIX 0x040 /* Use POSIX semantics for lock */
+#define F_INTR 0x080 /* Lock operation interrupted */
+#endif
+
+/*
+ * Advisory file segment locking data type -
+ * information passed to system by user
+ */
+struct flock {
+ off_t l_start; /* starting offset */
+ off_t l_len; /* len = 0 means until end of file */
+ pid_t l_pid; /* lock owner */
+ short l_type; /* lock type: read/write, etc. */
+ short l_whence; /* type of l_start */
+};
+
+
+#if __BSD_VISIBLE
+/* lock operations for flock(2) */
+#define LOCK_SH 0x01 /* shared file lock */
+#define LOCK_EX 0x02 /* exclusive file lock */
+#define LOCK_NB 0x04 /* don't block when locking */
+#define LOCK_UN 0x08 /* unlock file */
+#endif
+
+#if __POSIX_VISIBLE >= 200809
+#define AT_FDCWD -100
+
+#define AT_EACCESS 0x01
+#define AT_SYMLINK_NOFOLLOW 0x02
+#define AT_SYMLINK_FOLLOW 0x04
+#define AT_REMOVEDIR 0x08
+#endif
+
+#ifndef _KERNEL
+__BEGIN_DECLS
+int open(const char *, int, ...);
+int creat(const char *, mode_t);
+int fcntl(int, int, ...);
+#if __BSD_VISIBLE
+int flock(int, int);
+#endif
+#if __POSIX_VISIBLE >= 200809
+int openat(int, const char *, int, ...);
+#endif
+__END_DECLS
+#endif
+
+#endif /* !_SYS_FCNTL_H_ */
diff --git a/sys/sys/file.h b/sys/sys/file.h
new file mode 100644
index 0000000..f638c15
--- /dev/null
+++ b/sys/sys/file.h
@@ -0,0 +1,136 @@
+/* $OpenBSD: file.h,v 1.61 2020/03/13 10:07:01 anton Exp $ */
+/* $NetBSD: file.h,v 1.11 1995/03/26 20:24:13 jtc Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 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.
+ * 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.
+ *
+ * @(#)file.h 8.2 (Berkeley) 8/20/94
+ */
+
+#ifndef _KERNEL
+#include <sys/fcntl.h>
+
+#else /* _KERNEL */
+#include <sys/queue.h>
+#include <sys/mutex.h>
+
+struct proc;
+struct uio;
+struct knote;
+struct stat;
+struct file;
+struct ucred;
+
+/**
+ * File operations.
+ * The following entries could be called without KERNEL_LOCK hold:
+ * - fo_read
+ * - fo_write
+ * - fo_close
+ */
+struct fileops {
+ int (*fo_read)(struct file *, struct uio *, int);
+ int (*fo_write)(struct file *, struct uio *, int);
+ int (*fo_ioctl)(struct file *, u_long, caddr_t, struct proc *);
+ int (*fo_poll)(struct file *, int, struct proc *);
+ int (*fo_kqfilter)(struct file *, struct knote *);
+ int (*fo_stat)(struct file *, struct stat *, struct proc *);
+ int (*fo_close)(struct file *, struct proc *);
+ int (*fo_seek)(struct file *, off_t *, int, struct proc *);
+};
+#define FO_POSITION 0x00000001 /* positioned read/write */
+
+/*
+ * Kernel descriptor table.
+ * One entry for each open kernel vnode and socket.
+ *
+ * Locks used to protect struct members in this file:
+ * I immutable after creation
+ * F global `fhdlk' mutex
+ * a atomic operations
+ * f per file `f_mtx'
+ * v vnode lock
+ */
+struct file {
+ LIST_ENTRY(file) f_list;/* [F] list of active files */
+ struct mutex f_mtx;
+ u_int f_flag; /* [a] see fcntl.h */
+#define DTYPE_VNODE 1 /* file */
+#define DTYPE_SOCKET 2 /* communications endpoint */
+#define DTYPE_PIPE 3 /* pipe */
+#define DTYPE_KQUEUE 4 /* event queue */
+#define DTYPE_DMABUF 5 /* DMA buffer (for DRM) */
+ u_int f_iflags; /* [a] internal flags */
+ int f_type; /* [I] descriptor type */
+ u_int f_count; /* [a] reference count */
+ struct ucred *f_cred; /* [I] credentials associated with descriptor */
+ const struct fileops *f_ops; /* [I] file operation pointers */
+ off_t f_offset; /* [f,v] offset */
+ void *f_data; /* [I] private data */
+ uint64_t f_rxfer; /* [f] total number of read transfers */
+ uint64_t f_wxfer; /* [f] total number of write transfers */
+ uint64_t f_seek; /* [f] total independent seek operations */
+ uint64_t f_rbytes; /* [f] total bytes read */
+ uint64_t f_wbytes; /* [f] total bytes written */
+};
+
+#define FIF_HASLOCK 0x01 /* descriptor holds advisory lock */
+#define FIF_INSERTED 0x80 /* present in `filehead' */
+
+#define FREF(fp) \
+ do { \
+ extern void vfs_stall_barrier(void); \
+ vfs_stall_barrier(); \
+ atomic_inc_int(&(fp)->f_count); \
+ } while (0)
+
+#define FRELE(fp,p) \
+ (atomic_dec_int_nv(&fp->f_count) == 0 ? fdrop(fp, p) : 0)
+
+#define FDUP_MAX_COUNT (UINT_MAX - 2 * MAXCPUS)
+
+int fdrop(struct file *, struct proc *);
+
+static inline off_t
+foffset(struct file *fp)
+{
+ off_t offset;
+
+ mtx_enter(&fp->f_mtx);
+ offset = fp->f_offset;
+ mtx_leave(&fp->f_mtx);
+ return (offset);
+}
+
+LIST_HEAD(filelist, file);
+extern int maxfiles; /* kernel limit on number of open files */
+extern int numfiles; /* actual number of open files */
+extern const struct fileops socketops; /* socket operations for files */
+extern const struct fileops vnops; /* vnode operations for files */
+
+#endif /* _KERNEL */
diff --git a/sys/sys/filedesc.h b/sys/sys/filedesc.h
new file mode 100644
index 0000000..ef784f7
--- /dev/null
+++ b/sys/sys/filedesc.h
@@ -0,0 +1,157 @@
+/* $OpenBSD: filedesc.h,v 1.44 2020/01/30 15:33:04 visa Exp $ */
+/* $NetBSD: filedesc.h,v 1.14 1996/04/09 20:55:28 cgd Exp $ */
+
+/*
+ * Copyright (c) 1990, 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.
+ *
+ * @(#)filedesc.h 8.1 (Berkeley) 6/2/93
+ */
+
+#include <sys/mutex.h>
+#include <sys/rwlock.h>
+/*
+ * This structure is used for the management of descriptors. It may be
+ * shared by multiple processes.
+ *
+ * A process is initially started out with NDFILE descriptors stored within
+ * this structure, selected to be enough for typical applications based on
+ * the historical limit of 20 open files (and the usage of descriptors by
+ * shells). If these descriptors are exhausted, a larger descriptor table
+ * may be allocated, up to a process' resource limit; the internal arrays
+ * are then unused. The initial expansion is set to NDEXTENT; each time
+ * it runs out, it is doubled until the resource limit is reached. NDEXTENT
+ * should be selected to be the biggest multiple of OFILESIZE (see below)
+ * that will fit in a power-of-two sized piece of memory.
+ */
+#define NDFILE 20
+#define NDEXTENT 50 /* 250 bytes in 256-byte alloc. */
+#define NDENTRIES 32 /* 32 fds per entry */
+#define NDENTRYMASK (NDENTRIES - 1)
+#define NDENTRYSHIFT 5 /* bits per entry */
+#define NDREDUCE(x) (((x) + NDENTRIES - 1) >> NDENTRYSHIFT)
+#define NDHISLOTS(x) (NDREDUCE(NDREDUCE(x)))
+#define NDLOSLOTS(x) (NDHISLOTS(x) << NDENTRYSHIFT)
+
+struct kqueue;
+
+/*
+ * Locking:
+ * a atomic operations
+ * f fd_lock
+ * f/w fd_lock when writing
+ * k kernel lock
+ * m fd_fplock
+ */
+struct filedesc {
+ struct file **fd_ofiles; /* [f/w,m] file structures for
+ * open files */
+ char *fd_ofileflags; /* [f] per-process open file flags */
+ struct vnode *fd_cdir; /* [k] current directory */
+ struct vnode *fd_rdir; /* [k] root directory */
+ int fd_nfiles; /* [f] number of open files allocated */
+ int fd_openfd; /* [f] number of files currently open */
+ u_int *fd_himap; /* [f] each bit points to 32 fds */
+ u_int *fd_lomap; /* [f] bitmap of free fds */
+ int fd_lastfile; /* [f] high-water mark of fd_ofiles */
+ int fd_freefile; /* [f] approx. next free file */
+ u_short fd_cmask; /* [f/w] mask for file creation */
+ u_short fd_refcnt; /* [k] reference count */
+ struct rwlock fd_lock; /* lock for the file descs */
+ struct mutex fd_fplock; /* lock for reading fd_ofiles without
+ * fd_lock */
+ LIST_HEAD(, kqueue) fd_kqlist; /* [f] kqueues attached to this
+ * filedesc */
+ int fd_flags; /* [a] flags on this filedesc */
+};
+
+/*
+ * Basic allocation of descriptors:
+ * one of the above, plus arrays for NDFILE descriptors.
+ */
+struct filedesc0 {
+ struct filedesc fd_fd;
+ /*
+ * These arrays are used when the number of open files is
+ * <= NDFILE, and are then pointed to by the pointers above.
+ */
+ struct file *fd_dfiles[NDFILE];
+ char fd_dfileflags[NDFILE];
+ /*
+ * There arrays are used when the number of open files is
+ * <= 1024, and are then pointed to by the pointers above.
+ */
+ u_int fd_dhimap[NDENTRIES >> NDENTRYSHIFT];
+ u_int fd_dlomap[NDENTRIES];
+};
+
+/*
+ * Per-process open flags.
+ */
+#define UF_EXCLOSE 0x01 /* auto-close on exec */
+#define UF_PLEDGED 0x02 /* open after pledge(2) */
+
+/*
+ * Flags on the file descriptor table.
+ */
+#define FD_ADVLOCK 0x01 /* May hold a POSIX adv. lock. */
+
+/*
+ * Storage required per open file descriptor.
+ */
+#define OFILESIZE (sizeof(struct file *) + sizeof(char))
+
+#ifdef _KERNEL
+/*
+ * Kernel global variables and routines.
+ */
+void filedesc_init(void);
+int dupfdopen(struct proc *, int, int);
+int fdalloc(struct proc *p, int want, int *result);
+void fdexpand(struct proc *);
+struct file *fnew(struct proc *_p);
+int falloc(struct proc *_p, struct file **_rfp, int *_rfd);
+struct filedesc *fdinit(void);
+struct filedesc *fdshare(struct process *);
+struct filedesc *fdcopy(struct process *);
+void fdfree(struct proc *p);
+int fdrelease(struct proc *p, int);
+void fdinsert(struct filedesc *, int, int, struct file *);
+void fdremove(struct filedesc *, int);
+void fdcloseexec(struct proc *);
+struct file *fd_iterfile(struct file *, struct proc *);
+struct file *fd_getfile(struct filedesc *, int);
+struct file *fd_getfile_mode(struct filedesc *, int, int);
+int fd_checkclosed(struct filedesc *, int, struct file *);
+
+int closef(struct file *, struct proc *);
+int getsock(struct proc *, int, struct file **);
+
+#define fdplock(fdp) do { NET_ASSERT_UNLOCKED(); rw_enter_write(&(fdp)->fd_lock); } while (0)
+#define fdpunlock(fdp) rw_exit_write(&(fdp)->fd_lock)
+#define fdpassertlocked(fdp) rw_assert_wrlock(&(fdp)->fd_lock)
+#endif
diff --git a/sys/sys/filio.h b/sys/sys/filio.h
new file mode 100644
index 0000000..19fd805
--- /dev/null
+++ b/sys/sys/filio.h
@@ -0,0 +1,54 @@
+/* $OpenBSD: filio.h,v 1.5 2007/06/01 22:30:48 deraadt Exp $ */
+/* $NetBSD: filio.h,v 1.5 1994/06/29 06:44:14 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1982, 1986, 1990, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)filio.h 8.1 (Berkeley) 3/28/94
+ */
+
+#ifndef _SYS_FILIO_H_
+#define _SYS_FILIO_H_
+
+#include <sys/ioccom.h>
+
+/* Generic file-descriptor ioctl's. */
+#define FIOCLEX _IO('f', 1) /* set close on exec on fd */
+#define FIONCLEX _IO('f', 2) /* remove close on exec */
+#define FIONREAD _IOR('f', 127, int) /* get # bytes to read */
+#define FIONBIO _IOW('f', 126, int) /* set/clear non-blocking i/o */
+#define FIOASYNC _IOW('f', 125, int) /* set/clear async i/o */
+#define FIOSETOWN _IOW('f', 124, int) /* set owner */
+#define FIOGETOWN _IOR('f', 123, int) /* get owner */
+
+#endif /* !_SYS_FILIO_H_ */
diff --git a/sys/sys/fusebuf.h b/sys/sys/fusebuf.h
new file mode 100644
index 0000000..8706605
--- /dev/null
+++ b/sys/sys/fusebuf.h
@@ -0,0 +1,148 @@
+/* $OpenBSD: fusebuf.h,v 1.13 2018/06/19 11:27:54 helg Exp $ */
+/*
+ * Copyright (c) 2013 Sylvestre Gallon
+ * Copyright (c) 2013 Martin Pieuchot
+ *
+ * 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.
+ */
+
+#ifndef _SYS_FUSEBUF_H_
+#define _SYS_FUSEBUF_H_
+
+/*
+ * Fusebufs are of a single size, 4096 bytes.
+ */
+#define FUSEBUFSIZE (sizeof(struct fusebuf))
+#define FUSEBUFMAXSIZE (4096*1024)
+
+/* header at beginning of each fusebuf: */
+struct fb_hdr {
+ SIMPLEQ_ENTRY(fusebuf) fh_next; /* next buffer in chain */
+ size_t fh_len; /* Amount of data */
+ int fh_err; /* errno to pass back */
+ int fh_type; /* type of data */
+ ino_t fh_ino; /* Inode of this fusebuf */
+ uint64_t fh_uuid; /* Uuid to track the answer */
+ pid_t fh_tid; /* calling proc thread id */
+ uid_t fh_uid; /* calling proc uid */
+ gid_t fh_gid; /* calling proc gid */
+ mode_t fh_umask; /* calling proc umask */
+};
+
+/* header for fuse file operations (like read/write/mkdir): */
+struct fb_io {
+ uint64_t fi_fd; /* fd where the io is performed */
+ ino_t fi_ino; /* ino for the io */
+ off_t fi_off; /* offset for the io */
+ size_t fi_len; /* Length of data */
+ mode_t fi_mode; /* mode for fd */
+ uint32_t fi_flags; /* flags on transfer */
+ dev_t fi_rdev; /* dev for mknod */
+};
+
+/*
+ * An operation is issued by the kernel through fuse(4) when the
+ * userland file system needs to execute an action (mkdir(2),
+ * link(2), etc).
+ *
+ * F_databuf can be superior to FUSELEN for fusefs_read, fusefs_writes and
+ * fusefs_readdir. If it is the case the transfer will be split in N
+ * fusebuf with a changing offset in FD_io.
+ *
+ * When the userland file system answers to this operation it uses
+ * the same ID (fh_uuid).
+ */
+struct fusebuf {
+ struct fb_hdr fb_hdr;
+ union {
+ struct statvfs FD_stat; /* vfs statfs */
+ struct stat FD_attr; /* for attr vnops */
+ struct fb_io FD_io; /* for file io vnops */
+ } FD;
+ uint8_t *fb_dat; /* data's */
+};
+
+#define fb_next fb_hdr.fh_next
+#define fb_len fb_hdr.fh_len
+#define fb_err fb_hdr.fh_err
+#define fb_type fb_hdr.fh_type
+#define fb_ino fb_hdr.fh_ino
+#define fb_uuid fb_hdr.fh_uuid
+#define fb_tid fb_hdr.fh_tid
+#define fb_uid fb_hdr.fh_uid
+#define fb_gid fb_hdr.fh_gid
+#define fb_umask fb_hdr.fh_umask
+
+#define fb_stat FD.FD_stat
+#define fb_attr FD.FD_attr
+#define fb_io_fd FD.FD_io.fi_fd
+#define fb_io_ino FD.FD_io.fi_ino
+#define fb_io_off FD.FD_io.fi_off
+#define fb_io_len FD.FD_io.fi_len
+#define fb_io_mode FD.FD_io.fi_mode
+#define fb_io_flags FD.FD_io.fi_flags
+#define fb_io_rdev FD.FD_io.fi_rdev
+
+/*
+ * Macros for type conversion
+ * fbtod(fb,t) - convert fusebuf pointer to data pointer of correct
+ * type
+ */
+#define fbtod(fb,t) ((t)((fb)->fb_dat))
+
+/* flags needed by setattr */
+#define FUSE_FATTR_MODE (1 << 0)
+#define FUSE_FATTR_UID (1 << 1)
+#define FUSE_FATTR_GID (1 << 2)
+#define FUSE_FATTR_SIZE (1 << 3)
+#define FUSE_FATTR_ATIME (1 << 4)
+#define FUSE_FATTR_MTIME (1 << 5)
+#define FUSE_FATTR_FH (1 << 6)
+
+/* fusebuf types */
+#define FBT_LOOKUP 0
+#define FBT_GETATTR 1
+#define FBT_SETATTR 2
+#define FBT_READLINK 3
+#define FBT_SYMLINK 4
+#define FBT_MKNOD 5
+#define FBT_MKDIR 6
+#define FBT_UNLINK 7
+#define FBT_RMDIR 8
+#define FBT_RENAME 9
+#define FBT_LINK 10
+#define FBT_OPEN 11
+#define FBT_READ 12
+#define FBT_WRITE 13
+#define FBT_STATFS 14
+#define FBT_RELEASE 16
+#define FBT_FSYNC 17
+#define FBT_FLUSH 18
+#define FBT_INIT 19
+#define FBT_OPENDIR 20
+#define FBT_READDIR 21
+#define FBT_RELEASEDIR 22
+#define FBT_FSYNCDIR 23
+#define FBT_ACCESS 24
+#define FBT_DESTROY 26
+#define FBT_RECLAIM 27
+
+#ifdef _KERNEL
+
+/* fusebuf prototypes */
+struct fusebuf *fb_setup(size_t, ino_t, int, struct proc *);
+int fb_queue(dev_t, struct fusebuf *);
+void fb_delete(struct fusebuf *);
+
+#endif /* _KERNEL */
+#endif /* _SYS_FUSEBUF_H_ */
diff --git a/sys/sys/futex.h b/sys/sys/futex.h
new file mode 100644
index 0000000..62e32c9
--- /dev/null
+++ b/sys/sys/futex.h
@@ -0,0 +1,41 @@
+/* $OpenBSD: futex.h,v 1.2 2018/06/03 15:09:26 kettenis Exp $ */
+
+/*
+ * Copyright (c) 2016 Martin Pieuchot
+ *
+ * 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.
+ */
+
+#ifndef _SYS_FUTEX_H_
+#define _SYS_FUTEX_H_
+
+#ifndef _KERNEL
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+int futex(volatile uint32_t *, int, int, const struct timespec *,
+ volatile uint32_t *);
+__END_DECLS
+#endif /* ! _KERNEL */
+
+#define FUTEX_WAIT 1
+#define FUTEX_WAKE 2
+#define FUTEX_REQUEUE 3
+
+#define FUTEX_PRIVATE_FLAG 128
+
+#define FUTEX_WAIT_PRIVATE (FUTEX_WAIT | FUTEX_PRIVATE_FLAG)
+#define FUTEX_WAKE_PRIVATE (FUTEX_WAKE | FUTEX_PRIVATE_FLAG)
+#define FUTEX_REQUEUE_PRIVATE (FUTEX_REQUEUE | FUTEX_PRIVATE_FLAG)
+
+#endif /* _SYS_FUTEX_H_ */
diff --git a/sys/sys/gmon.h b/sys/sys/gmon.h
new file mode 100644
index 0000000..1a63cb5
--- /dev/null
+++ b/sys/sys/gmon.h
@@ -0,0 +1,175 @@
+/* $OpenBSD: gmon.h,v 1.8 2016/05/07 19:30:52 guenther Exp $ */
+/* $NetBSD: gmon.h,v 1.5 1996/04/09 20:55:30 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1982, 1986, 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.
+ *
+ * @(#)gmon.h 8.2 (Berkeley) 1/4/94
+ */
+
+#ifndef _SYS_GMON_H_
+#define _SYS_GMON_H_
+
+#include <machine/profile.h>
+
+/*
+ * Structure prepended to gmon.out profiling data file.
+ */
+struct gmonhdr {
+ u_long lpc; /* base pc address of sample buffer */
+ u_long hpc; /* max pc address of sampled buffer */
+ int ncnt; /* size of sample buffer (plus this header) */
+ int version; /* version number */
+ int profrate; /* profiling clock rate */
+ int spare[3]; /* reserved */
+};
+#define GMONVERSION 0x00051879
+
+/*
+ * histogram counters are unsigned shorts (according to the kernel).
+ */
+#define HISTCOUNTER unsigned short
+
+/*
+ * fraction of text space to allocate for histogram counters here, 1/2
+ */
+#define HISTFRACTION 2
+
+/*
+ * Fraction of text space to allocate for from hash buckets.
+ * The value of HASHFRACTION is based on the minimum number of bytes
+ * of separation between two subroutine call points in the object code.
+ * Given MIN_SUBR_SEPARATION bytes of separation the value of
+ * HASHFRACTION is calculated as:
+ *
+ * HASHFRACTION = MIN_SUBR_SEPARATION / (2 * sizeof(short) - 1);
+ *
+ * For example, on the VAX, the shortest two call sequence is:
+ *
+ * calls $0,(r0)
+ * calls $0,(r0)
+ *
+ * which is separated by only three bytes, thus HASHFRACTION is
+ * calculated as:
+ *
+ * HASHFRACTION = 3 / (2 * 2 - 1) = 1
+ *
+ * Note that the division above rounds down, thus if MIN_SUBR_FRACTION
+ * is less than three, this algorithm will not work!
+ *
+ * In practice, however, call instructions are rarely at a minimal
+ * distance. Hence, we will define HASHFRACTION to be 2 across all
+ * architectures. This saves a reasonable amount of space for
+ * profiling data structures without (in practice) sacrificing
+ * any granularity.
+ */
+#define HASHFRACTION 2
+
+/*
+ * percent of text space to allocate for tostructs with a minimum.
+ */
+#define ARCDENSITY 2
+#define MINARCS 50
+#define MAXARCS ((1 << (8 * sizeof(HISTCOUNTER))) - 2)
+
+struct tostruct {
+ u_long selfpc;
+ long count;
+ u_short link;
+ u_short pad;
+};
+
+/*
+ * a raw arc, with pointers to the calling site and
+ * the called site and a count.
+ */
+struct rawarc {
+ u_long raw_frompc;
+ u_long raw_selfpc;
+ long raw_count;
+};
+
+/*
+ * general rounding functions.
+ */
+#define ROUNDDOWN(x,y) (((x)/(y))*(y))
+#define ROUNDUP(x,y) ((((x)+(y)-1)/(y))*(y))
+
+/*
+ * The profiling data structures are housed in this structure.
+ */
+struct gmonparam {
+ int state;
+ u_short *kcount;
+ u_long kcountsize;
+ u_short *froms;
+ u_long fromssize;
+ struct tostruct *tos;
+ u_long tossize;
+ long tolimit;
+ u_long lowpc;
+ u_long highpc;
+ u_long textsize;
+ u_long hashfraction;
+};
+
+/*
+ * Possible states of profiling.
+ */
+#define GMON_PROF_ON 0
+#define GMON_PROF_BUSY 1
+#define GMON_PROF_ERROR 2
+#define GMON_PROF_OFF 3
+
+/*
+ * Sysctl definitions for extracting profiling information from the kernel.
+ */
+#define GPROF_STATE 0 /* int: profiling enabling variable */
+#define GPROF_COUNT 1 /* struct: profile tick count buffer */
+#define GPROF_FROMS 2 /* struct: from location hash bucket */
+#define GPROF_TOS 3 /* struct: destination/count structure */
+#define GPROF_GMONPARAM 4 /* struct: profiling parameters (see above) */
+
+#ifdef _KERNEL
+extern int gmoninit; /* Is the kernel ready for beeing profiled? */
+
+#else /* !_KERNEL */
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+extern struct gmonparam _gmonparam;
+void _mcleanup(void);
+void _monstartup(u_long, u_long);
+void moncontrol(int);
+void monstartup(u_long, u_long);
+__END_DECLS
+
+#endif /* !_KERNEL */
+
+#endif /* !_SYS_GMON_H_ */
diff --git a/sys/sys/gpio.h b/sys/sys/gpio.h
new file mode 100644
index 0000000..95ce9cd
--- /dev/null
+++ b/sys/sys/gpio.h
@@ -0,0 +1,80 @@
+/* $OpenBSD: gpio.h,v 1.8 2011/10/03 20:24:51 matthieu Exp $ */
+/*
+ * Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org>
+ *
+ * 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.
+ */
+
+#ifndef _SYS_GPIO_H_
+#define _SYS_GPIO_H_
+
+/* GPIO pin states */
+#define GPIO_PIN_LOW 0x00 /* low level (logical 0) */
+#define GPIO_PIN_HIGH 0x01 /* high level (logical 1) */
+
+/* Max name length of a pin */
+#define GPIOPINMAXNAME 64
+
+/* GPIO pin configuration flags */
+#define GPIO_PIN_INPUT 0x0001 /* input direction */
+#define GPIO_PIN_OUTPUT 0x0002 /* output direction */
+#define GPIO_PIN_INOUT 0x0004 /* bi-directional */
+#define GPIO_PIN_OPENDRAIN 0x0008 /* open-drain output */
+#define GPIO_PIN_PUSHPULL 0x0010 /* push-pull output */
+#define GPIO_PIN_TRISTATE 0x0020 /* output disabled */
+#define GPIO_PIN_PULLUP 0x0040 /* internal pull-up enabled */
+#define GPIO_PIN_PULLDOWN 0x0080 /* internal pull-down enabled */
+#define GPIO_PIN_INVIN 0x0100 /* invert input */
+#define GPIO_PIN_INVOUT 0x0200 /* invert output */
+#define GPIO_PIN_USER 0x0400 /* user != 0 can access */
+#define GPIO_PIN_SET 0x8000 /* set for securelevel access */
+
+/* GPIO controller description */
+struct gpio_info {
+ int gpio_npins; /* total number of pins available */
+};
+
+/* GPIO pin operation (read/write/toggle) */
+struct gpio_pin_op {
+ char gp_name[GPIOPINMAXNAME]; /* pin name */
+ int gp_pin; /* pin number */
+ int gp_value; /* value */
+};
+
+/* GPIO pin configuration */
+struct gpio_pin_set {
+ char gp_name[GPIOPINMAXNAME];
+ int gp_pin;
+ int gp_caps;
+ int gp_flags;
+ char gp_name2[GPIOPINMAXNAME]; /* new name */
+};
+
+/* Attach/detach device drivers that use GPIO pins */
+struct gpio_attach {
+ char ga_dvname[16]; /* device name */
+ int ga_offset; /* pin number */
+ u_int32_t ga_mask; /* binary mask */
+ u_int32_t ga_flags; /* flags */
+};
+
+#define GPIOINFO _IOR('G', 0, struct gpio_info)
+#define GPIOPINREAD _IOWR('G', 1, struct gpio_pin_op)
+#define GPIOPINWRITE _IOWR('G', 2, struct gpio_pin_op)
+#define GPIOPINTOGGLE _IOWR('G', 3, struct gpio_pin_op)
+#define GPIOPINSET _IOWR('G', 4, struct gpio_pin_set)
+#define GPIOPINUNSET _IOWR('G', 5, struct gpio_pin_set)
+#define GPIOATTACH _IOWR('G', 6, struct gpio_attach)
+#define GPIODETACH _IOWR('G', 7, struct gpio_attach)
+
+#endif /* !_SYS_GPIO_H_ */
diff --git a/sys/sys/hibernate.h b/sys/sys/hibernate.h
new file mode 100644
index 0000000..be09102
--- /dev/null
+++ b/sys/sys/hibernate.h
@@ -0,0 +1,159 @@
+/* $OpenBSD: hibernate.h,v 1.42 2018/06/21 07:33:30 mlarkin Exp $ */
+
+/*
+ * Copyright (c) 2011 Ariane van der Steldt <ariane@stack.nl>
+ *
+ * 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.
+ */
+
+#ifndef _SYS_HIBERNATE_H_
+#define _SYS_HIBERNATE_H_
+
+#include <sys/types.h>
+#include <sys/tree.h>
+#include <lib/libz/zlib.h>
+#include <machine/vmparam.h>
+
+#define HIBERNATE_CHUNK_USED 1
+#define HIBERNATE_CHUNK_CONFLICT 2
+#define HIBERNATE_CHUNK_PLACED 4
+
+/* Magic number used to indicate hibernate signature block */
+#define HIBERNATE_MAGIC 0x0B5D0B5D
+
+/* Page skip operations used during unpack */
+#define HIB_MOVE 2
+#define HIB_SKIP 1
+
+struct hiballoc_entry;
+
+/*
+ * Allocator operates from an arena, that is pre-allocated by the caller.
+ */
+struct hiballoc_arena {
+ RBT_HEAD(hiballoc_addr, hiballoc_entry) hib_addrs;
+};
+
+/*
+ * Describes a zlib compression stream and its associated hiballoc area
+ */
+struct hibernate_zlib_state {
+ z_stream hib_stream;
+ struct hiballoc_arena hiballoc_arena;
+};
+
+/*
+ * Describes a range of physical memory on the machine
+ */
+struct hibernate_memory_range {
+ paddr_t base;
+ paddr_t end;
+};
+
+/*
+ * Describes a hibernate chunk structure, used when splitting the memory
+ * image of the machine into easy-to-manage pieces.
+ */
+struct hibernate_disk_chunk {
+ paddr_t base; /* Base of chunk */
+ paddr_t end; /* End of chunk */
+ daddr_t offset; /* Abs. disk block locating chunk */
+ size_t compressed_size; /* Compressed size on disk */
+ short flags; /* Flags */
+};
+
+#define HIB_INIT -1
+#define HIB_DONE -2
+#define HIB_R 0
+#define HIB_W 1
+typedef int (*hibio_fn)(dev_t, daddr_t, vaddr_t, size_t, int, void *);
+
+/*
+ * Used to store information about the hibernation state of the machine,
+ * such as memory range count and extents, disk sector size, and various
+ * offsets where things are located on disk.
+ */
+union hibernate_info {
+ struct {
+ u_int32_t magic;
+ size_t nranges;
+ struct hibernate_memory_range ranges[VM_PHYSSEG_MAX];
+ size_t image_size;
+ size_t chunk_ctr;
+ dev_t dev;
+ daddr_t sig_offset;
+ daddr_t chunktable_offset;
+ daddr_t image_offset;
+ paddr_t piglet_pa;
+ vaddr_t piglet_va;
+ char kernel_version[128];
+ u_int32_t kernel_sum;
+ hibio_fn io_func;
+ void *io_page;
+#ifndef NO_PROPOLICE
+ long guard;
+#endif /* ! NO_PROPOLICE */
+ u_int32_t retguard_ofs;
+ };
+
+ /* XXX - remove restriction to have this union fit in a single block */
+ char pad[512]; /* Pad to 512 bytes */
+};
+
+void *hib_alloc(struct hiballoc_arena*, size_t);
+void hib_free(struct hiballoc_arena*, void*);
+int hiballoc_init(struct hiballoc_arena*, void*, size_t len);
+void uvm_pmr_zero_everything(void);
+void uvm_pmr_dirty_everything(void);
+int uvm_pmr_alloc_pig(paddr_t*, psize_t, paddr_t);
+int uvm_pmr_alloc_piglet(vaddr_t*, paddr_t*, vsize_t, paddr_t);
+void uvm_pmr_free_piglet(vaddr_t, vsize_t);
+int uvm_page_rle(paddr_t);
+void uvmpd_hibernate(void);
+
+hibio_fn get_hibernate_io_function(dev_t);
+int get_hibernate_info(union hibernate_info *, int);
+
+int hibernate_zlib_reset(union hibernate_info *, int);
+void *hibernate_zlib_alloc(void *, int, int);
+void hibernate_zlib_free(void *, void *);
+void hibernate_inflate_region(union hibernate_info *, paddr_t, paddr_t,
+ size_t);
+size_t hibernate_deflate(union hibernate_info *, paddr_t, size_t *);
+void hibernate_process_chunk(union hibernate_info *,
+ struct hibernate_disk_chunk *, paddr_t);
+int hibernate_inflate_page(int *);
+
+int hibernate_block_io(union hibernate_info *, daddr_t, size_t, vaddr_t, int);
+int hibernate_write_signature(union hibernate_info *);
+int hibernate_write_chunktable(union hibernate_info *);
+int hibernate_write_chunks(union hibernate_info *);
+int hibernate_clear_signature(void);
+int hibernate_compare_signature(union hibernate_info *,
+ union hibernate_info *);
+void hibernate_resume(void);
+int hibernate_suspend(void);
+int hibernate_read_image(union hibernate_info *);
+int hibernate_read_chunks(union hibernate_info *, paddr_t, paddr_t, size_t,
+ struct hibernate_disk_chunk *);
+void hibernate_unpack_image(union hibernate_info *);
+void hibernate_populate_resume_pt(union hibernate_info *, paddr_t, paddr_t);
+int hibernate_alloc(void);
+void hibernate_free(void);
+void hib_getentropy(char **, size_t *);
+
+void hibernate_sort_ranges(union hibernate_info *);
+void hibernate_suspend_bufcache(void);
+void hibernate_resume_bufcache(void);
+
+#endif /* _SYS_HIBERNATE_H_ */
diff --git a/sys/sys/hotplug.h b/sys/sys/hotplug.h
new file mode 100644
index 0000000..f2da3f6
--- /dev/null
+++ b/sys/sys/hotplug.h
@@ -0,0 +1,40 @@
+/* $OpenBSD: hotplug.h,v 1.5 2006/05/28 16:52:34 mk Exp $ */
+/*
+ * Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org>
+ *
+ * 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.
+ */
+
+#ifndef _SYS_HOTPLUG_H_
+#define _SYS_HOTPLUG_H_
+
+/*
+ * Public interface for enqueuing and dequeueing device
+ * attachment and detachment notifications.
+ */
+
+#define HOTPLUG_DEVAT 0x01 /* device attached */
+#define HOTPLUG_DEVDT 0x02 /* device detached */
+
+struct hotplug_event {
+ int he_type; /* event type */
+ enum devclass he_devclass; /* device class */
+ char he_devname[16]; /* device name */
+};
+
+#ifdef _KERNEL
+void hotplug_device_attach(enum devclass, char *);
+void hotplug_device_detach(enum devclass, char *);
+#endif
+
+#endif /* _SYS_HOTPLUG_H_ */
diff --git a/sys/sys/ioccom.h b/sys/sys/ioccom.h
new file mode 100644
index 0000000..936fc13
--- /dev/null
+++ b/sys/sys/ioccom.h
@@ -0,0 +1,68 @@
+/* $OpenBSD: ioccom.h,v 1.5 2013/03/22 21:22:05 deraadt Exp $ */
+/* $NetBSD: ioccom.h,v 1.4 1994/10/30 21:49:56 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1982, 1986, 1990, 1993, 1994
+ * 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.
+ *
+ * @(#)ioccom.h 8.2 (Berkeley) 3/28/94
+ */
+
+#ifndef _SYS_IOCCOM_H_
+#define _SYS_IOCCOM_H_
+
+/*
+ * Ioctl's have the command encoded in the lower word, and the size of
+ * any in or out parameters in the upper word. The high 3 bits of the
+ * upper word are used to encode the in/out status of the parameter.
+ */
+#define IOCPARM_MASK 0x1fff /* parameter length, at most 13 bits */
+#define IOCPARM_LEN(x) (((x) >> 16) & IOCPARM_MASK)
+#define IOCBASECMD(x) ((x) & ~(IOCPARM_MASK << 16))
+#define IOCGROUP(x) (((x) >> 8) & 0xff)
+
+#define IOCPARM_MAX PAGE_SIZE /* max size of ioctl args */
+ /* no parameters */
+#define IOC_VOID (unsigned long)0x20000000
+ /* copy parameters out */
+#define IOC_OUT (unsigned long)0x40000000
+ /* copy parameters in */
+#define IOC_IN (unsigned long)0x80000000
+ /* copy parameters in and out */
+#define IOC_INOUT (IOC_IN|IOC_OUT)
+ /* mask for IN/OUT/VOID */
+#define IOC_DIRMASK (unsigned long)0xe0000000
+
+#define _IOC(inout,group,num,len) \
+ (inout | ((len & IOCPARM_MASK) << 16) | ((group) << 8) | (num))
+#define _IO(g,n) _IOC(IOC_VOID, (g), (n), 0)
+#define _IOR(g,n,t) _IOC(IOC_OUT, (g), (n), sizeof(t))
+#define _IOW(g,n,t) _IOC(IOC_IN, (g), (n), sizeof(t))
+/* this should be _IORW, but stdio got there first */
+#define _IOWR(g,n,t) _IOC(IOC_INOUT, (g), (n), sizeof(t))
+
+#endif /* !_SYS_IOCCOM_H_ */
diff --git a/sys/sys/ioctl.h b/sys/sys/ioctl.h
new file mode 100644
index 0000000..eee6e34
--- /dev/null
+++ b/sys/sys/ioctl.h
@@ -0,0 +1,55 @@
+/* $OpenBSD: ioctl.h,v 1.17 2016/02/28 15:46:19 naddy Exp $ */
+/* $NetBSD: ioctl.h,v 1.20 1996/01/30 18:21:47 thorpej Exp $ */
+
+/*-
+ * Copyright (c) 1982, 1986, 1990, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)ioctl.h 8.6 (Berkeley) 3/28/94
+ */
+
+#ifndef _SYS_IOCTL_H_
+#define _SYS_IOCTL_H_
+
+#include <sys/ttycom.h>
+#include <sys/filio.h>
+#include <sys/sockio.h>
+
+#ifndef _KERNEL
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+int ioctl(int, unsigned long, ...);
+__END_DECLS
+#endif /* !_KERNEL */
+#endif /* !_SYS_IOCTL_H_ */
diff --git a/sys/sys/ipc.h b/sys/sys/ipc.h
new file mode 100644
index 0000000..d710de2
--- /dev/null
+++ b/sys/sys/ipc.h
@@ -0,0 +1,95 @@
+/* $OpenBSD: ipc.h,v 1.13 2014/11/15 21:42:50 guenther Exp $ */
+/* $NetBSD: ipc.h,v 1.15 1996/02/09 18:25:12 christos Exp $ */
+
+/*
+ * Copyright (c) 1988 University of Utah.
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * the Systems Programming Group of the University of Utah Computer
+ * Science Department.
+ *
+ * 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.
+ *
+ * @(#)ipc.h 8.3 (Berkeley) 1/21/94
+ */
+
+/*
+ * SVID compatible ipc.h file
+ */
+#ifndef _SYS_IPC_H_
+#define _SYS_IPC_H_
+
+#include <sys/types.h>
+
+struct ipc_perm {
+ uid_t cuid; /* creator user id */
+ gid_t cgid; /* creator group id */
+ uid_t uid; /* user id */
+ gid_t gid; /* group id */
+ mode_t mode; /* r/w permission */
+ unsigned short seq; /* sequence # (to generate unique msg/sem/shm id) */
+ key_t key; /* user specified msg/sem/shm key */
+};
+
+/* common mode bits */
+#define IPC_R 000400 /* read permission */
+#define IPC_W 000200 /* write/alter permission */
+#define IPC_M 010000 /* permission to change control info */
+
+/* SVID required constants (same values as system 5) */
+#define IPC_CREAT 001000 /* create entry if key does not exist */
+#define IPC_EXCL 002000 /* fail if key exists */
+#define IPC_NOWAIT 004000 /* error if request must wait */
+
+#define IPC_PRIVATE (key_t)0 /* private key */
+
+#define IPC_RMID 0 /* remove identifier */
+#define IPC_SET 1 /* set options */
+#define IPC_STAT 2 /* get options */
+
+#ifdef _KERNEL
+/* Macros to convert between ipc ids and array indices or sequence ids */
+#define IPCID_TO_IX(id) ((id) & 0xffff)
+#define IPCID_TO_SEQ(id) (((id) >> 16) & 0xffff)
+#define IXSEQ_TO_IPCID(ix,perm) (((perm.seq) << 16) | (ix & 0xffff))
+
+struct ucred;
+
+int ipcperm(struct ucred *, struct ipc_perm *, int);
+
+#else /* !_KERNEL */
+
+__BEGIN_DECLS
+key_t ftok(const char *, int);
+__END_DECLS
+#endif
+#endif /* !_SYS_IPC_H_ */
diff --git a/sys/sys/kcore.h b/sys/sys/kcore.h
new file mode 100644
index 0000000..4c5662b
--- /dev/null
+++ b/sys/sys/kcore.h
@@ -0,0 +1,65 @@
+/* $OpenBSD: kcore.h,v 1.1 1996/04/18 21:40:57 niklas Exp $ */
+/* $NetBSD: kcore.h,v 1.1 1996/03/10 21:56:00 leo Exp $ */
+
+/*
+ * Copyright (c) 1996 Leo Weppelman.
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Leo Weppelman.
+ * 4. 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.
+ */
+#ifndef _SYS_KCORE_H_
+#define _SYS_KCORE_H_
+
+/*
+ * Definitions for the kernel crash-dump format. The structure of
+ * the files and headers is borrowed from the 'regular' core files
+ * as described in <sys/core.h>.
+ */
+#define KCORE_MAGIC 0x8fca
+#define KCORESEG_MAGIC 0x8fac
+
+/*
+ * Description of a memory segment. To make this suitable for sharing
+ * between all architectures, u_quad_t seems to be the necessary type...
+ */
+typedef struct {
+ u_quad_t start; /* Physical start address */
+ u_quad_t size; /* Size in bytes */
+} phys_ram_seg_t;
+
+typedef struct kcore_hdr {
+ u_int32_t c_midmag; /* Magic, id, flags */
+ u_int16_t c_hdrsize; /* Aligned header size */
+ u_int16_t c_seghdrsize; /* Aligned seg-header size */
+ u_int32_t c_nseg; /* Number of segments */
+} kcore_hdr_t;
+
+typedef struct kcore_seg {
+ u_int32_t c_midmag; /* Magic, id, flags */
+ u_int32_t c_size; /* Sizeof this segment */
+} kcore_seg_t;
+
+#endif /* _SYS_KCORE_H_ */
diff --git a/sys/sys/kcov.h b/sys/sys/kcov.h
new file mode 100644
index 0000000..717a5e8
--- /dev/null
+++ b/sys/sys/kcov.h
@@ -0,0 +1,40 @@
+/* $OpenBSD: kcov.h,v 1.4 2019/01/20 09:57:23 anton Exp $ */
+
+/*
+ * Copyright (c) 2018 Anton Lindqvist <anton@openbsd.org>
+ *
+ * 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.
+ */
+
+#ifndef _SYS_KCOV_H_
+#define _SYS_KCOV_H_
+
+#include <sys/ioccom.h>
+
+#define KIOSETBUFSIZE _IOW('K', 1, unsigned long)
+#define KIOENABLE _IOW('K', 2, int)
+#define KIODISABLE _IO('K', 3)
+
+#define KCOV_MODE_NONE 0
+#define KCOV_MODE_TRACE_PC 1
+#define KCOV_MODE_TRACE_CMP 2
+
+#ifdef _KERNEL
+
+#define KCOV_BUF_MAX_NMEMB (256 << 10)
+
+void kcov_exit(struct proc *);
+
+#endif /* _KERNEL */
+
+#endif /* !_SYS_KCOV_H_ */
diff --git a/sys/sys/kernel.h b/sys/sys/kernel.h
new file mode 100644
index 0000000..f1c2aab
--- /dev/null
+++ b/sys/sys/kernel.h
@@ -0,0 +1,65 @@
+/* $OpenBSD: kernel.h,v 1.22 2019/09/07 01:23:23 cheloha Exp $ */
+/* $NetBSD: kernel.h,v 1.11 1995/03/03 01:24:16 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)kernel.h 8.3 (Berkeley) 1/21/94
+ */
+
+/* Global variables for the kernel. */
+
+/* 1.1 */
+extern long hostid;
+extern char hostname[MAXHOSTNAMELEN];
+extern int hostnamelen;
+extern char domainname[MAXHOSTNAMELEN];
+extern int domainnamelen;
+
+/* 1.2 */
+extern int utc_offset; /* seconds east of UTC */
+
+extern int tick; /* usec per tick (1000000 / hz) */
+extern int tick_nsec; /* nsec per tick */
+extern int tickfix; /* periodic tick adj. tick not integral */
+extern int tickfixinterval; /* interval at which to apply adjustment */
+extern int tickadj; /* "standard" clock skew, us./tick */
+extern int ticks; /* # of hardclock ticks */
+extern int hz; /* system clock's frequency */
+extern int stathz; /* statistics clock's frequency */
+extern int profhz; /* profiling clock's frequency */
+extern int lbolt; /* once a second sleep address */
+extern int tickdelta;
+extern long timedelta;
+
+extern struct bintime naptime; /* time spent suspended */
diff --git a/sys/sys/kthread.h b/sys/sys/kthread.h
new file mode 100644
index 0000000..b640045
--- /dev/null
+++ b/sys/sys/kthread.h
@@ -0,0 +1,50 @@
+/* $OpenBSD: kthread.h,v 1.7 2020/02/18 12:13:40 mpi Exp $ */
+/* $NetBSD: kthread.h,v 1.2 1998/11/14 00:08:49 thorpej Exp $ */
+
+/*-
+ * Copyright (c) 1998 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
+ * NASA Ames Research Center.
+ *
+ * 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.
+ */
+
+#ifndef _SYS_KTHREAD_H_
+#define _SYS_KTHREAD_H_
+
+/*
+ * Kernel thread handling.
+ */
+
+#ifdef _KERNEL
+struct proc;
+int kthread_create(void (*)(void *), void *, struct proc **,
+ const char *);
+void kthread_create_deferred(void (*)(void *), void *);
+void kthread_run_deferred_queue(void);
+void kthread_exit(int) __attribute__((__noreturn__));
+#endif /* _KERNEL */
+
+#endif /* _SYS_KTHREAD_H_ */
diff --git a/sys/sys/ktrace.h b/sys/sys/ktrace.h
new file mode 100644
index 0000000..c6a41cf
--- /dev/null
+++ b/sys/sys/ktrace.h
@@ -0,0 +1,254 @@
+/* $OpenBSD: ktrace.h,v 1.38 2019/02/26 22:24:41 deraadt Exp $ */
+/* $NetBSD: ktrace.h,v 1.12 1996/02/04 02:12:29 christos Exp $ */
+
+/*
+ * Copyright (c) 1988, 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.
+ *
+ * @(#)ktrace.h 8.1 (Berkeley) 6/2/93
+ */
+
+#include <sys/uio.h>
+
+/*
+ * operations to ktrace system call (KTROP(op))
+ */
+#define KTROP_SET 0 /* set trace points */
+#define KTROP_CLEAR 1 /* clear trace points */
+#define KTROP_CLEARFILE 2 /* stop all tracing to file */
+#define KTROP(o) ((o)&3) /* macro to extract operation */
+/*
+ * flags (ORed in with operation)
+ */
+#define KTRFLAG_DESCEND 4 /* perform op on all children too */
+
+/*
+ * ktrace record header
+ */
+struct ktr_header {
+ uint ktr_type; /* trace record type */
+ pid_t ktr_pid; /* process id */
+ pid_t ktr_tid; /* thread id */
+ struct timespec ktr_time; /* timestamp */
+ char ktr_comm[MAXCOMLEN+1]; /* command name */
+ size_t ktr_len; /* length of buf */
+};
+
+/*
+ * ktrace record types
+ */
+
+ /*
+ * KTR_START - start of trace record, one per ktrace(KTROP_SET) syscall
+ */
+#define KTR_START 0x4b545200 /* "KTR" */
+
+/*
+ * KTR_SYSCALL - system call record
+ */
+#define KTR_SYSCALL 1
+struct ktr_syscall {
+ int ktr_code; /* syscall number */
+ int ktr_argsize; /* size of arguments */
+ /*
+ * followed by ktr_argsize/sizeof(register_t) "register_t"s
+ */
+};
+
+/*
+ * KTR_SYSRET - return from system call record
+ */
+#define KTR_SYSRET 2
+struct ktr_sysret {
+ int ktr_code;
+ int ktr_error;
+ /*
+ * If ktr_error is zero, then followed by retval: register_t for
+ * all syscalls except lseek(), which uses long long
+ */
+};
+
+/*
+ * KTR_NAMEI - namei record
+ */
+#define KTR_NAMEI 3
+ /* record contains pathname */
+
+/*
+ * KTR_GENIO - trace generic process i/o
+ */
+#define KTR_GENIO 4
+struct ktr_genio {
+ int ktr_fd;
+ enum uio_rw ktr_rw;
+ /*
+ * followed by data successfully read/written
+ */
+};
+
+/*
+ * KTR_PSIG - trace processed signal
+ */
+#define KTR_PSIG 5
+struct ktr_psig {
+ int signo;
+ sig_t action;
+ int mask;
+ int code;
+ siginfo_t si;
+};
+
+/*
+ * KTR_STRUCT - misc. structs
+ */
+#define KTR_STRUCT 8
+ /*
+ * record contains null-terminated struct name followed by
+ * struct contents
+ */
+struct sockaddr;
+struct stat;
+
+/*
+ * KTR_USER - user record
+ */
+#define KTR_USER 9
+#define KTR_USER_MAXIDLEN 20
+#define KTR_USER_MAXLEN 2048 /* maximum length of passed data */
+struct ktr_user {
+ char ktr_id[KTR_USER_MAXIDLEN]; /* string id of caller */
+ /*
+ * Followed by ktr_len - sizeof(struct ktr_user) of user data.
+ */
+};
+
+/*
+ * KTR_EXECARGS and KTR_EXECENV - args and evironment records
+ */
+#define KTR_EXECARGS 10
+#define KTR_EXECENV 11
+
+
+/*
+ * KTR_PLEDGE - details of pledge violation
+ */
+#define KTR_PLEDGE 12
+struct ktr_pledge {
+ int error;
+ int syscall;
+ uint64_t code;
+};
+
+/*
+ * kernel trace points (in p_traceflag)
+ */
+#define KTRFAC_MASK 0x00ffffff
+#define KTRFAC_SYSCALL (1<<KTR_SYSCALL)
+#define KTRFAC_SYSRET (1<<KTR_SYSRET)
+#define KTRFAC_NAMEI (1<<KTR_NAMEI)
+#define KTRFAC_GENIO (1<<KTR_GENIO)
+#define KTRFAC_PSIG (1<<KTR_PSIG)
+#define KTRFAC_STRUCT (1<<KTR_STRUCT)
+#define KTRFAC_USER (1<<KTR_USER)
+#define KTRFAC_EXECARGS (1<<KTR_EXECARGS)
+#define KTRFAC_EXECENV (1<<KTR_EXECENV)
+#define KTRFAC_PLEDGE (1<<KTR_PLEDGE)
+
+/*
+ * trace flags (also in p_traceflags)
+ */
+#define KTRFAC_ROOT 0x80000000U /* root set this trace */
+#define KTRFAC_INHERIT 0x40000000 /* pass trace flags to children */
+
+#ifndef _KERNEL
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+int ktrace(const char *, int, int, pid_t);
+int utrace(const char *, const void *, size_t);
+__END_DECLS
+
+#else
+
+/*
+ * Test for kernel trace point
+ */
+#define KTRPOINT(p, type) \
+ ((p)->p_p->ps_traceflag & (1<<(type)) && ((p)->p_flag & P_INKTR) == 0)
+
+void ktrgenio(struct proc *, int, enum uio_rw, struct iovec *, ssize_t);
+void ktrnamei(struct proc *, char *);
+void ktrpsig(struct proc *, int, sig_t, int, int, siginfo_t *);
+void ktrsyscall(struct proc *, register_t, size_t, register_t []);
+void ktrsysret(struct proc *, register_t, int, const register_t [2]);
+int ktruser(struct proc *, const char *, const void *, size_t);
+void ktrexec(struct proc *, int, const char *, ssize_t);
+void ktrpledge(struct proc *, int, uint64_t, int);
+
+void ktrcleartrace(struct process *);
+void ktrsettrace(struct process *, int, struct vnode *, struct ucred *);
+
+void ktrstruct(struct proc *, const char *, const void *, size_t);
+#define ktrsockaddr(p, s, l) \
+ ktrstruct((p), "sockaddr", (s), (l))
+#define ktrstat(p, s) \
+ ktrstruct((p), "stat", (s), sizeof(struct stat))
+#define ktrabstimespec(p, s) \
+ ktrstruct((p), "abstimespec", (s), sizeof(struct timespec))
+#define ktrreltimespec(p, s) \
+ ktrstruct((p), "reltimespec", (s), sizeof(struct timespec))
+#define ktrabstimeval(p, s) \
+ ktrstruct((p), "abstimeval", (s), sizeof(struct timeval))
+#define ktrreltimeval(p, s) \
+ ktrstruct((p), "reltimeval", (s), sizeof(struct timeval))
+#define ktrsigaction(p, s) \
+ ktrstruct((p), "sigaction", (s), sizeof(struct sigaction))
+#define ktrrlimit(p, s) \
+ ktrstruct((p), "rlimit", (s), sizeof(struct rlimit))
+#define ktrrusage(p, s) \
+ ktrstruct((p), "rusage", (s), sizeof(struct rusage))
+#define ktrfdset(p, s, l) \
+ ktrstruct((p), "fdset", (s), l)
+#define ktrquota(p, s) \
+ ktrstruct((p), "quota", (s), sizeof(struct dqblk))
+#define ktrmsghdr(p, s) \
+ ktrstruct(p, "msghdr", s, sizeof(struct msghdr))
+#define ktriovec(p, s, count) \
+ ktrstruct(p, "iovec", s, (count) * sizeof(struct iovec))
+#define ktrcmsghdr(p, c, len) \
+ ktrstruct(p, "cmsghdr", c, len)
+#define ktrevent(p, kev, count) \
+ ktrstruct(p, "kevent", kev, (count) * sizeof(struct kevent))
+#define ktrpollfd(p, pfd, count) \
+ ktrstruct(p, "pollfd", pfd, (count) * sizeof(struct pollfd))
+#define ktrfds(p, fds, count) \
+ ktrstruct(p, "fds", fds, (count) * sizeof(int))
+#define ktrflock(p, fl) \
+ ktrstruct(p, "flock", (fl), sizeof(struct flock))
+
+#endif /* !_KERNEL */
diff --git a/sys/sys/limits.h b/sys/sys/limits.h
new file mode 100644
index 0000000..1faba69
--- /dev/null
+++ b/sys/sys/limits.h
@@ -0,0 +1,125 @@
+/* $OpenBSD: limits.h,v 1.10 2012/06/30 20:21:10 guenther Exp $ */
+/*
+ * Copyright (c) 2002 Marc Espie.
+ *
+ * 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 OPENBSD PROJECT 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 OPENBSD
+ * PROJECT 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 _SYS_LIMITS_H_
+#define _SYS_LIMITS_H_
+
+#include <sys/cdefs.h>
+
+/* Common definitions for limits.h. */
+
+/* Legacy */
+#include <machine/limits.h>
+
+#define CHAR_BIT 8 /* number of bits in a char */
+
+#define SCHAR_MAX 0x7f /* max value for a signed char */
+#define SCHAR_MIN (-0x7f-1) /* min value for a signed char */
+
+#define UCHAR_MAX 0xff /* max value for an unsigned char */
+#ifdef __CHAR_UNSIGNED__
+# define CHAR_MIN 0 /* min value for a char */
+# define CHAR_MAX 0xff /* max value for a char */
+#else
+# define CHAR_MAX 0x7f
+# define CHAR_MIN (-0x7f-1)
+#endif
+
+#define MB_LEN_MAX 4 /* Allow UTF-8 (RFC 3629) */
+
+#define USHRT_MAX 0xffff /* max value for an unsigned short */
+#define SHRT_MAX 0x7fff /* max value for a short */
+#define SHRT_MIN (-0x7fff-1) /* min value for a short */
+
+#define UINT_MAX 0xffffffffU /* max value for an unsigned int */
+#define INT_MAX 0x7fffffff /* max value for an int */
+#define INT_MIN (-0x7fffffff-1) /* min value for an int */
+
+#ifdef __LP64__
+# define ULONG_MAX 0xffffffffffffffffUL
+ /* max value for unsigned long */
+# define LONG_MAX 0x7fffffffffffffffL
+ /* max value for a signed long */
+# define LONG_MIN (-0x7fffffffffffffffL-1)
+ /* min value for a signed long */
+#else
+# define ULONG_MAX 0xffffffffUL /* max value for an unsigned long */
+# define LONG_MAX 0x7fffffffL /* max value for a long */
+# define LONG_MIN (-0x7fffffffL-1)/* min value for a long */
+#endif
+
+#if __BSD_VISIBLE || __ISO_C_VISIBLE >= 1999
+# define ULLONG_MAX 0xffffffffffffffffULL
+ /* max value for unsigned long long */
+# define LLONG_MAX 0x7fffffffffffffffLL
+ /* max value for a signed long long */
+# define LLONG_MIN (-0x7fffffffffffffffLL-1)
+ /* min value for a signed long long */
+#endif
+
+#if __BSD_VISIBLE
+# define UID_MAX UINT_MAX /* max value for a uid_t */
+# define GID_MAX UINT_MAX /* max value for a gid_t */
+#endif
+
+#if __XPG_VISIBLE || __POSIX_VISIBLE >= 200809
+# ifdef __LP64__
+# define LONG_BIT 64
+# else
+# define LONG_BIT 32
+# endif
+# define WORD_BIT 32
+#endif
+
+#if __XPG_VISIBLE < 600
+# include <machine/_float.h>
+
+/* XSI defines marked LEGACY in XPG5 and removed in IEEE Std 1003.1-2001 */
+# ifndef FLT_DIG
+# define FLT_DIG __FLT_DIG
+# endif
+# ifndef FLT_MAX
+# define FLT_MAX __FLT_MAX
+# endif
+# ifndef DBL_DIG
+# define DBL_DIG __DBL_DIG
+# endif
+# ifndef DBL_MAX
+# define DBL_MAX __DBL_MAX
+# endif
+
+/* XSI defines marked LEGACY in XPG4v2 and removed in XPG5 */
+# if __XPG_VISIBLE < 500
+# ifndef FLT_MIN
+# define FLT_MIN __FLT_MIN
+# endif
+# ifndef DBL_MIN
+# define DBL_MIN __DBL_MIN
+# endif
+# endif
+
+#endif /* __XPG_VISIBLE < 600 */
+
+#endif
diff --git a/sys/sys/lock.h b/sys/sys/lock.h
new file mode 100644
index 0000000..2388b59
--- /dev/null
+++ b/sys/sys/lock.h
@@ -0,0 +1,55 @@
+/* $OpenBSD: lock.h,v 1.27 2016/06/19 11:54:33 natano Exp $ */
+
+/*
+ * Copyright (c) 1995
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code contains ideas from software contributed to Berkeley by
+ * Avadis Tevanian, Jr., Michael Wayne Young, and the Mach Operating
+ * System project at Carnegie-Mellon University.
+ *
+ * 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.
+ *
+ * @(#)lock.h 8.12 (Berkeley) 5/19/95
+ */
+
+#ifndef _LOCK_H_
+#define _LOCK_H_
+
+#include <sys/rwlock.h>
+
+#define LK_EXCLUSIVE RW_WRITE /* exclusive lock */
+#define LK_SHARED RW_READ /* shared lock */
+#define LK_TYPE_MASK (RW_WRITE|RW_READ) /* type of lock sought */
+#define LK_NOWAIT RW_NOSLEEP /* do not sleep to await lock */
+#define LK_RECURSEFAIL RW_RECURSEFAIL /* fail if recursive exclusive lock */
+#define LK_EXCLOTHER RW_WRITE_OTHER /* exclusive lock held by some other thread */
+#define LK_RWFLAGS (RW_WRITE|RW_READ|RW_NOSLEEP|RW_RECURSEFAIL|RW_WRITE_OTHER)
+
+/* LK_ specific */
+#define LK_DRAIN 0x1000UL /* wait for all lock activity to end */
+#define LK_RETRY 0x2000UL /* vn_lock: retry until locked */
+
+#endif /* !_LOCK_H_ */
diff --git a/sys/sys/lockf.h b/sys/sys/lockf.h
new file mode 100644
index 0000000..8606339
--- /dev/null
+++ b/sys/sys/lockf.h
@@ -0,0 +1,45 @@
+/* $OpenBSD: lockf.h,v 1.17 2019/04/20 08:28:59 anton Exp $ */
+/* $NetBSD: lockf.h,v 1.5 1994/06/29 06:44:33 cgd Exp $ */
+
+/*
+ * Copyright (c) 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Scooter Morris at Genentech Inc.
+ *
+ * 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.
+ *
+ * @(#)lockf.h 8.1 (Berkeley) 6/11/93
+ */
+
+#ifdef _KERNEL
+struct lockf_state;
+
+void lf_init(void);
+int lf_advlock(struct lockf_state **,
+ off_t, caddr_t, int, struct flock *, int);
+void lf_purgelocks(struct lockf_state **);
+#endif /* _KERNEL */
diff --git a/sys/sys/malloc.h b/sys/sys/malloc.h
new file mode 100644
index 0000000..ff8e09b
--- /dev/null
+++ b/sys/sys/malloc.h
@@ -0,0 +1,406 @@
+/* $OpenBSD: malloc.h,v 1.119 2019/11/28 16:23:11 guenther Exp $ */
+/* $NetBSD: malloc.h,v 1.39 1998/07/12 19:52:01 augustss Exp $ */
+
+/*
+ * Copyright (c) 1987, 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.
+ *
+ * @(#)malloc.h 8.5 (Berkeley) 5/3/95
+ */
+
+#ifndef _SYS_MALLOC_H_
+#define _SYS_MALLOC_H_
+
+#include <sys/queue.h>
+
+#define KERN_MALLOC_BUCKETS 1
+#define KERN_MALLOC_BUCKET 2
+#define KERN_MALLOC_KMEMNAMES 3
+#define KERN_MALLOC_KMEMSTATS 4
+#define KERN_MALLOC_MAXID 5
+
+#define CTL_KERN_MALLOC_NAMES { \
+ { 0, 0 }, \
+ { "buckets", CTLTYPE_STRING }, \
+ { "bucket", CTLTYPE_NODE }, \
+ { "kmemnames", CTLTYPE_STRING }, \
+ { "kmemstat", CTLTYPE_NODE }, \
+}
+
+/*
+ * flags to malloc
+ */
+#define M_WAITOK 0x0001
+#define M_NOWAIT 0x0002
+#define M_CANFAIL 0x0004
+#define M_ZERO 0x0008
+
+/*
+ * Types of memory to be allocated
+ */
+#define M_FREE 0 /* should be on free list */
+/* 1 - free */
+#define M_DEVBUF 2 /* device driver memory */
+/* 3 - free */
+#define M_PCB 4 /* protocol control block */
+#define M_RTABLE 5 /* routing tables */
+/* 6 - free */
+/* 7 - free */
+/* 8 - free */
+#define M_IFADDR 9 /* interface address */
+#define M_SOOPTS 10 /* socket options */
+#define M_SYSCTL 11 /* sysctl buffers (persistent storage) */
+#define M_COUNTERS 12 /* per CPU counters */
+/* 13 - free */
+#define M_IOCTLOPS 14 /* ioctl data buffer */
+/* 15-18 - free */
+#define M_IOV 19 /* large iov's */
+#define M_MOUNT 20 /* vfs mount struct */
+/* 21 - free */
+#define M_NFSREQ 22 /* NFS request header */
+#define M_NFSMNT 23 /* NFS mount structure */
+/* 24 - free */
+#define M_VNODE 25 /* Dynamically allocated vnodes */
+#define M_CACHE 26 /* Dynamically allocated cache entries */
+#define M_DQUOT 27 /* UFS quota entries */
+#define M_UFSMNT 28 /* UFS mount structure */
+#define M_SHM 29 /* SVID compatible shared memory segments */
+#define M_VMMAP 30 /* VM map structures */
+#define M_SEM 31 /* SVID compatible semaphores */
+#define M_DIRHASH 32 /* UFS dirhash */
+#define M_ACPI 33 /* ACPI */
+#define M_VMPMAP 34 /* VM pmap */
+/* 35-37 - free */
+#define M_FILE 38 /* Open file structure */
+#define M_FILEDESC 39 /* Open file descriptor table */
+#define M_SIGIO 40 /* Sigio structures */
+#define M_PROC 41 /* Proc structures */
+#define M_SUBPROC 42 /* Proc sub-structures */
+#define M_VCLUSTER 43 /* Cluster for VFS */
+/* 45-46 - free */
+#define M_MFSNODE 46 /* MFS vnode private part */
+/* 47-48 - free */
+#define M_NETADDR 49 /* Export host address structure */
+#define M_NFSSVC 50 /* Nfs server structure */
+/* 51 - free */
+#define M_NFSD 52 /* Nfs server daemon structure */
+#define M_IPMOPTS 53 /* internet multicast options */
+#define M_IPMADDR 54 /* internet multicast address */
+#define M_IFMADDR 55 /* link-level multicast address */
+#define M_MRTABLE 56 /* multicast routing tables */
+#define M_ISOFSMNT 57 /* ISOFS mount structure */
+#define M_ISOFSNODE 58 /* ISOFS vnode private part */
+#define M_MSDOSFSMNT 59 /* MSDOS FS mount structure */
+#define M_MSDOSFSFAT 60 /* MSDOS FS fat table */
+#define M_MSDOSFSNODE 61 /* MSDOS FS vnode private part */
+#define M_TTYS 62 /* allocated tty structures */
+#define M_EXEC 63 /* argument lists & other mem used by exec */
+#define M_MISCFSMNT 64 /* miscfs mount structures */
+#define M_FUSEFS 65 /* fusefs mount structures */
+/* 66-73 - free */
+#define M_PFKEY 74 /* pfkey data */
+#define M_TDB 75 /* Transforms database */
+#define M_XDATA 76 /* IPsec data */
+/* 77 - free */
+#define M_PAGEDEP 78 /* File page dependencies */
+#define M_INODEDEP 79 /* Inode dependencies */
+#define M_NEWBLK 80 /* New block allocation */
+/* 81-82 - free */
+#define M_INDIRDEP 83 /* Indirect block dependencies */
+/* 84-91 - free */
+#define M_VMSWAP 92 /* VM swap structures */
+/* 93-97 - free */
+#define M_UVMAMAP 98 /* UVM amap and related */
+#define M_UVMAOBJ 99 /* UVM aobj and related */
+/* 100 - free */
+#define M_USB 101 /* USB general */
+#define M_USBDEV 102 /* USB device driver */
+#define M_USBHC 103 /* USB host controller */
+#define M_WITNESS 104 /* witness data */
+#define M_MEMDESC 105 /* Memory range */
+/* 106-107 - free */
+#define M_CRYPTO_DATA 108 /* Crypto framework data buffers (keys etc.) */
+/* 109 - free */
+#define M_CREDENTIALS 110 /* IPsec-related credentials and ID info */
+/* 111-113 - free */
+#define M_EMULDATA 114 /* Per-process emulation data */
+/* 115-122 - free */
+
+/* KAME IPv6 */
+#define M_IP6OPT 123 /* IPv6 options */
+#define M_IP6NDP 124 /* IPv6 Neighbour Discovery */
+/* 125-126 - free */
+#define M_TEMP 127 /* misc temporary data buffers */
+
+#define M_NTFSMNT 128 /* NTFS mount structure */
+#define M_NTFSNTNODE 129 /* NTFS ntnode information */
+#define M_NTFSFNODE 130 /* NTFS fnode information */
+#define M_NTFSDIR 131 /* NTFS dir buffer */
+#define M_NTFSNTHASH 132 /* NTFS ntnode hash tables */
+#define M_NTFSNTVATTR 133 /* NTFS file attribute information */
+#define M_NTFSRDATA 134 /* NTFS resident data */
+#define M_NTFSDECOMP 135 /* NTFS decompression temporary */
+#define M_NTFSRUN 136 /* NTFS vrun storage */
+
+#define M_KEVENT 137 /* kqueue related */
+
+ /* 138 free */
+#define M_SYNCACHE 139 /* syn cache hash array */
+
+#define M_UDFMOUNT 140 /* UDF mount */
+#define M_UDFFENTRY 141 /* UDF file entry */
+#define M_UDFFID 142 /* UDF file id */
+
+ /* 143 free */
+
+#define M_AGP 144 /* AGP Memory */
+
+#define M_DRM 145 /* Direct Rendering Manager */
+
+#define M_LAST 146 /* Must be last type + 1 */
+
+#define INITKMEMNAMES { \
+ "free", /* 0 M_FREE */ \
+ NULL, \
+ "devbuf", /* 2 M_DEVBUF */ \
+ NULL, \
+ "pcb", /* 4 M_PCB */ \
+ "rtable", /* 5 M_RTABLE */ \
+ NULL, /* 6 */ \
+ NULL, \
+ NULL, \
+ "ifaddr", /* 9 M_IFADDR */ \
+ "soopts", /* 10 M_SOOPTS */ \
+ "sysctl", /* 11 M_SYSCTL */ \
+ "counters", /* 12 M_COUNTERS */ \
+ NULL, \
+ "ioctlops", /* 14 M_IOCTLOPS */ \
+ NULL, \
+ NULL, \
+ NULL, \
+ NULL, \
+ "iov", /* 19 M_IOV */ \
+ "mount", /* 20 M_MOUNT */ \
+ NULL, \
+ "NFS req", /* 22 M_NFSREQ */ \
+ "NFS mount", /* 23 M_NFSMNT */ \
+ NULL, \
+ "vnodes", /* 25 M_VNODE */ \
+ "namecache", /* 26 M_CACHE */ \
+ "UFS quota", /* 27 M_DQUOT */ \
+ "UFS mount", /* 28 M_UFSMNT */ \
+ "shm", /* 29 M_SHM */ \
+ "VM map", /* 30 M_VMMAP */ \
+ "sem", /* 31 M_SEM */ \
+ "dirhash", /* 32 M_DIRHASH */ \
+ "ACPI", /* 33 M_ACPI */ \
+ "VM pmap", /* 34 M_VMPMAP */ \
+ NULL, /* 35 */ \
+ NULL, /* 36 */ \
+ NULL, /* 37 */ \
+ "file", /* 38 M_FILE */ \
+ "file desc", /* 39 M_FILEDESC */ \
+ "sigio", /* 40 M_SIGIO */ \
+ "proc", /* 41 M_PROC */ \
+ "subproc", /* 42 M_SUBPROC */ \
+ "VFS cluster", /* 43 M_VCLUSTER */ \
+ NULL, \
+ NULL, \
+ "MFS node", /* 46 M_MFSNODE */ \
+ NULL, \
+ NULL, \
+ "Export Host", /* 49 M_NETADDR */ \
+ "NFS srvsock", /* 50 M_NFSSVC */ \
+ NULL, \
+ "NFS daemon", /* 52 M_NFSD */ \
+ "ip_moptions", /* 53 M_IPMOPTS */ \
+ "in_multi", /* 54 M_IPMADDR */ \
+ "ether_multi", /* 55 M_IFMADDR */ \
+ "mrt", /* 56 M_MRTABLE */ \
+ "ISOFS mount", /* 57 M_ISOFSMNT */ \
+ "ISOFS node", /* 58 M_ISOFSNODE */ \
+ "MSDOSFS mount", /* 59 M_MSDOSFSMNT */ \
+ "MSDOSFS fat", /* 60 M_MSDOSFSFAT */ \
+ "MSDOSFS node", /* 61 M_MSDOSFSNODE */ \
+ "ttys", /* 62 M_TTYS */ \
+ "exec", /* 63 M_EXEC */ \
+ "miscfs mount", /* 64 M_MISCFSMNT */ \
+ "fusefs mount", /* 65 M_FUSEFS */ \
+ NULL, \
+ NULL, \
+ NULL, \
+ NULL, \
+ NULL, \
+ NULL, \
+ NULL, \
+ NULL, \
+ "pfkey data", /* 74 M_PFKEY */ \
+ "tdb", /* 75 M_TDB */ \
+ "xform_data", /* 76 M_XDATA */ \
+ NULL, \
+ "pagedep", /* 78 M_PAGEDEP */ \
+ "inodedep", /* 79 M_INODEDEP */ \
+ "newblk", /* 80 M_NEWBLK */ \
+ NULL, \
+ NULL, \
+ "indirdep", /* 83 M_INDIRDEP */ \
+ NULL, NULL, NULL, NULL, \
+ NULL, NULL, NULL, NULL, \
+ "VM swap", /* 92 M_VMSWAP */ \
+ NULL, NULL, NULL, NULL, NULL, \
+ "UVM amap", /* 98 M_UVMAMAP */ \
+ "UVM aobj", /* 99 M_UVMAOBJ */ \
+ NULL, \
+ "USB", /* 101 M_USB */ \
+ "USB device", /* 102 M_USBDEV */ \
+ "USB HC", /* 103 M_USBHC */ \
+ "witness", /* 104 M_WITNESS */ \
+ "memdesc", /* 105 M_MEMDESC */ \
+ NULL, /* 106 */ \
+ NULL, \
+ "crypto data", /* 108 M_CRYPTO_DATA */ \
+ NULL, \
+ "IPsec creds", /* 110 M_CREDENTIALS */ \
+ NULL, \
+ NULL, \
+ NULL, \
+ "emuldata", /* 114 M_EMULDATA */ \
+ NULL, NULL, NULL, NULL, \
+ NULL, NULL, NULL, NULL, \
+ "ip6_options", /* 123 M_IP6OPT */ \
+ "NDP", /* 124 M_IP6NDP */ \
+ NULL, \
+ NULL, \
+ "temp", /* 127 M_TEMP */ \
+ "NTFS mount", /* 128 M_NTFSMNT */ \
+ "NTFS node", /* 129 M_NTFSNTNODE */ \
+ "NTFS fnode", /* 130 M_NTFSFNODE */ \
+ "NTFS dir", /* 131 M_NTFSDIR */ \
+ "NTFS hash", /* 132 M_NTFSNTHASH */ \
+ "NTFS attr", /* 133 M_NTFSNTVATTR */ \
+ "NTFS data", /* 134 M_NTFSRDATA */ \
+ "NTFS decomp", /* 135 M_NTFSDECOMP */ \
+ "NTFS vrun", /* 136 M_NTFSRUN */ \
+ "kqueue", /* 137 M_KEVENT */ \
+ NULL, /* 138 free */ \
+ "SYN cache", /* 139 M_SYNCACHE */ \
+ "UDF mount", /* 140 M_UDFMOUNT */ \
+ "UDF file entry", /* 141 M_UDFFENTRY */ \
+ "UDF file id", /* 142 M_UDFFID */ \
+ NULL, /* 143 free */ \
+ "AGP Memory", /* 144 M_AGP */ \
+ "DRM", /* 145 M_DRM */ \
+}
+
+struct kmemstats {
+ long ks_inuse; /* # of packets of this type currently in use */
+ long ks_calls; /* total packets of this type ever allocated */
+ long ks_memuse; /* total memory held in bytes */
+ u_short ks_limblocks; /* number of times blocked for hitting limit */
+ long ks_maxused; /* maximum number ever used */
+ long ks_limit; /* most that are allowed to exist */
+ long ks_size; /* sizes of this thing that are allocated */
+ long ks_spare;
+};
+
+/*
+ * Array of descriptors that describe the contents of each page
+ */
+struct kmemusage {
+ short ku_indx; /* bucket index */
+ union {
+ u_short freecnt;/* for small allocations, free pieces in page */
+ u_short pagecnt;/* for large allocations, pages alloced */
+ } ku_un;
+};
+#define ku_freecnt ku_un.freecnt
+#define ku_pagecnt ku_un.pagecnt
+
+struct kmem_freelist;
+
+/*
+ * Set of buckets for each size of memory block that is retained
+ */
+struct kmembuckets {
+ XSIMPLEQ_HEAD(, kmem_freelist) kb_freelist; /* list of free blocks */
+ u_int64_t kb_calls; /* total calls to allocate this size */
+ u_int64_t kb_total; /* total number of blocks allocated */
+ u_int64_t kb_totalfree; /* # of free elements in this bucket */
+ u_int64_t kb_elmpercl; /* # of elements in this sized allocation */
+ u_int64_t kb_highwat; /* high water mark */
+ u_int64_t kb_couldfree; /* over high water mark and could free */
+};
+
+/*
+ * Constants for setting the parameters of the kernel memory allocator.
+ *
+ * 2 ** MINBUCKET is the smallest unit of memory that will be
+ * allocated. It must be at least large enough to hold a pointer.
+ *
+ * Units of memory less or equal to MAXALLOCSAVE will permanently
+ * allocate physical memory; requests for these size pieces of
+ * memory are quite fast. Allocations greater than MAXALLOCSAVE must
+ * always allocate and free physical memory; requests for these
+ * size allocations should be done infrequently as they will be slow.
+ *
+ * Constraints: PAGE_SIZE <= MAXALLOCSAVE <= 2 ** (MINBUCKET + 14), and
+ * MAXALLOCSIZE must be a power of two.
+ */
+#define MINBUCKET 4 /* 4 => min allocation of 16 bytes */
+
+#ifdef _KERNEL
+
+#define MINALLOCSIZE (1 << MINBUCKET)
+#define MAXALLOCSAVE (2 * PAGE_SIZE)
+
+/*
+ * Turn virtual addresses into kmem map indices
+ */
+#define kmemxtob(alloc) (kmembase + (alloc) * PAGE_SIZE)
+#define btokmemx(addr) (((caddr_t)(addr) - kmembase) / PAGE_SIZE)
+#define btokup(addr) (&kmemusage[((caddr_t)(addr) - kmembase) >> PAGE_SHIFT])
+
+extern struct kmemstats kmemstats[];
+extern struct kmemusage *kmemusage;
+extern char *kmembase;
+extern struct kmembuckets bucket[];
+
+void *malloc(size_t, int, int);
+void *mallocarray(size_t, size_t, int, int);
+void free(void *, int, size_t);
+int sysctl_malloc(int *, u_int, void *, size_t *, void *, size_t,
+ struct proc *);
+
+size_t malloc_roundup(size_t);
+void malloc_printit(int (*)(const char *, ...));
+
+void poison_mem(void *, size_t);
+int poison_check(void *, size_t, size_t *, uint32_t *);
+uint32_t poison_value(void *);
+
+#endif /* _KERNEL */
+#endif /* !_SYS_MALLOC_H_ */
diff --git a/sys/sys/mbuf.h b/sys/sys/mbuf.h
new file mode 100644
index 0000000..a54b003
--- /dev/null
+++ b/sys/sys/mbuf.h
@@ -0,0 +1,550 @@
+/* $OpenBSD: mbuf.h,v 1.246 2020/01/22 22:56:35 dlg Exp $ */
+/* $NetBSD: mbuf.h,v 1.19 1996/02/09 18:25:14 christos Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 1988, 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.
+ *
+ * @(#)mbuf.h 8.5 (Berkeley) 2/19/95
+ */
+
+#ifndef _SYS_MBUF_H_
+#define _SYS_MBUF_H_
+
+#include <sys/queue.h>
+
+/*
+ * Constants related to network buffer management.
+ * MCLBYTES must be no larger than PAGE_SIZE (the software page size) and,
+ * on machines that exchange pages of input or output buffers with mbuf
+ * clusters (MAPPED_MBUFS), MCLBYTES must also be an integral multiple
+ * of the hardware page size.
+ */
+#define MSIZE 256 /* size of an mbuf */
+
+/*
+ * Mbufs are of a single size, MSIZE, which includes overhead. An mbuf may
+ * add a single "mbuf cluster" of size MCLBYTES, which has no additional
+ * overhead and is used instead of the internal data area; this is done when
+ * at least MINCLSIZE of data must be stored.
+ */
+
+#define MLEN (MSIZE - sizeof(struct m_hdr)) /* normal data len */
+#define MHLEN (MLEN - sizeof(struct pkthdr)) /* data len w/pkthdr */
+
+#define MAXMCLBYTES (64 * 1024) /* largest cluster from the stack */
+#define MINCLSIZE (MHLEN + MLEN + 1) /* smallest amount to put in cluster */
+#define M_MAXCOMPRESS (MHLEN / 2) /* max amount to copy for compression */
+
+#define MCLSHIFT 11 /* convert bytes to m_buf clusters */
+ /* 2K cluster can hold Ether frame */
+#define MCLBYTES (1 << MCLSHIFT) /* size of a m_buf cluster */
+#define MCLOFSET (MCLBYTES - 1)
+
+/* Packet tags structure */
+struct m_tag {
+ SLIST_ENTRY(m_tag) m_tag_link; /* List of packet tags */
+ u_int16_t m_tag_id; /* Tag ID */
+ u_int16_t m_tag_len; /* Length of data */
+};
+
+/*
+ * Macros for type conversion
+ * mtod(m,t) - convert mbuf pointer to data pointer of correct type
+ */
+#define mtod(m,t) ((t)((m)->m_data))
+
+/* header at beginning of each mbuf: */
+struct m_hdr {
+ struct mbuf *mh_next; /* next buffer in chain */
+ struct mbuf *mh_nextpkt; /* next chain in queue/record */
+ caddr_t mh_data; /* location of data */
+ u_int mh_len; /* amount of data in this mbuf */
+ short mh_type; /* type of data in this mbuf */
+ u_short mh_flags; /* flags; see below */
+#ifndef __LP64__
+ u_int mh_pad; /* pad to 8-byte boundary */
+#endif
+};
+
+/* pf stuff */
+struct pf_state_key;
+struct inpcb;
+
+struct pkthdr_pf {
+ struct pf_state_key *statekey; /* pf stackside statekey */
+ struct inpcb *inp; /* connected pcb for outgoing packet */
+ u_int32_t qid; /* queue id */
+ u_int16_t tag; /* tag id */
+ u_int16_t delay; /* delay packet by X ms */
+ u_int8_t flags;
+ u_int8_t routed;
+ u_int8_t prio;
+ u_int8_t pad[1];
+};
+
+/* pkthdr_pf.flags */
+#define PF_TAG_GENERATED 0x01
+#define PF_TAG_SYNCOOKIE_RECREATED 0x02
+#define PF_TAG_TRANSLATE_LOCALHOST 0x04
+#define PF_TAG_DIVERTED 0x08
+#define PF_TAG_DIVERTED_PACKET 0x10
+#define PF_TAG_REROUTE 0x20
+#define PF_TAG_REFRAGMENTED 0x40 /* refragmented ipv6 packet */
+#define PF_TAG_PROCESSED 0x80 /* packet was checked by pf */
+
+#ifdef _KERNEL
+#define MPF_BITS \
+ ("\20\1GENERATED\2SYNCOOKIE_RECREATED\3TRANSLATE_LOCALHOST\4DIVERTED" \
+ "\5DIVERTED_PACKET\6REROUTE\7REFRAGMENTED\10PROCESSED")
+#endif
+
+/* record/packet header in first mbuf of chain; valid if M_PKTHDR set */
+struct pkthdr {
+ void *ph_cookie; /* additional data */
+ SLIST_HEAD(, m_tag) ph_tags; /* list of packet tags */
+ int64_t ph_timestamp; /* packet timestamp */
+ int len; /* total packet length */
+ u_int16_t ph_tagsset; /* mtags attached */
+ u_int16_t ph_flowid; /* pseudo unique flow id */
+ u_int16_t csum_flags; /* checksum flags */
+ u_int16_t ether_vtag; /* Ethernet 802.1p+Q vlan tag */
+ u_int ph_rtableid; /* routing table id */
+ u_int ph_ifidx; /* rcv interface index */
+ u_int8_t ph_loopcnt; /* mbuf is looping in kernel */
+ u_int8_t ph_family; /* af, used when queueing */
+ struct pkthdr_pf pf;
+};
+
+/* description of external storage mapped into mbuf, valid if M_EXT set */
+struct mbuf_ext {
+ caddr_t ext_buf; /* start of buffer */
+ void *ext_arg;
+ u_int ext_free_fn; /* index of free function */
+ u_int ext_size; /* size of buffer, for ext_free_fn */
+ struct mbuf *ext_nextref;
+ struct mbuf *ext_prevref;
+#ifdef DEBUG
+ const char *ext_ofile;
+ const char *ext_nfile;
+ int ext_oline;
+ int ext_nline;
+#endif
+};
+
+struct mbuf {
+ struct m_hdr m_hdr;
+ union {
+ struct {
+ struct pkthdr MH_pkthdr; /* M_PKTHDR set */
+ union {
+ struct mbuf_ext MH_ext; /* M_EXT set */
+ char MH_databuf[MHLEN];
+ } MH_dat;
+ } MH;
+ char M_databuf[MLEN]; /* !M_PKTHDR, !M_EXT */
+ } M_dat;
+};
+#define m_next m_hdr.mh_next
+#define m_len m_hdr.mh_len
+#define m_data m_hdr.mh_data
+#define m_type m_hdr.mh_type
+#define m_flags m_hdr.mh_flags
+#define m_nextpkt m_hdr.mh_nextpkt
+#define m_pkthdr M_dat.MH.MH_pkthdr
+#define m_ext M_dat.MH.MH_dat.MH_ext
+#define m_pktdat M_dat.MH.MH_dat.MH_databuf
+#define m_dat M_dat.M_databuf
+
+/* mbuf flags */
+#define M_EXT 0x0001 /* has associated external storage */
+#define M_PKTHDR 0x0002 /* start of record */
+#define M_EOR 0x0004 /* end of record */
+#define M_EXTWR 0x0008 /* external storage is writable */
+#define M_PROTO1 0x0010 /* protocol-specific */
+
+/* mbuf pkthdr flags, also in m_flags */
+#define M_VLANTAG 0x0020 /* ether_vtag is valid */
+#define M_LOOP 0x0040 /* packet has been sent from local machine */
+#define M_ACAST 0x0080 /* received as IPv6 anycast */
+#define M_BCAST 0x0100 /* sent/received as link-level broadcast */
+#define M_MCAST 0x0200 /* sent/received as link-level multicast */
+#define M_CONF 0x0400 /* payload was encrypted (ESP-transport) */
+#define M_AUTH 0x0800 /* payload was authenticated (AH or ESP auth) */
+#define M_TUNNEL 0x1000 /* IP-in-IP added by tunnel mode IPsec */
+#define M_ZEROIZE 0x2000 /* Zeroize data part on free */
+#define M_COMP 0x4000 /* header was decompressed */
+#define M_LINK0 0x8000 /* link layer specific flag */
+
+#ifdef _KERNEL
+#define M_BITS \
+ ("\20\1M_EXT\2M_PKTHDR\3M_EOR\4M_EXTWR\5M_PROTO1\6M_VLANTAG\7M_LOOP" \
+ "\10M_ACAST\11M_BCAST\12M_MCAST\13M_CONF\14M_AUTH\15M_TUNNEL" \
+ "\16M_ZEROIZE\17M_COMP\20M_LINK0")
+#endif
+
+/* flags copied when copying m_pkthdr */
+#define M_COPYFLAGS (M_PKTHDR|M_EOR|M_PROTO1|M_BCAST|M_MCAST|M_CONF|M_COMP|\
+ M_AUTH|M_LOOP|M_TUNNEL|M_LINK0|M_VLANTAG|M_ACAST|\
+ M_ZEROIZE)
+
+/* Checksumming flags */
+#define M_IPV4_CSUM_OUT 0x0001 /* IPv4 checksum needed */
+#define M_TCP_CSUM_OUT 0x0002 /* TCP checksum needed */
+#define M_UDP_CSUM_OUT 0x0004 /* UDP checksum needed */
+#define M_IPV4_CSUM_IN_OK 0x0008 /* IPv4 checksum verified */
+#define M_IPV4_CSUM_IN_BAD 0x0010 /* IPv4 checksum bad */
+#define M_TCP_CSUM_IN_OK 0x0020 /* TCP checksum verified */
+#define M_TCP_CSUM_IN_BAD 0x0040 /* TCP checksum bad */
+#define M_UDP_CSUM_IN_OK 0x0080 /* UDP checksum verified */
+#define M_UDP_CSUM_IN_BAD 0x0100 /* UDP checksum bad */
+#define M_ICMP_CSUM_OUT 0x0200 /* ICMP/ICMPv6 checksum needed */
+#define M_ICMP_CSUM_IN_OK 0x0400 /* ICMP/ICMPv6 checksum verified */
+#define M_ICMP_CSUM_IN_BAD 0x0800 /* ICMP/ICMPv6 checksum bad */
+#define M_IPV6_DF_OUT 0x1000 /* don't fragment outgoing IPv6 */
+#define M_TIMESTAMP 0x2000 /* ph_timestamp is set */
+
+#ifdef _KERNEL
+#define MCS_BITS \
+ ("\20\1IPV4_CSUM_OUT\2TCP_CSUM_OUT\3UDP_CSUM_OUT\4IPV4_CSUM_IN_OK" \
+ "\5IPV4_CSUM_IN_BAD\6TCP_CSUM_IN_OK\7TCP_CSUM_IN_BAD\10UDP_CSUM_IN_OK" \
+ "\11UDP_CSUM_IN_BAD\12ICMP_CSUM_OUT\13ICMP_CSUM_IN_OK\14ICMP_CSUM_IN_BAD" \
+ "\15IPV6_NODF_OUT" "\16TIMESTAMP")
+#endif
+
+/* mbuf types */
+#define MT_FREE 0 /* should be on free list */
+#define MT_DATA 1 /* dynamic (data) allocation */
+#define MT_HEADER 2 /* packet header */
+#define MT_SONAME 3 /* socket name */
+#define MT_SOOPTS 4 /* socket options */
+#define MT_FTABLE 5 /* fragment reassembly header */
+#define MT_CONTROL 6 /* extra-data protocol message */
+#define MT_OOBDATA 7 /* expedited data */
+#define MT_NTYPES 8
+
+/* flowid field */
+#define M_FLOWID_VALID 0x8000 /* is the flowid set */
+#define M_FLOWID_MASK 0x7fff /* flow id to map to path */
+
+/* flags to m_get/MGET */
+#include <sys/malloc.h>
+#define M_DONTWAIT M_NOWAIT
+#define M_WAIT M_WAITOK
+
+/*
+ * mbuf allocation/deallocation macros:
+ *
+ * MGET(struct mbuf *m, int how, int type)
+ * allocates an mbuf and initializes it to contain internal data.
+ *
+ * MGETHDR(struct mbuf *m, int how, int type)
+ * allocates an mbuf and initializes it to contain a packet header
+ * and internal data.
+ */
+#define MGET(m, how, type) m = m_get((how), (type))
+
+#define MGETHDR(m, how, type) m = m_gethdr((how), (type))
+
+/*
+ * Macros for tracking external storage associated with an mbuf.
+ */
+#ifdef DEBUG
+#define MCLREFDEBUGN(m, file, line) do { \
+ (m)->m_ext.ext_nfile = (file); \
+ (m)->m_ext.ext_nline = (line); \
+ } while (/* CONSTCOND */ 0)
+#define MCLREFDEBUGO(m, file, line) do { \
+ (m)->m_ext.ext_ofile = (file); \
+ (m)->m_ext.ext_oline = (line); \
+ } while (/* CONSTCOND */ 0)
+#else
+#define MCLREFDEBUGN(m, file, line)
+#define MCLREFDEBUGO(m, file, line)
+#endif
+
+#define MCLISREFERENCED(m) ((m)->m_ext.ext_nextref != (m))
+
+#define MCLADDREFERENCE(o, n) m_extref((o), (n))
+
+#define MCLINITREFERENCE(m) do { \
+ (m)->m_ext.ext_prevref = (m); \
+ (m)->m_ext.ext_nextref = (m); \
+ MCLREFDEBUGO((m), __FILE__, __LINE__); \
+ MCLREFDEBUGN((m), NULL, 0); \
+ } while (/* CONSTCOND */ 0)
+
+/*
+ * Macros for mbuf external storage.
+ *
+ * MEXTADD adds pre-allocated external storage to
+ * a normal mbuf; the flag M_EXT is set.
+ *
+ * MCLGET allocates and adds an mbuf cluster to a normal mbuf;
+ * the flag M_EXT is set upon success.
+ */
+#define MEXTADD(m, buf, size, mflags, freefn, arg) do { \
+ (m)->m_data = (m)->m_ext.ext_buf = (caddr_t)(buf); \
+ (m)->m_flags |= M_EXT | (mflags & M_EXTWR); \
+ (m)->m_ext.ext_size = (size); \
+ (m)->m_ext.ext_free_fn = (freefn); \
+ (m)->m_ext.ext_arg = (arg); \
+ MCLINITREFERENCE(m); \
+} while (/* CONSTCOND */ 0)
+
+#define MCLGET(m, how) (void) m_clget((m), (how), MCLBYTES)
+#define MCLGETI(m, how, ifp, l) m_clget((m), (how), (l))
+
+u_int mextfree_register(void (*)(caddr_t, u_int, void *));
+#define MEXTFREE_POOL 0
+
+/*
+ * Move just m_pkthdr from from to to,
+ * remove M_PKTHDR and clean flags/tags for from.
+ */
+#define M_MOVE_HDR(to, from) do { \
+ (to)->m_pkthdr = (from)->m_pkthdr; \
+ (from)->m_flags &= ~M_PKTHDR; \
+ SLIST_INIT(&(from)->m_pkthdr.ph_tags); \
+ (from)->m_pkthdr.pf.statekey = NULL; \
+} while (/* CONSTCOND */ 0)
+
+/*
+ * MOVE mbuf pkthdr from from to to.
+ * from must have M_PKTHDR set, and to must be empty.
+ */
+#define M_MOVE_PKTHDR(to, from) do { \
+ (to)->m_flags = ((to)->m_flags & (M_EXT | M_EXTWR)); \
+ (to)->m_flags |= (from)->m_flags & M_COPYFLAGS; \
+ M_MOVE_HDR((to), (from)); \
+ if (((to)->m_flags & M_EXT) == 0) \
+ (to)->m_data = (to)->m_pktdat; \
+} while (/* CONSTCOND */ 0)
+
+/*
+ * Determine if an mbuf's data area is read-only. This is true for
+ * non-cluster external storage and for clusters that are being
+ * referenced by more than one mbuf.
+ */
+#define M_READONLY(m) \
+ (((m)->m_flags & M_EXT) != 0 && \
+ (((m)->m_flags & M_EXTWR) == 0 || MCLISREFERENCED(m)))
+
+/*
+ * Arrange to prepend space of size plen to mbuf m.
+ * If a new mbuf must be allocated, how specifies whether to wait.
+ * If how is M_DONTWAIT and allocation fails, the original mbuf chain
+ * is freed and m is set to NULL.
+ */
+#define M_PREPEND(m, plen, how) \
+ (m) = m_prepend((m), (plen), (how))
+
+/* length to m_copy to copy all */
+#define M_COPYALL 1000000000
+
+/*
+ * Mbuf statistics.
+ * For statistics related to mbuf and cluster allocations, see also the
+ * pool headers (mbpool and mclpool).
+ */
+struct mbstat {
+ u_long m_drops; /* times failed to find space */
+ u_long m_wait; /* times waited for space */
+ u_long m_drain; /* times drained protocols for space */
+ u_short m_mtypes[256]; /* type specific mbuf allocations */
+};
+
+#define MBSTAT_TYPES MT_NTYPES
+#define MBSTAT_DROPS (MBSTAT_TYPES + 0)
+#define MBSTAT_WAIT (MBSTAT_TYPES + 1)
+#define MBSTAT_DRAIN (MBSTAT_TYPES + 2)
+#define MBSTAT_COUNT (MBSTAT_TYPES + 3)
+
+#include <sys/mutex.h>
+
+struct mbuf_list {
+ struct mbuf *ml_head;
+ struct mbuf *ml_tail;
+ u_int ml_len;
+};
+
+struct mbuf_queue {
+ struct mutex mq_mtx;
+ struct mbuf_list mq_list;
+ u_int mq_maxlen;
+ u_int mq_drops;
+};
+
+#ifdef _KERNEL
+struct pool;
+
+extern long nmbclust; /* limit on the # of clusters */
+extern int mblowat; /* mbuf low water mark */
+extern int mcllowat; /* mbuf cluster low water mark */
+extern int max_linkhdr; /* largest link-level header */
+extern int max_protohdr; /* largest protocol header */
+extern int max_hdr; /* largest link+protocol header */
+
+void mbinit(void);
+void mbcpuinit(void);
+int nmbclust_update(long);
+struct mbuf *m_copym(struct mbuf *, int, int, int);
+struct mbuf *m_free(struct mbuf *);
+struct mbuf *m_get(int, int);
+struct mbuf *m_getclr(int, int);
+struct mbuf *m_gethdr(int, int);
+struct mbuf *m_inithdr(struct mbuf *);
+void m_removehdr(struct mbuf *);
+void m_resethdr(struct mbuf *);
+void m_calchdrlen(struct mbuf *);
+int m_defrag(struct mbuf *, int);
+struct mbuf *m_prepend(struct mbuf *, int, int);
+struct mbuf *m_pulldown(struct mbuf *, int, int, int *);
+struct mbuf *m_pullup(struct mbuf *, int);
+struct mbuf *m_split(struct mbuf *, int, int);
+struct mbuf *m_makespace(struct mbuf *, int, int, int *);
+struct mbuf *m_getptr(struct mbuf *, int, int *);
+int m_leadingspace(struct mbuf *);
+int m_trailingspace(struct mbuf *);
+void m_align(struct mbuf *, int);
+struct mbuf *m_clget(struct mbuf *, int, u_int);
+void m_extref(struct mbuf *, struct mbuf *);
+void m_pool_init(struct pool *, u_int, u_int, const char *);
+void m_extfree_pool(caddr_t, u_int, void *);
+void m_adj(struct mbuf *, int);
+int m_copyback(struct mbuf *, int, int, const void *, int);
+struct mbuf *m_freem(struct mbuf *);
+void m_purge(struct mbuf *);
+void m_reclaim(void *, int);
+void m_copydata(struct mbuf *, int, int, caddr_t);
+void m_cat(struct mbuf *, struct mbuf *);
+struct mbuf *m_devget(char *, int, int);
+int m_apply(struct mbuf *, int, int,
+ int (*)(caddr_t, caddr_t, unsigned int), caddr_t);
+struct mbuf *m_dup_pkt(struct mbuf *, unsigned int, int);
+int m_dup_pkthdr(struct mbuf *, struct mbuf *, int);
+
+void m_microtime(const struct mbuf *, struct timeval *);
+
+static inline struct mbuf *
+m_freemp(struct mbuf **mp)
+{
+ struct mbuf *m = *mp;
+
+ *mp = NULL;
+ return m_freem(m);
+}
+
+/* Packet tag routines */
+struct m_tag *m_tag_get(int, int, int);
+void m_tag_prepend(struct mbuf *, struct m_tag *);
+void m_tag_delete(struct mbuf *, struct m_tag *);
+void m_tag_delete_chain(struct mbuf *);
+struct m_tag *m_tag_find(struct mbuf *, int, struct m_tag *);
+struct m_tag *m_tag_copy(struct m_tag *, int);
+int m_tag_copy_chain(struct mbuf *, struct mbuf *, int);
+void m_tag_init(struct mbuf *);
+struct m_tag *m_tag_first(struct mbuf *);
+struct m_tag *m_tag_next(struct mbuf *, struct m_tag *);
+
+/* Packet tag types */
+#define PACKET_TAG_IPSEC_IN_DONE 0x0001 /* IPsec applied, in */
+#define PACKET_TAG_IPSEC_OUT_DONE 0x0002 /* IPsec applied, out */
+#define PACKET_TAG_GIF 0x0040 /* GIF processing done */
+#define PACKET_TAG_GRE 0x0080 /* GRE processing done */
+#define PACKET_TAG_DLT 0x0100 /* data link layer type */
+#define PACKET_TAG_PF_DIVERT 0x0200 /* pf(4) diverted packet */
+#define PACKET_TAG_PF_REASSEMBLED 0x0800 /* pf reassembled ipv6 packet */
+#define PACKET_TAG_SRCROUTE 0x1000 /* IPv4 source routing options */
+#define PACKET_TAG_TUNNEL 0x2000 /* Tunnel endpoint address */
+#define PACKET_TAG_CARP_BAL_IP 0x4000 /* carp(4) ip balanced marker */
+
+#define MTAG_BITS \
+ ("\20\1IPSEC_IN_DONE\2IPSEC_OUT_DONE\3IPSEC_IN_CRYPTO_DONE" \
+ "\4IPSEC_OUT_CRYPTO_NEEDED\5IPSEC_PENDING_TDB\6BRIDGE\7GIF\10GRE\11DLT" \
+ "\12PF_DIVERT\14PF_REASSEMBLED\15SRCROUTE\16TUNNEL\17CARP_BAL_IP")
+
+/*
+ * Maximum tag payload length (that is excluding the m_tag structure).
+ * Please make sure to update this value when increasing the payload
+ * length for an existing packet tag type or when adding a new one that
+ * has payload larger than the value below.
+ */
+#define PACKET_TAG_MAXSIZE 60
+
+/* Detect mbufs looping in the kernel when spliced too often. */
+#define M_MAXLOOP 128
+
+/*
+ * mbuf lists
+ */
+
+#define MBUF_LIST_INITIALIZER() { NULL, NULL, 0 }
+
+void ml_init(struct mbuf_list *);
+void ml_enqueue(struct mbuf_list *, struct mbuf *);
+struct mbuf * ml_dequeue(struct mbuf_list *);
+void ml_enlist(struct mbuf_list *, struct mbuf_list *);
+struct mbuf * ml_dechain(struct mbuf_list *);
+unsigned int ml_purge(struct mbuf_list *);
+unsigned int ml_hdatalen(struct mbuf_list *);
+
+#define ml_len(_ml) ((_ml)->ml_len)
+#define ml_empty(_ml) ((_ml)->ml_len == 0)
+
+#define MBUF_LIST_FIRST(_ml) ((_ml)->ml_head)
+#define MBUF_LIST_NEXT(_m) ((_m)->m_nextpkt)
+
+#define MBUF_LIST_FOREACH(_ml, _m) \
+ for ((_m) = MBUF_LIST_FIRST(_ml); \
+ (_m) != NULL; \
+ (_m) = MBUF_LIST_NEXT(_m))
+
+/*
+ * mbuf queues
+ */
+
+#define MBUF_QUEUE_INITIALIZER(_maxlen, _ipl) \
+ { MUTEX_INITIALIZER(_ipl), MBUF_LIST_INITIALIZER(), (_maxlen), 0 }
+
+void mq_init(struct mbuf_queue *, u_int, int);
+int mq_enqueue(struct mbuf_queue *, struct mbuf *);
+struct mbuf * mq_dequeue(struct mbuf_queue *);
+int mq_enlist(struct mbuf_queue *, struct mbuf_list *);
+void mq_delist(struct mbuf_queue *, struct mbuf_list *);
+struct mbuf * mq_dechain(struct mbuf_queue *);
+unsigned int mq_purge(struct mbuf_queue *);
+unsigned int mq_hdatalen(struct mbuf_queue *);
+
+#define mq_len(_mq) ml_len(&(_mq)->mq_list)
+#define mq_empty(_mq) ml_empty(&(_mq)->mq_list)
+#define mq_full(_mq) (mq_len((_mq)) >= (_mq)->mq_maxlen)
+#define mq_drops(_mq) ((_mq)->mq_drops)
+#define mq_set_maxlen(_mq, _l) ((_mq)->mq_maxlen = (_l))
+
+#endif /* _KERNEL */
+#endif /* _SYS_MBUF_H_ */
diff --git a/sys/sys/memrange.h b/sys/sys/memrange.h
new file mode 100644
index 0000000..c806e39
--- /dev/null
+++ b/sys/sys/memrange.h
@@ -0,0 +1,97 @@
+/* $OpenBSD: memrange.h,v 1.10 2015/08/18 20:19:32 miod Exp $ */
+/*-
+ * Copyright (c) 1999 Michael Smith <msmith@freebsd.org>
+ * 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.
+ */
+/*
+ * Memory range attribute operations, performed on /dev/mem
+ */
+
+/* Memory range attributes */
+#define MDF_UNCACHEABLE (1<<0) /* region not cached */
+#define MDF_WRITECOMBINE (1<<1) /* region supports "write combine" action */
+#define MDF_WRITETHROUGH (1<<2) /* write-through cached */
+#define MDF_WRITEBACK (1<<3) /* write-back cached */
+#define MDF_WRITEPROTECT (1<<4) /* read-only region */
+#define MDF_UNKNOWN (1<<5) /* any state we don't understand */
+#define MDF_ATTRMASK (0x00ffffff)
+
+#define MDF_FIXBASE (1<<24) /* fixed base */
+#define MDF_FIXLEN (1<<25) /* fixed length */
+#define MDF_FIRMWARE (1<<26) /* set by firmware (XXX not useful?) */
+#define MDF_ACTIVE (1<<27) /* currently active */
+#define MDF_BOGUS (1<<28) /* we don't like it */
+#define MDF_FIXACTIVE (1<<29) /* can't be turned off */
+#define MDF_FORCE (1<<31) /* force risky changes */
+
+struct mem_range_desc {
+ u_int64_t mr_base;
+ u_int64_t mr_len;
+ int mr_flags;
+ char mr_owner[8];
+};
+
+struct mem_range_op {
+ struct mem_range_desc *mo_desc;
+ int mo_arg[2];
+#define MEMRANGE_SET_UPDATE 0
+#define MEMRANGE_SET_REMOVE 1
+ /* XXX want a flag that says "set and undo when I exit" */
+};
+
+#define MEMRANGE_GET _IOWR('m', 50, struct mem_range_op)
+#define MEMRANGE_SET _IOW('m', 51, struct mem_range_op)
+
+/* Offset indicating a write combining mapping is requested. */
+#define MEMRANGE_WC_RANGE 0x4000000000000000ULL
+
+#ifdef _KERNEL
+
+struct mem_range_softc;
+struct mem_range_ops {
+ void (*init)(struct mem_range_softc *sc);
+ int (*set)(struct mem_range_softc *sc,
+ struct mem_range_desc *mrd, int *arg);
+ void (*initAP)(struct mem_range_softc *sc);
+ void (*reload)(struct mem_range_softc *sc);
+};
+
+struct mem_range_softc {
+ struct mem_range_ops *mr_op;
+ int mr_cap;
+ int mr_ndesc;
+ struct mem_range_desc *mr_desc;
+};
+
+extern struct mem_range_softc mem_range_softc;
+
+__BEGIN_DECLS
+extern void mem_range_attach(void);
+extern int mem_range_attr_get(struct mem_range_desc *mrd, int *arg);
+extern int mem_range_attr_set(struct mem_range_desc *mrd, int *arg);
+extern void mem_range_AP_init(void);
+extern void mem_range_reload(void);
+__END_DECLS
+#endif /* _KERNEL */
+
diff --git a/sys/sys/mman.h b/sys/sys/mman.h
new file mode 100644
index 0000000..47972b5
--- /dev/null
+++ b/sys/sys/mman.h
@@ -0,0 +1,165 @@
+/* $OpenBSD: mman.h,v 1.34 2019/03/01 01:46:18 cheloha Exp $ */
+/* $NetBSD: mman.h,v 1.11 1995/03/26 20:24:23 jtc 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.
+ * 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.
+ *
+ * @(#)mman.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _KERNEL
+#include <sys/cdefs.h>
+#endif
+
+/*
+ * Protections are chosen from these bits, or-ed together
+ */
+#define PROT_NONE 0x00 /* no permissions */
+#define PROT_READ 0x01 /* pages can be read */
+#define PROT_WRITE 0x02 /* pages can be written */
+#define PROT_EXEC 0x04 /* pages can be executed */
+
+/*
+ * Flags contain sharing type and options.
+ * Sharing types; choose one.
+ */
+#define MAP_SHARED 0x0001 /* share changes */
+#define MAP_PRIVATE 0x0002 /* changes are private */
+
+/*
+ * Other flags
+ */
+#define MAP_FIXED 0x0010 /* map addr must be exactly as requested */
+#define __MAP_NOREPLACE 0x0800 /* fail if address not available */
+#define MAP_ANON 0x1000 /* allocated from memory, swap space */
+#define MAP_ANONYMOUS MAP_ANON /* alternate POSIX spelling */
+#define __MAP_NOFAULT 0x2000
+#define MAP_STACK 0x4000 /* mapping is used for a stack */
+#define MAP_CONCEAL 0x8000 /* omit from dumps */
+
+#define MAP_FLAGMASK 0xfff7
+
+#ifndef _KERNEL
+/*
+ * Legacy defines for userland source compatibility.
+ * Can be removed once no longer needed in base and ports.
+ */
+#define MAP_COPY MAP_PRIVATE /* "copy" region at mmap time */
+#define MAP_FILE 0 /* map from file (default) */
+#define MAP_HASSEMAPHORE 0 /* region may contain semaphores */
+#define MAP_INHERIT 0 /* region is retained after exec */
+#define MAP_NOEXTEND 0 /* for MAP_FILE, don't change file size */
+#define MAP_NORESERVE 0 /* Sun: don't reserve needed swap area */
+#define MAP_RENAME 0 /* Sun: rename private pages to file */
+#define MAP_TRYFIXED 0 /* attempt hint address, even within heap */
+#endif
+
+/*
+ * Error return from mmap()
+ */
+#define MAP_FAILED ((void *)-1)
+
+/*
+ * POSIX memory advisory values.
+ * Note: keep consistent with the original definitions below.
+ */
+#define POSIX_MADV_NORMAL 0 /* no further special treatment */
+#define POSIX_MADV_RANDOM 1 /* expect random page references */
+#define POSIX_MADV_SEQUENTIAL 2 /* expect sequential page references */
+#define POSIX_MADV_WILLNEED 3 /* will need these pages */
+#define POSIX_MADV_DONTNEED 4 /* don't need these pages */
+
+#if __BSD_VISIBLE
+/*
+ * Original advice values, equivalent to POSIX definitions,
+ * and few implementation-specific ones. For in-kernel and historic use.
+ */
+#define MADV_NORMAL POSIX_MADV_NORMAL
+#define MADV_RANDOM POSIX_MADV_RANDOM
+#define MADV_SEQUENTIAL POSIX_MADV_SEQUENTIAL
+#define MADV_WILLNEED POSIX_MADV_WILLNEED
+#define MADV_DONTNEED POSIX_MADV_DONTNEED
+#define MADV_SPACEAVAIL 5 /* insure that resources are reserved */
+#define MADV_FREE 6 /* pages are empty, free them */
+#endif
+
+/*
+ * Flags to minherit
+ */
+#define MAP_INHERIT_SHARE 0 /* share with child */
+#define MAP_INHERIT_COPY 1 /* copy into child */
+#define MAP_INHERIT_NONE 2 /* absent from child */
+#define MAP_INHERIT_ZERO 3 /* zero in child */
+
+/*
+ * Flags to msync
+ */
+#define MS_ASYNC 0x01 /* perform asynchronous writes */
+#define MS_SYNC 0x02 /* perform synchronous writes */
+#define MS_INVALIDATE 0x04 /* invalidate cached data */
+
+/*
+ * Flags to mlockall
+ */
+#define MCL_CURRENT 0x01 /* lock all pages currently mapped */
+#define MCL_FUTURE 0x02 /* lock all pages mapped in the future */
+
+#ifndef _KERNEL
+#include <sys/_types.h>
+
+#ifndef _SIZE_T_DEFINED_
+#define _SIZE_T_DEFINED_
+typedef __size_t size_t;
+#endif
+
+#ifndef _OFF_T_DEFINED_
+#define _OFF_T_DEFINED_
+typedef __off_t off_t;
+#endif
+
+__BEGIN_DECLS
+void * mmap(void *, size_t, int, int, int, off_t);
+int mprotect(void *, size_t, int);
+int munmap(void *, size_t);
+int msync(void *, size_t, int);
+int mlock(const void *, size_t);
+int munlock(const void *, size_t);
+int mlockall(int);
+int munlockall(void);
+#if __BSD_VISIBLE
+int madvise(void *, size_t, int);
+int minherit(void *, size_t, int);
+void * mquery(void *, size_t, int, int, int, off_t);
+#endif
+int posix_madvise(void *, size_t, int);
+int shm_open(const char *, int, __mode_t);
+int shm_unlink(const char *);
+int shm_mkstemp(char *);
+__END_DECLS
+
+#endif /* !_KERNEL */
diff --git a/sys/sys/mount.h b/sys/sys/mount.h
new file mode 100644
index 0000000..cdf31d3
--- /dev/null
+++ b/sys/sys/mount.h
@@ -0,0 +1,637 @@
+/* $OpenBSD: mount.h,v 1.147 2020/01/18 08:40:19 visa Exp $ */
+/* $NetBSD: mount.h,v 1.48 1996/02/18 11:55:47 fvdl Exp $ */
+
+/*
+ * 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.
+ * 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.
+ *
+ * @(#)mount.h 8.15 (Berkeley) 7/14/94
+ */
+
+#ifndef _SYS_MOUNT_H_
+#define _SYS_MOUNT_H_
+
+#include <sys/cdefs.h>
+#ifndef _KERNEL
+#include <sys/ucred.h>
+#endif
+#include <sys/queue.h>
+#include <sys/rwlock.h>
+
+typedef struct { int32_t val[2]; } fsid_t; /* file system id type */
+
+/*
+ * File identifier.
+ * These are unique per filesystem on a single machine.
+ */
+#define MAXFIDSZ 16
+
+struct fid {
+ u_short fid_len; /* length of data in bytes */
+ u_short fid_reserved; /* force longword alignment */
+ char fid_data[MAXFIDSZ]; /* data (variable length) */
+};
+
+/*
+ * Export arguments for local filesystem mount calls.
+ */
+struct export_args {
+ int ex_flags; /* export related flags */
+ uid_t ex_root; /* mapping for root uid */
+ struct xucred ex_anon; /* mapping for anonymous user */
+ struct sockaddr *ex_addr; /* net address to which exported */
+ int ex_addrlen; /* and the net address length */
+ struct sockaddr *ex_mask; /* mask of valid bits in saddr */
+ int ex_masklen; /* and the smask length */
+};
+
+/*
+ * Arguments to mount UFS-based filesystems
+ */
+struct ufs_args {
+ char *fspec; /* block special device to mount */
+ struct export_args export_info;/* network export information */
+};
+
+/*
+ * Arguments to mount MFS
+ */
+struct mfs_args {
+ char *fspec; /* name to export for statfs */
+ struct export_args export_info;/* if exported MFSes are supported */
+ caddr_t base; /* base of file system in memory */
+ u_long size; /* size of file system */
+};
+
+/*
+ * Arguments to mount ISO 9660 filesystems.
+ */
+struct iso_args {
+ char *fspec; /* block special device to mount */
+ struct export_args export_info;/* network export info */
+ int flags; /* mounting flags, see below */
+ int sess; /* start sector of session */
+};
+
+#define ISOFSMNT_NORRIP 0x00000001 /* disable Rock Ridge Ext.*/
+#define ISOFSMNT_GENS 0x00000002 /* enable generation numbers */
+#define ISOFSMNT_EXTATT 0x00000004 /* enable extended attr. */
+#define ISOFSMNT_NOJOLIET 0x00000008 /* disable Joliet Ext.*/
+#define ISOFSMNT_SESS 0x00000010 /* use iso_args.sess */
+
+/*
+ * Arguments to mount NFS
+ */
+#define NFS_ARGSVERSION 4 /* change when nfs_args changes */
+struct nfs_args {
+ int version; /* args structure version number */
+ struct sockaddr *addr; /* file server address */
+ int addrlen; /* length of address */
+ int sotype; /* Socket type */
+ int proto; /* and Protocol */
+ u_char *fh; /* File handle to be mounted */
+ int fhsize; /* Size, in bytes, of fh */
+ int flags; /* flags */
+ int wsize; /* write size in bytes */
+ int rsize; /* read size in bytes */
+ int readdirsize; /* readdir size in bytes */
+ int timeo; /* initial timeout in .1 secs */
+ int retrans; /* times to retry send */
+ int maxgrouplist; /* Max. size of group list */
+ int readahead; /* # of blocks to readahead */
+ int leaseterm; /* Term (sec) of lease */
+ int deadthresh; /* Retrans threshold */
+ char *hostname; /* server's name */
+ int acregmin; /* Attr cache file recently modified */
+ int acregmax; /* ac file not recently modified */
+ int acdirmin; /* ac for dir recently modified */
+ int acdirmax; /* ac for dir not recently modified */
+};
+
+/*
+ * NFS mount option flags
+ */
+#define NFSMNT_RESVPORT 0x00000000 /* always use reserved ports */
+#define NFSMNT_SOFT 0x00000001 /* soft mount (hard is default) */
+#define NFSMNT_WSIZE 0x00000002 /* set write size */
+#define NFSMNT_RSIZE 0x00000004 /* set read size */
+#define NFSMNT_TIMEO 0x00000008 /* set initial timeout */
+#define NFSMNT_RETRANS 0x00000010 /* set number of request retries */
+#define NFSMNT_MAXGRPS 0x00000020 /* set maximum grouplist size */
+#define NFSMNT_INT 0x00000040 /* allow interrupts on hard mount */
+#define NFSMNT_NOCONN 0x00000080 /* Don't Connect the socket */
+#define NFSMNT_NQNFS 0x00000100 /* Use Nqnfs protocol */
+#define NFSMNT_NFSV3 0x00000200 /* Use NFS Version 3 protocol */
+#define NFSMNT_KERB 0x00000400 /* Use Kerberos authentication */
+#define NFSMNT_DUMBTIMR 0x00000800 /* Don't estimate rtt dynamically */
+#define NFSMNT_LEASETERM 0x00001000 /* set lease term (nqnfs) */
+#define NFSMNT_READAHEAD 0x00002000 /* set read ahead */
+#define NFSMNT_DEADTHRESH 0x00004000 /* set dead server retry thresh */
+#define NFSMNT_NOAC 0x00008000 /* disable attribute cache */
+#define NFSMNT_RDIRPLUS 0x00010000 /* Use Readdirplus for V3 */
+#define NFSMNT_READDIRSIZE 0x00020000 /* Set readdir size */
+
+/* Flags valid only in mount syscall arguments */
+#define NFSMNT_ACREGMIN 0x00040000 /* acregmin field valid */
+#define NFSMNT_ACREGMAX 0x00080000 /* acregmax field valid */
+#define NFSMNT_ACDIRMIN 0x00100000 /* acdirmin field valid */
+#define NFSMNT_ACDIRMAX 0x00200000 /* acdirmax field valid */
+
+/* Flags valid only in kernel */
+#define NFSMNT_INTERNAL 0xfffc0000 /* Bits set internally */
+#define NFSMNT_HASWRITEVERF 0x00040000 /* Has write verifier for V3 */
+#define NFSMNT_GOTPATHCONF 0x00080000 /* Got the V3 pathconf info */
+#define NFSMNT_GOTFSINFO 0x00100000 /* Got the V3 fsinfo */
+#define NFSMNT_MNTD 0x00200000 /* Mnt server for mnt point */
+#define NFSMNT_DISMINPROG 0x00400000 /* Dismount in progress */
+#define NFSMNT_DISMNT 0x00800000 /* Dismounted */
+#define NFSMNT_SNDLOCK 0x01000000 /* Send socket lock */
+#define NFSMNT_WANTSND 0x02000000 /* Want above */
+#define NFSMNT_RCVLOCK 0x04000000 /* Rcv socket lock */
+#define NFSMNT_WANTRCV 0x08000000 /* Want above */
+#define NFSMNT_WAITAUTH 0x10000000 /* Wait for authentication */
+#define NFSMNT_HASAUTH 0x20000000 /* Has authenticator */
+#define NFSMNT_WANTAUTH 0x40000000 /* Wants an authenticator */
+#define NFSMNT_AUTHERR 0x80000000 /* Authentication error */
+
+/*
+ * Arguments to mount MSDOS filesystems.
+ */
+struct msdosfs_args {
+ char *fspec; /* blocks special holding the fs to mount */
+ struct export_args export_info;
+ /* network export information */
+ uid_t uid; /* uid that owns msdosfs files */
+ gid_t gid; /* gid that owns msdosfs files */
+ mode_t mask; /* mask to be applied for msdosfs perms */
+ int flags; /* see below */
+};
+
+/*
+ * Msdosfs mount options:
+ */
+#define MSDOSFSMNT_SHORTNAME 0x01 /* Force old DOS short names only */
+#define MSDOSFSMNT_LONGNAME 0x02 /* Force Win'95 long names */
+#define MSDOSFSMNT_NOWIN95 0x04 /* Completely ignore Win95 entries */
+
+/*
+ * Arguments to mount ntfs filesystems
+ */
+struct ntfs_args {
+ char *fspec; /* block special device to mount */
+ struct export_args export_info;/* network export information */
+ uid_t uid; /* uid that owns ntfs files */
+ gid_t gid; /* gid that owns ntfs files */
+ mode_t mode; /* mask to be applied for ntfs perms */
+ u_long flag; /* additional flags */
+};
+
+/*
+ * ntfs mount options:
+ */
+#define NTFS_MFLAG_CASEINS 0x00000001
+#define NTFS_MFLAG_ALLNAMES 0x00000002
+
+/* Arguments to mount UDF file systems */
+struct udf_args {
+ char *fspec; /* Block special device to mount */
+ u_int32_t lastblock; /* Special device last block */
+};
+
+/*
+ * Arguments to mount tmpfs file systems
+ */
+#define TMPFS_ARGS_VERSION 1
+struct tmpfs_args {
+ int ta_version;
+
+ /* Size counters. */
+ ino_t ta_nodes_max;
+ off_t ta_size_max;
+
+ /* Root node attributes. */
+ uid_t ta_root_uid;
+ gid_t ta_root_gid;
+ mode_t ta_root_mode;
+};
+
+/*
+ * Arguments to mount fusefs filesystems
+ */
+struct fusefs_args {
+ char *name;
+ int fd;
+ int max_read;
+
+ /*
+ * FUSE does not allow the file system to be accessed by other users
+ * unless this option is specified. This is to prevent unintentional
+ * denial of service to other users if the file system is not
+ * responding. e.g. user executes df(1) or cron job that scans mounted
+ * file systems.
+ */
+ int allow_other;
+};
+
+/*
+ * file system statistics
+ */
+
+#define MFSNAMELEN 16 /* length of fs type name, including nul */
+#define MNAMELEN 90 /* length of buffer for returned name */
+
+/* per-filesystem mount options */
+union mount_info {
+ struct ufs_args ufs_args;
+ struct mfs_args mfs_args;
+ struct nfs_args nfs_args;
+ struct iso_args iso_args;
+ struct msdosfs_args msdosfs_args;
+ struct ntfs_args ntfs_args;
+ struct tmpfs_args tmpfs_args;
+ char __align[160]; /* 64-bit alignment and room to grow */
+};
+
+/* new statfs structure with mount options and statvfs fields */
+struct statfs {
+ u_int32_t f_flags; /* copy of mount flags */
+ u_int32_t f_bsize; /* file system block size */
+ u_int32_t f_iosize; /* optimal transfer block size */
+
+ /* unit is f_bsize */
+ u_int64_t f_blocks; /* total data blocks in file system */
+ u_int64_t f_bfree; /* free blocks in fs */
+ int64_t f_bavail; /* free blocks avail to non-superuser */
+
+ u_int64_t f_files; /* total file nodes in file system */
+ u_int64_t f_ffree; /* free file nodes in fs */
+ int64_t f_favail; /* free file nodes avail to non-root */
+
+ u_int64_t f_syncwrites; /* count of sync writes since mount */
+ u_int64_t f_syncreads; /* count of sync reads since mount */
+ u_int64_t f_asyncwrites; /* count of async writes since mount */
+ u_int64_t f_asyncreads; /* count of async reads since mount */
+
+ fsid_t f_fsid; /* file system id */
+ u_int32_t f_namemax; /* maximum filename length */
+ uid_t f_owner; /* user that mounted the file system */
+ u_int64_t f_ctime; /* last mount [-u] time */
+
+ char f_fstypename[MFSNAMELEN]; /* fs type name */
+ char f_mntonname[MNAMELEN]; /* directory on which mounted */
+ char f_mntfromname[MNAMELEN]; /* mounted file system */
+ char f_mntfromspec[MNAMELEN]; /* special for mount request */
+ union mount_info mount_info; /* per-filesystem mount options */
+};
+
+
+/*
+ * File system types.
+ */
+#define MOUNT_FFS "ffs" /* UNIX "Fast" Filesystem */
+#define MOUNT_UFS MOUNT_FFS /* for compatibility */
+#define MOUNT_NFS "nfs" /* Network Filesystem */
+#define MOUNT_MFS "mfs" /* Memory Filesystem */
+#define MOUNT_MSDOS "msdos" /* MSDOS Filesystem */
+#define MOUNT_AFS "afs" /* Andrew Filesystem */
+#define MOUNT_CD9660 "cd9660" /* ISO9660 (aka CDROM) Filesystem */
+#define MOUNT_EXT2FS "ext2fs" /* Second Extended Filesystem */
+#define MOUNT_NCPFS "ncpfs" /* NetWare Network File System */
+#define MOUNT_NTFS "ntfs" /* NTFS */
+#define MOUNT_UDF "udf" /* UDF */
+#define MOUNT_TMPFS "tmpfs" /* tmpfs */
+#define MOUNT_FUSEFS "fuse" /* FUSE */
+
+/*
+ * Structure per mounted file system. Each mounted file system has an
+ * array of operations and an instance record. The file systems are
+ * put on a doubly linked list.
+ */
+struct mount {
+ TAILQ_ENTRY(mount) mnt_list; /* mount list */
+ SLIST_ENTRY(mount) mnt_dounmount; /* unmount work queue */
+ const struct vfsops *mnt_op; /* operations on fs */
+ struct vfsconf *mnt_vfc; /* configuration info */
+ struct vnode *mnt_vnodecovered; /* vnode we mounted on */
+ struct vnode *mnt_syncer; /* syncer vnode */
+ TAILQ_HEAD(, vnode) mnt_vnodelist; /* list of vnodes this mount */
+ struct rwlock mnt_lock; /* mount structure lock */
+ int mnt_flag; /* flags */
+ struct statfs mnt_stat; /* cache of filesystem stats */
+ void *mnt_data; /* private data */
+};
+
+/*
+ * Mount flags.
+ *
+ * Unmount uses MNT_FORCE flag.
+ */
+#define MNT_RDONLY 0x00000001 /* read only filesystem */
+#define MNT_SYNCHRONOUS 0x00000002 /* file system written synchronously */
+#define MNT_NOEXEC 0x00000004 /* can't exec from filesystem */
+#define MNT_NOSUID 0x00000008 /* don't honor setuid bits on fs */
+#define MNT_NODEV 0x00000010 /* don't interpret special files */
+#define MNT_NOPERM 0x00000020 /* don't enforce permission checks */
+#define MNT_ASYNC 0x00000040 /* file system written asynchronously */
+#define MNT_WXALLOWED 0x00000800 /* filesystem allows W|X mappings */
+
+/*
+ * exported mount flags.
+ */
+#define MNT_EXRDONLY 0x00000080 /* exported read only */
+#define MNT_EXPORTED 0x00000100 /* file system is exported */
+#define MNT_DEFEXPORTED 0x00000200 /* exported to the world */
+#define MNT_EXPORTANON 0x00000400 /* use anon uid mapping for everyone */
+
+/*
+ * Flags set by internal operations.
+ */
+#define MNT_LOCAL 0x00001000 /* filesystem is stored locally */
+#define MNT_QUOTA 0x00002000 /* quotas are enabled on filesystem */
+#define MNT_ROOTFS 0x00004000 /* identifies the root filesystem */
+
+/*
+ * Extra post 4.4BSD-lite2 mount flags.
+ */
+#define MNT_NOATIME 0x00008000 /* don't update access times on fs */
+
+/*
+ * Mask of flags that are visible to statfs()
+ */
+#define MNT_VISFLAGMASK 0x0400ffff
+
+#define MNT_BITS \
+ "\20\001RDONLY\002SYNCHRONOUS\003NOEXEC\004NOSUID\005NODEV\006NOPERM" \
+ "\007ASYNC\010EXRDONLY\011EXPORTED\012DEFEXPORTED\013EXPORTANON" \
+ "\014WXALLOWED\015LOCAL\016QUOTA\017ROOTFS\020NOATIME"
+
+/*
+ * filesystem control flags.
+ */
+#define MNT_UPDATE 0x00010000 /* not a real mount, just an update */
+#define MNT_DELEXPORT 0x00020000 /* delete export host lists */
+#define MNT_RELOAD 0x00040000 /* reload filesystem data */
+#define MNT_FORCE 0x00080000 /* force unmount or readonly change */
+#define MNT_STALLED 0x00100000 /* filesystem stalled */
+#define MNT_SWAPPABLE 0x00200000 /* filesystem can be used for swap */
+#define MNT_WANTRDWR 0x02000000 /* want upgrade to read/write */
+#define MNT_SOFTDEP 0x04000000 /* soft dependencies being done */
+#define MNT_DOOMED 0x08000000 /* device behind filesystem is gone */
+
+#ifdef _KERNEL
+#define MNT_OP_FLAGS (MNT_UPDATE | MNT_RELOAD | MNT_FORCE | MNT_WANTRDWR)
+#endif
+
+/*
+ * Flags for various system call interfaces.
+ *
+ * waitfor flags to vfs_sync() and getfsstat()
+ */
+#define MNT_WAIT 1 /* synchronously wait for I/O to complete */
+#define MNT_NOWAIT 2 /* start all I/O, but do not wait for it */
+#define MNT_LAZY 3 /* push data not written by filesystem syncer */
+
+/*
+ * Generic file handle
+ */
+struct fhandle {
+ fsid_t fh_fsid; /* File system id of mount point */
+ struct fid fh_fid; /* File sys specific id */
+};
+typedef struct fhandle fhandle_t;
+
+/*
+ * Sysctl CTL_VFS definitions.
+ *
+ * Second level identifier specifies which filesystem. Second level
+ * identifier VFS_GENERIC returns information about all filesystems.
+ */
+#define VFS_GENERIC 0 /* generic filesystem information */
+/*
+ * Third level identifiers for VFS_GENERIC are given below; third
+ * level identifiers for specific filesystems are given in their
+ * mount specific header files.
+ */
+#define VFS_MAXTYPENUM 1 /* int: highest defined filesystem type */
+#define VFS_CONF 2 /* struct: vfsconf for filesystem given
+ as next argument */
+#define VFS_BCACHESTAT 3 /* struct: buffer cache statistics given
+ as next argument */
+#define CTL_VFSGENCTL_NAMES { \
+ { 0, 0 }, \
+ { "maxtypenum", CTLTYPE_INT }, \
+ { "conf", CTLTYPE_NODE }, \
+ { "bcachestat", CTLTYPE_STRUCT } \
+}
+
+/*
+ * Filesystem configuration information. One of these exists for each
+ * type of filesystem supported by the kernel. These are searched at
+ * mount time to identify the requested filesystem.
+ */
+struct vfsconf {
+ const struct vfsops *vfc_vfsops; /* filesystem operations vector */
+ char vfc_name[MFSNAMELEN]; /* filesystem type name */
+ int vfc_typenum; /* historic filesystem type number */
+ u_int vfc_refcount; /* number mounted of this type */
+ int vfc_flags; /* permanent flags */
+ size_t vfc_datasize; /* size of data args */
+};
+
+/* buffer cache statistics */
+struct bcachestats {
+ int64_t numbufs; /* number of buffers allocated */
+ int64_t numbufpages; /* number of pages in buffer cache */
+ int64_t numdirtypages; /* number of dirty free pages */
+ int64_t numcleanpages; /* number of clean free pages */
+ int64_t pendingwrites; /* number of pending writes */
+ int64_t pendingreads; /* number of pending reads */
+ int64_t numwrites; /* total writes started */
+ int64_t numreads; /* total reads started */
+ int64_t cachehits; /* total reads found in cache */
+ int64_t busymapped; /* number of busy and mapped buffers */
+ int64_t dmapages; /* dma reachable pages in buffer cache */
+ int64_t highpages; /* pages above dma region */
+ int64_t delwribufs; /* delayed write buffers */
+ int64_t kvaslots; /* kva slots total */
+ int64_t kvaslots_avail; /* available kva slots */
+ int64_t highflips; /* total flips to above DMA */
+ int64_t highflops; /* total failed flips to above DMA */
+ int64_t dmaflips; /* total flips from high to DMA */
+};
+#ifdef _KERNEL
+extern struct bcachestats bcstats;
+extern long buflowpages, bufhighpages, bufbackpages;
+#define BUFPAGES_DEFICIT (((buflowpages - bcstats.numbufpages) < 0) ? 0 \
+ : buflowpages - bcstats.numbufpages)
+#define BUFPAGES_INACT (((bcstats.numcleanpages - buflowpages) < 0) ? 0 \
+ : bcstats.numcleanpages - buflowpages)
+extern int bufcachepercent;
+extern void bufadjust(int);
+struct uvm_constraint_range;
+extern int bufbackoff(struct uvm_constraint_range*, long);
+
+/*
+ * Operations supported on mounted file system.
+ */
+struct nameidata;
+struct mbuf;
+
+extern int maxvfsconf; /* highest defined filesystem type */
+
+struct vfsops {
+ int (*vfs_mount)(struct mount *mp, const char *path,
+ void *data,
+ struct nameidata *ndp, struct proc *p);
+ int (*vfs_start)(struct mount *mp, int flags,
+ struct proc *p);
+ int (*vfs_unmount)(struct mount *mp, int mntflags,
+ struct proc *p);
+ int (*vfs_root)(struct mount *mp, struct vnode **vpp);
+ int (*vfs_quotactl)(struct mount *mp, int cmds, uid_t uid,
+ caddr_t arg, struct proc *p);
+ int (*vfs_statfs)(struct mount *mp, struct statfs *sbp,
+ struct proc *p);
+ int (*vfs_sync)(struct mount *mp, int waitfor, int stall,
+ struct ucred *cred, struct proc *p);
+ int (*vfs_vget)(struct mount *mp, ino_t ino,
+ struct vnode **vpp);
+ int (*vfs_fhtovp)(struct mount *mp, struct fid *fhp,
+ struct vnode **vpp);
+ int (*vfs_vptofh)(struct vnode *vp, struct fid *fhp);
+ int (*vfs_init)(struct vfsconf *);
+ int (*vfs_sysctl)(int *, u_int, void *, size_t *, void *,
+ size_t, struct proc *);
+ int (*vfs_checkexp)(struct mount *mp, struct mbuf *nam,
+ int *extflagsp, struct ucred **credanonp);
+};
+
+#define VFS_MOUNT(MP, PATH, DATA, NDP, P) \
+ (*(MP)->mnt_op->vfs_mount)(MP, PATH, DATA, NDP, P)
+#define VFS_START(MP, FLAGS, P) (*(MP)->mnt_op->vfs_start)(MP, FLAGS, P)
+#define VFS_UNMOUNT(MP, FORCE, P) (*(MP)->mnt_op->vfs_unmount)(MP, FORCE, P)
+#define VFS_ROOT(MP, VPP) (*(MP)->mnt_op->vfs_root)(MP, VPP)
+#define VFS_QUOTACTL(MP,C,U,A,P) (*(MP)->mnt_op->vfs_quotactl)(MP, C, U, A, P)
+#define VFS_STATFS(MP, SBP, P) (*(MP)->mnt_op->vfs_statfs)(MP, SBP, P)
+#define VFS_SYNC(MP, W, S, C, P) (*(MP)->mnt_op->vfs_sync)(MP, W, S, C, P)
+#define VFS_VGET(MP, INO, VPP) (*(MP)->mnt_op->vfs_vget)(MP, INO, VPP)
+#define VFS_FHTOVP(MP, FIDP, VPP) \
+ (*(MP)->mnt_op->vfs_fhtovp)(MP, FIDP, VPP)
+#define VFS_VPTOFH(VP, FIDP) (*(VP)->v_mount->mnt_op->vfs_vptofh)(VP, FIDP)
+#define VFS_CHECKEXP(MP, NAM, EXFLG, CRED) \
+ (*(MP)->mnt_op->vfs_checkexp)(MP, NAM, EXFLG, CRED)
+
+/* Set up the filesystem operations for vnodes. */
+extern const struct vfsops ffs_vfsops;
+extern const struct vfsops mfs_vfsops;
+extern const struct vfsops msdosfs_vfsops;
+extern const struct vfsops nfs_vfsops;
+extern const struct vfsops cd9660_vfsops;
+extern const struct vfsops ext2fs_vfsops;
+extern const struct vfsops ntfs_vfsops;
+extern const struct vfsops udf_vfsops;
+extern const struct vfsops fusefs_vfsops;
+extern const struct vfsops tmpfs_vfsops;
+
+#include <net/radix.h>
+#include <sys/socket.h> /* XXX for AF_MAX */
+
+/*
+ * Network address lookup element
+ */
+struct netcred {
+ struct radix_node netc_rnodes[2];
+ int netc_exflags;
+ int netc_len; /* size of the allocation */
+ struct ucred netc_anon;
+};
+
+/*
+ * Network export information
+ */
+struct netexport {
+ struct netcred ne_defexported; /* Default export */
+ struct radix_node_head *ne_rtable_inet;/* Individual exports */
+};
+
+/*
+ * exported vnode operations
+ */
+int vfs_busy(struct mount *, int);
+#define VB_READ 0x01
+#define VB_WRITE 0x02
+#define VB_NOWAIT 0x04 /* immediately fail on busy lock */
+#define VB_WAIT 0x08 /* sleep fail on busy lock */
+#define VB_DUPOK 0x10 /* permit duplicate mount busying */
+
+int vfs_isbusy(struct mount *);
+struct mount *vfs_mount_alloc(struct vnode *, struct vfsconf *);
+void vfs_mount_free(struct mount *);
+int vfs_mount_foreach_vnode(struct mount *, int (*func)(struct vnode *,
+ void *), void *);
+void vfs_getnewfsid(struct mount *);
+struct mount *vfs_getvfs(fsid_t *);
+int vfs_mountedon(struct vnode *);
+int vfs_rootmountalloc(char *, char *, struct mount **);
+void vfs_unbusy(struct mount *);
+extern TAILQ_HEAD(mntlist, mount) mountlist;
+int vfs_stall(struct proc *, int);
+void vfs_stall_barrier(void);
+
+struct mount *getvfs(fsid_t *); /* return vfs given fsid */
+ /* process mount export info */
+int vfs_export(struct mount *, struct netexport *, struct export_args *);
+ /* lookup host in fs export list */
+struct netcred *vfs_export_lookup(struct mount *, struct netexport *,
+ struct mbuf *);
+int vfs_allocate_syncvnode(struct mount *);
+int speedup_syncer(void);
+
+int vfs_syncwait(struct proc *, int); /* sync and wait for complete */
+void vfs_shutdown(struct proc *); /* unmount and sync file systems */
+int dounmount(struct mount *, int, struct proc *);
+void vfsinit(void);
+struct vfsconf *vfs_byname(const char *);
+struct vfsconf *vfs_bytypenum(int);
+#else /* _KERNEL */
+__BEGIN_DECLS
+int fstatfs(int, struct statfs *);
+int getfh(const char *, fhandle_t *);
+int getfsstat(struct statfs *, size_t, int);
+int getmntinfo(struct statfs **, int);
+int mount(const char *, const char *, int, void *);
+int statfs(const char *, struct statfs *);
+int unmount(const char *, int);
+#if __BSD_VISIBLE
+struct stat;
+int fhopen(const fhandle_t *, int);
+int fhstat(const fhandle_t *, struct stat *);
+int fhstatfs(const fhandle_t *, struct statfs *);
+#endif /* __BSD_VISIBLE */
+__END_DECLS
+#endif /* _KERNEL */
+#endif /* !_SYS_MOUNT_H_ */
diff --git a/sys/sys/mplock.h b/sys/sys/mplock.h
new file mode 100644
index 0000000..34f2f97
--- /dev/null
+++ b/sys/sys/mplock.h
@@ -0,0 +1,75 @@
+/* $OpenBSD: mplock.h,v 1.13 2019/04/23 13:35:12 visa Exp $ */
+
+/*
+ * Copyright (c) 2004 Niklas Hallqvist. 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.
+ */
+
+#ifndef _MPLOCK_H_
+#define _MPLOCK_H_
+
+#include <machine/mplock.h>
+
+#ifdef __USE_MI_MPLOCK
+
+#include <sys/_lock.h>
+
+struct __mp_lock_cpu {
+ u_int mplc_ticket;
+ u_int mplc_depth;
+};
+
+struct __mp_lock {
+ struct __mp_lock_cpu mpl_cpus[MAXCPUS];
+ volatile u_int mpl_ticket;
+ u_int mpl_users;
+#ifdef WITNESS
+ struct lock_object mpl_lock_obj;
+#endif
+};
+
+void ___mp_lock_init(struct __mp_lock *, const struct lock_type *);
+void __mp_lock(struct __mp_lock *);
+void __mp_unlock(struct __mp_lock *);
+int __mp_release_all(struct __mp_lock *);
+int __mp_release_all_but_one(struct __mp_lock *);
+void __mp_acquire_count(struct __mp_lock *, int);
+int __mp_lock_held(struct __mp_lock *, struct cpu_info *);
+
+#ifdef WITNESS
+
+#define __mp_lock_init(mpl) do { \
+ static const struct lock_type __lock_type = { .lt_name = #mpl };\
+ ___mp_lock_init((mpl), &__lock_type); \
+} while (0)
+
+#else /* WITNESS */
+
+#define __mp_lock_init(mpl) ___mp_lock_init((mpl), NULL)
+
+#endif /* WITNESS */
+
+#endif /* __USE_MI_MPLOCK */
+
+extern struct __mp_lock kernel_lock;
+
+#endif /* !_MPLOCK_H */
diff --git a/sys/sys/msg.h b/sys/sys/msg.h
new file mode 100644
index 0000000..96a4a0c
--- /dev/null
+++ b/sys/sys/msg.h
@@ -0,0 +1,177 @@
+/* $OpenBSD: msg.h,v 1.19 2014/11/23 04:31:42 guenther Exp $ */
+/* $NetBSD: msg.h,v 1.9 1996/02/09 18:25:18 christos Exp $ */
+
+/*
+ * SVID compatible msg.h file
+ *
+ * Author: Daniel Boulet
+ *
+ * Copyright 1993 Daniel Boulet and RTMX Inc.
+ *
+ * This system call was implemented by Daniel Boulet under contract from RTMX.
+ *
+ * Redistribution and use in source forms, with and without modification,
+ * are permitted provided that this entire comment appears intact.
+ *
+ * Redistribution in binary form may occur without any restrictions.
+ * Obviously, it would be nice if you gave credit where credit is due
+ * but requiring it would be too onerous.
+ *
+ * This software is provided ``AS IS'' without any warranties of any kind.
+ */
+
+#ifndef _SYS_MSG_H_
+#define _SYS_MSG_H_
+
+#include <sys/ipc.h>
+
+/*
+ * The MSG_NOERROR identifier value, the msqid_ds struct and the msg struct
+ * are as defined by the SV API Intel 386 Processor Supplement.
+ */
+
+#define MSG_NOERROR 010000 /* don't complain about too long msgs */
+
+struct msqid_ds {
+ struct ipc_perm msg_perm; /* msg queue permission bits */
+ struct msg *msg_first; /* first message in the queue */
+ struct msg *msg_last; /* last message in the queue */
+ unsigned long msg_cbytes; /* number of bytes in use on the queue */
+ unsigned long msg_qnum; /* number of msgs in the queue */
+ unsigned long msg_qbytes; /* max # of bytes on the queue */
+ pid_t msg_lspid; /* pid of last msgsnd() */
+ pid_t msg_lrpid; /* pid of last msgrcv() */
+ time_t msg_stime; /* time of last msgsnd() */
+ long msg_pad1;
+ time_t msg_rtime; /* time of last msgrcv() */
+ long msg_pad2;
+ time_t msg_ctime; /* time of last msgctl() */
+ long msg_pad3;
+ long msg_pad4[4];
+};
+
+#ifdef _KERNEL
+#include <sys/queue.h>
+
+struct msg {
+ long msg_type;
+ size_t msg_len;
+ struct mbuf *msg_data;
+
+ TAILQ_ENTRY(msg) msg_next;
+};
+
+struct que {
+ struct msqid_ds msqid_ds;
+ int que_ix; /* pseudo-index */
+ int que_flags;
+ int que_references;
+
+ TAILQ_ENTRY(que) que_next;
+ TAILQ_HEAD(, msg) que_msgs;
+};
+
+/* for que_flags */
+#define MSGQ_READERS 0x01
+#define MSGQ_WRITERS 0x02
+#define MSGQ_DYING 0x04
+
+#define QREF(q) (q)->que_references++
+
+#define QRELE(q) do { \
+ if (--(q)->que_references == 0 && (q)->que_flags & MSGQ_DYING) \
+ wakeup_one(&(q)->que_references); \
+} while (0)
+#endif
+
+/*
+ * Structure describing a message. The SVID doesn't suggest any
+ * particular name for this structure. There is a reference in the
+ * msgop man page that reads "The structure mymsg is an example of what
+ * this user defined buffer might look like, and includes the following
+ * members:". This sentence is followed by two lines equivalent
+ * to the mtype and mtext field declarations below. It isn't clear
+ * if "mymsg" refers to the name of the structure type or the name of an
+ * instance of the structure...
+ */
+struct mymsg {
+ long mtype; /* message type (+ve integer) */
+ char mtext[1]; /* message body */
+};
+
+
+#ifdef _KERNEL
+/*
+ * Based on the configuration parameters described in an SVR2 (yes, two)
+ * config(1m) man page.
+ *
+ * Each message is broken up and stored in segments that are msgssz bytes
+ * long. For efficiency reasons, this should be a power of two. Also,
+ * it doesn't make sense if it is less than 8 or greater than about 256.
+ * Consequently, msginit in kern/sysv_msg.c checks that msgssz is a power of
+ * two between 8 and 1024 inclusive (and panic's if it isn't).
+ */
+struct msginfo {
+ int msgmax, /* max chars in a message */
+ msgmni, /* max message queue identifiers */
+ msgmnb, /* max chars in a queue */
+ msgtql, /* max messages in system */
+ msgssz, /* size of a message segment (see notes above) */
+ msgseg; /* number of message segments */
+};
+#ifdef SYSVMSG
+extern struct msginfo msginfo;
+#endif
+
+int sysctl_sysvmsg(int *, u_int, void *, size_t *);
+
+struct msg_sysctl_info {
+ struct msginfo msginfo;
+ struct msqid_ds msgids[1];
+};
+
+#ifndef MSGSSZ
+#define MSGSSZ 8 /* Each segment must be 2^N long */
+#endif
+#ifndef MSGSEG
+#define MSGSEG 2048 /* must be less than 32767 */
+#endif
+#undef MSGMAX /* ALWAYS compute MSGMAX! */
+#define MSGMAX (MSGSSZ*MSGSEG)
+#ifndef MSGMNB
+#define MSGMNB 2048 /* max # of bytes in a queue */
+#endif
+#ifndef MSGMNI
+#define MSGMNI 40
+#endif
+#ifndef MSGTQL
+#define MSGTQL 40
+#endif
+
+/*
+ * macros to convert between msqid_ds's and msqid's.
+ * XXX unused, going away
+ */
+#define MSQID(ix,ds) ((ix) & 0xffff | (((ds).msg_perm.seq << 16) & 0xffff0000))
+#define MSQID_IX(id) ((id) & 0xffff)
+#define MSQID_SEQ(id) (((id) >> 16) & 0xffff)
+#endif
+
+
+#ifndef _KERNEL
+__BEGIN_DECLS
+int msgctl(int, int, struct msqid_ds *);
+int msgget(key_t, int);
+int msgsnd(int, const void *, size_t, int);
+int msgrcv(int, void *, size_t, long, int);
+__END_DECLS
+#else
+struct proc;
+
+void msginit(void);
+int msgctl1(struct proc *, int, int, caddr_t,
+ int (*)(const void *, void *, size_t),
+ int (*)(const void *, void *, size_t));
+#endif /* !_KERNEL */
+
+#endif /* !_SYS_MSG_H_ */
diff --git a/sys/sys/msgbuf.h b/sys/sys/msgbuf.h
new file mode 100644
index 0000000..3a53a5a
--- /dev/null
+++ b/sys/sys/msgbuf.h
@@ -0,0 +1,53 @@
+/* $OpenBSD: msgbuf.h,v 1.11 2016/06/23 13:15:21 bluhm Exp $ */
+/* $NetBSD: msgbuf.h,v 1.8 1995/03/26 20:24:27 jtc Exp $ */
+
+/*
+ * Copyright (c) 1981, 1984, 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.
+ *
+ * @(#)msgbuf.h 8.1 (Berkeley) 6/2/93
+ */
+
+struct msgbuf {
+#define MSG_MAGIC 0x063061
+ long msg_magic;
+ long msg_bufx; /* write pointer */
+ long msg_bufr; /* read pointer */
+ long msg_bufs; /* real msg_bufc size (bytes) */
+ long msg_bufl; /* # chars, <= msg_bufs */
+ long msg_bufd; /* number of dropped bytes */
+ char msg_bufc[1]; /* buffer */
+};
+#ifdef _KERNEL
+#define CONSBUFSIZE (16 * 1024) /* console message buffer size */
+extern struct msgbuf *msgbufp;
+extern struct msgbuf *consbufp;
+
+void initmsgbuf(caddr_t buf, size_t bufsize);
+void initconsbuf(void);
+void msgbuf_putchar(struct msgbuf *, const char c);
+#endif
diff --git a/sys/sys/mtio.h b/sys/sys/mtio.h
new file mode 100644
index 0000000..fa7a32b
--- /dev/null
+++ b/sys/sys/mtio.h
@@ -0,0 +1,147 @@
+/* $OpenBSD: mtio.h,v 1.9 2007/06/01 18:44:48 krw Exp $ */
+/* $NetBSD: mtio.h,v 1.14 1997/04/15 06:50:19 lukem 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.
+ * 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.
+ *
+ * @(#)mtio.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _SYS_MTIO_H_
+#define _SYS_MTIO_H_
+
+/*
+ * Structures and definitions for mag tape io control commands
+ */
+
+/* structure for MTIOCTOP - mag tape op command */
+struct mtop {
+ short mt_op; /* operations defined below */
+ int mt_count; /* how many of them */
+};
+
+/* operations */
+#define MTWEOF 0 /* write an end-of-file record */
+#define MTFSF 1 /* forward space file */
+#define MTBSF 2 /* backward space file */
+#define MTFSR 3 /* forward space record */
+#define MTBSR 4 /* backward space record */
+#define MTREW 5 /* rewind */
+#define MTOFFL 6 /* rewind and put the drive offline */
+#define MTNOP 7 /* no operation, sets status only */
+#define MTRETEN 8 /* retension */
+#define MTERASE 9 /* erase entire tape */
+#define MTEOM 10 /* forward to end of media */
+#define MTNBSF 11 /* backward space to beginning of file */
+#define MTCACHE 12 /* enable controller cache */
+#define MTNOCACHE 13 /* disable controller cache */
+#define MTSETBSIZ 14 /* set block size; 0 for variable */
+#define MTSETDNSTY 15 /* set density code for current mode */
+
+/* structure for MTIOCGET - mag tape get status command */
+
+struct mtget {
+ short mt_type; /* type of magtape device */
+/* the following two registers are grossly device dependent */
+ short mt_dsreg; /* ``drive status'' register */
+ short mt_erreg; /* ``error'' register */
+/* end device-dependent registers */
+ short mt_resid; /* residual count */
+ int mt_fileno; /* current file number relative to BOT. */
+ int mt_blkno; /* current block number relative to BOF. */
+ int mt_blksiz; /* current block size */
+ int mt_density; /* current density code */
+ int mt_mblksiz; /* default block size */
+ int mt_mdensity; /* default density code */
+};
+
+/*
+ * Constants for mt_type byte. These are the same
+ * for controllers compatible with the types listed.
+ */
+#define MT_ISTS 0x01 /* TS-11 */
+#define MT_ISHT 0x02 /* TM03 Massbus: TE16, TU45, TU77 */
+#define MT_ISTM 0x03 /* TM11/TE10 Unibus */
+#define MT_ISMT 0x04 /* TM78/TU78 Massbus */
+#define MT_ISUT 0x05 /* SI TU-45 emulation on Unibus */
+#define MT_ISCPC 0x06 /* SUN */
+#define MT_ISAR 0x07 /* SUN */
+#define MT_ISTMSCP 0x08 /* DEC TMSCP protocol (TU81, TK50) */
+#define MT_ISCY 0x09 /* CCI Cipher */
+#define MT_ISCT 0x0a /* HP 1/4 tape */
+#define MT_ISFHP 0x0b /* HP 7980 1/2 tape */
+#define MT_ISEXABYTE 0x0c /* Exabyte */
+#define MT_ISEXA8200 0x0c /* Exabyte EXB-8200 */
+#define MT_ISEXA8500 0x0d /* Exabyte EXB-8500 */
+#define MT_ISVIPER1 0x0e /* Archive Viper-150 */
+#define MT_ISPYTHON 0x0f /* Archive Python (DAT) */
+#define MT_ISHPDAT 0x10 /* HP 35450A DAT drive */
+#define MT_ISWANGTEK 0x11 /* WANGTEK 5150ES */
+#define MT_ISCALIPER 0x12 /* Caliper CP150 */
+#define MT_ISWTEK5099 0x13 /* WANGTEK 5099ES */
+#define MT_ISVIPER2525 0x14 /* Archive Viper 2525 */
+#define MT_ISMFOUR 0x11 /* M4 Data 1/2 9track drive */
+#define MT_ISTK50 0x12 /* DEC SCSI TK50 */
+#define MT_ISMT02 0x13 /* Emulex MT02 SCSI tape controller */
+
+/* bits defined for the mt_dsreg field */
+#define MT_DS_RDONLY 0x10 /* tape mounted readonly */
+#define MT_DS_MOUNTED 0x03 /* tape mounted (for control opens) */
+
+/* mag tape io control commands */
+#define MTIOCTOP _IOW('m', 1, struct mtop) /* do a mag tape op */
+#define MTIOCGET _IOR('m', 2, struct mtget) /* get tape status */
+#define MTIOCIEOT _IO('m', 3) /* ignore EOT error */
+#define MTIOCEEOT _IO('m', 4) /* enable EOT error */
+
+/*
+ * When more SCSI-3 SSC (streaming device) devices are out there
+ * that support the full 32 byte type 2 structure, we'll have to
+ * rethink these ioctls to support all the entities they haul into
+ * the picture (64 bit blocks, logical file record numbers, etc..).
+ */
+#define MTIOCRDSPOS _IOR('m', 5, u_int32_t) /* get logical blk addr */
+#define MTIOCRDHPOS _IOR('m', 6, u_int32_t) /* get hardware blk addr */
+#define MTIOCSLOCATE _IOW('m', 5, u_int32_t) /* seek to logical blk addr */
+#define MTIOCHLOCATE _IOW('m', 6, u_int32_t) /* seek to hardware blk addr */
+
+#ifdef _KERNEL
+/*
+ * minor device number
+ */
+
+#define T_UNIT 003 /* unit selection */
+#define T_NOREWIND 004 /* no rewind on close */
+#define T_DENSEL 030 /* density select */
+#define T_800BPI 000 /* select 800 bpi */
+#define T_1600BPI 010 /* select 1600 bpi */
+#define T_6250BPI 020 /* select 6250 bpi */
+#define T_BADBPI 030 /* undefined selection */
+#endif /* _KERNEL */
+
+#endif /* !_SYS_MTIO_H_ */
diff --git a/sys/sys/mutex.h b/sys/sys/mutex.h
new file mode 100644
index 0000000..22a375a
--- /dev/null
+++ b/sys/sys/mutex.h
@@ -0,0 +1,165 @@
+/* $OpenBSD: mutex.h,v 1.18 2019/04/23 13:35:12 visa Exp $ */
+
+/*
+ * Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
+ *
+ * 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.
+ */
+
+#ifndef _SYS_MUTEX_H_
+#define _SYS_MUTEX_H_
+
+/*
+ * A mutex is:
+ * - owned by a cpu.
+ * - non-recursive.
+ * - spinning.
+ * - not providing mutual exclusion between processes, only cpus.
+ * - providing interrupt blocking when necessary.
+ *
+ * Different mutexes can be nested, but not interleaved. This is ok:
+ * "mtx_enter(foo); mtx_enter(bar); mtx_leave(bar); mtx_leave(foo);"
+ * This is _not_ ok:
+ * "mtx_enter(foo); mtx_enter(bar); mtx_leave(foo); mtx_leave(bar);"
+ */
+
+#include <machine/mutex.h>
+
+#ifdef __USE_MI_MUTEX
+
+#include <sys/_lock.h>
+
+struct mutex {
+ volatile void *mtx_owner;
+ int mtx_wantipl;
+ int mtx_oldipl;
+#ifdef WITNESS
+ struct lock_object mtx_lock_obj;
+#endif
+};
+
+/*
+ * To prevent lock ordering problems with the kernel lock, we need to
+ * make sure we block all interrupts that can grab the kernel lock.
+ * The simplest way to achieve this is to make sure mutexes always
+ * raise the interrupt priority level to the highest level that has
+ * interrupts that grab the kernel lock.
+ */
+#ifdef MULTIPROCESSOR
+#define __MUTEX_IPL(ipl) \
+ (((ipl) > IPL_NONE && (ipl) < IPL_MPFLOOR) ? IPL_MPFLOOR : (ipl))
+#else
+#define __MUTEX_IPL(ipl) (ipl)
+#endif
+
+#ifdef WITNESS
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { NULL, __MUTEX_IPL((ipl)), IPL_NONE, MTX_LO_INITIALIZER(name, flags) }
+#else
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { NULL, __MUTEX_IPL((ipl)), IPL_NONE }
+#endif
+
+void __mtx_init(struct mutex *, int);
+#define _mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl)))
+
+#ifdef DIAGNOSTIC
+#define MUTEX_ASSERT_LOCKED(mtx) do { \
+ if (((mtx)->mtx_owner != curcpu()) && !(panicstr || db_active)) \
+ panic("mutex %p not held in %s", (mtx), __func__); \
+} while (0)
+
+#define MUTEX_ASSERT_UNLOCKED(mtx) do { \
+ if (((mtx)->mtx_owner == curcpu()) && !(panicstr || db_active)) \
+ panic("mutex %p held in %s", (mtx), __func__); \
+} while (0)
+#else
+#define MUTEX_ASSERT_LOCKED(mtx) do { } while (0)
+#define MUTEX_ASSERT_UNLOCKED(mtx) do { } while (0)
+#endif
+
+#define MUTEX_LOCK_OBJECT(mtx) (&(mtx)->mtx_lock_obj)
+#define MUTEX_OLDIPL(mtx) (mtx)->mtx_oldipl
+
+#endif /* __USE_MI_MUTEX */
+
+
+#define MTX_LO_FLAGS(flags) \
+ ((!((flags) & MTX_NOWITNESS) ? LO_WITNESS : 0) | \
+ ((flags) & MTX_DUPOK ? LO_DUPOK : 0) | \
+ LO_INITIALIZED | (LO_CLASS_MUTEX << LO_CLASSSHIFT))
+
+#define __MTX_STRING(x) #x
+#define __MTX_S(x) __MTX_STRING(x)
+#define __MTX_NAME __FILE__ ":" __MTX_S(__LINE__)
+
+#define MTX_LO_INITIALIZER(name, flags) \
+ { .lo_type = &(const struct lock_type){ .lt_name = __MTX_NAME }, \
+ .lo_name = (name), \
+ .lo_flags = MTX_LO_FLAGS(flags) }
+
+#define MTX_NOWITNESS 0x01
+#define MTX_DUPOK 0x02
+
+#define MUTEX_INITIALIZER(ipl) \
+ MUTEX_INITIALIZER_FLAGS(ipl, __MTX_NAME, 0)
+
+/*
+ * Some architectures need to do magic for the ipl, so they need a macro.
+ */
+#ifndef _mtx_init
+void _mtx_init(struct mutex *, int);
+#endif
+
+void mtx_enter(struct mutex *);
+int mtx_enter_try(struct mutex *);
+void mtx_leave(struct mutex *);
+
+#define mtx_init(m, ipl) mtx_init_flags(m, ipl, NULL, 0)
+
+#ifdef WITNESS
+
+void _mtx_init_flags(struct mutex *, int, const char *, int,
+ const struct lock_type *);
+
+#define mtx_init_flags(m, ipl, name, flags) do { \
+ static const struct lock_type __lock_type = { .lt_name = #m }; \
+ _mtx_init_flags(m, ipl, name, flags, &__lock_type); \
+} while (0)
+
+#else /* WITNESS */
+
+#define mtx_init_flags(m, ipl, name, flags) do { \
+ (void)(name); (void)(flags); \
+ _mtx_init(m, ipl); \
+} while (0)
+
+#define _mtx_init_flags(m,i,n,f,t) _mtx_init(m,i)
+
+#endif /* WITNESS */
+
+#if defined(_KERNEL) && defined(DDB)
+
+struct db_mutex {
+ struct cpu_info *mtx_owner;
+ unsigned long mtx_intr_state;
+};
+
+#define DB_MUTEX_INITIALIZER { NULL, 0 }
+
+void db_mtx_enter(struct db_mutex *);
+void db_mtx_leave(struct db_mutex *);
+
+#endif /* _KERNEL && DDB */
+
+#endif
diff --git a/sys/sys/namei.h b/sys/sys/namei.h
new file mode 100644
index 0000000..975dfa9
--- /dev/null
+++ b/sys/sys/namei.h
@@ -0,0 +1,279 @@
+/* $OpenBSD: namei.h,v 1.45 2020/03/19 13:55:20 anton Exp $ */
+/* $NetBSD: namei.h,v 1.11 1996/02/09 18:25:20 christos Exp $ */
+
+/*
+ * Copyright (c) 1985, 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.
+ * 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.
+ *
+ * @(#)namei.h 8.4 (Berkeley) 8/20/94
+ */
+
+#ifndef _SYS_NAMEI_H_
+#define _SYS_NAMEI_H_
+
+#include <sys/queue.h>
+#include <sys/tree.h>
+#include <sys/uio.h>
+
+struct unveil;
+
+/*
+ * Encapsulation of namei parameters.
+ */
+struct nameidata {
+ /*
+ * Arguments to namei/lookup.
+ */
+ const char *ni_dirp; /* pathname pointer */
+ int ni_dirfd; /* dirfd from *at() functions */
+ enum uio_seg ni_segflg; /* location of pathname */
+ /* u_long ni_nameiop; namei operation */
+ /* u_long ni_flags; flags to namei */
+ /* struct proc *ni_proc; process requesting lookup */
+ /*
+ * Arguments to lookup.
+ */
+ /* struct ucred *ni_cred; credentials */
+ struct vnode *ni_startdir; /* starting directory */
+ struct vnode *ni_rootdir; /* logical root directory */
+ uint64_t ni_pledge; /* expected pledge for namei */
+ u_char ni_unveil; /* required unveil flags for namei */
+ /*
+ * Results: returned from/manipulated by lookup
+ */
+ struct vnode *ni_vp; /* vnode of result */
+ struct vnode *ni_dvp; /* vnode of intermediate directory */
+
+ /*
+ * Shared between namei and lookup/commit routines.
+ */
+ size_t ni_pathlen; /* remaining chars in path */
+ char *ni_next; /* next location in pathname */
+ u_long ni_loopcnt; /* count of symlinks encountered */
+ struct unveil *ni_unveil_match; /* last matching unveil component */
+ struct vnode **ni_tvp; /* traversed vnodes */
+ size_t ni_tvpend; /* end of traversed vnode list */
+ size_t ni_tvpsize; /* size of traversed vnode list */
+ int ni_unveil_eacces; /* indicates unveil flag mismatch */
+
+ /*
+ * Lookup parameters: this structure describes the subset of
+ * information from the nameidat satructure that is passed
+ * through the VOP interface.
+ */
+ struct componentname {
+ /*
+ * Arguments to lookup.
+ */
+ u_long cn_nameiop; /* namei operation */
+ u_long cn_flags; /* flags to namei */
+ struct proc *cn_proc; /* process requesting lookup */
+ struct ucred *cn_cred; /* credentials */
+ /*
+ * Shared between lookup and commit routines.
+ */
+ char *cn_pnbuf; /* pathname buffer */
+ char *cn_rpbuf; /* realpath buffer */
+ size_t cn_rpi; /* realpath index */
+ char *cn_nameptr; /* pointer to looked up name */
+ long cn_namelen; /* length of looked up component */
+ long cn_consume; /* chars to consume in lookup() */
+ } ni_cnd;
+};
+
+#ifdef _KERNEL
+/*
+ * namei operations
+ */
+#define LOOKUP 0 /* perform name lookup only */
+#define CREATE 1 /* setup for file creation */
+#define DELETE 2 /* setup for file deletion */
+#define RENAME 3 /* setup for file renaming */
+#define OPMASK 3 /* mask for operation */
+/*
+ * namei operational modifier flags, stored in ni_cnd.flags
+ */
+#define LOCKLEAF 0x0004 /* lock inode on return */
+#define LOCKPARENT 0x0008 /* want parent vnode returned locked */
+#define WANTPARENT 0x0010 /* want parent vnode returned unlocked */
+#define NOCACHE 0x0020 /* name must not be left in cache */
+#define FOLLOW 0x0040 /* follow symbolic links */
+#define NOFOLLOW 0x0000 /* do not follow symbolic links (pseudo) */
+#define MODMASK 0x00fc /* mask of operational modifiers */
+/*
+ * Namei parameter descriptors.
+ *
+ * SAVENAME may be set by either the callers of namei or by VOP_LOOKUP.
+ * If the caller of namei sets the flag (for example execve wants to
+ * know the name of the program that is being executed), then it must
+ * free the buffer. If VOP_LOOKUP sets the flag, then the buffer must
+ * be freed by either the commit routine or the VOP_ABORT routine.
+ * SAVESTART is set only by the callers of namei. It implies SAVENAME
+ * plus the addition of saving the parent directory that contains the
+ * name in ni_startdir. It allows repeated calls to lookup for the
+ * name being sought. The caller is responsible for releasing the
+ * buffer and for vrele'ing ni_startdir.
+ */
+#define NOCROSSMOUNT 0x000100 /* do not cross mount points */
+#define RDONLY 0x000200 /* lookup with read-only semantics */
+#define HASBUF 0x000400 /* has allocated pathname buffer */
+#define SAVENAME 0x000800 /* save pathanme buffer */
+#define SAVESTART 0x001000 /* save starting directory */
+#define ISDOTDOT 0x002000 /* current component name is .. */
+#define MAKEENTRY 0x004000 /* entry is to be added to name cache */
+#define ISLASTCN 0x008000 /* this is last component of pathname */
+#define ISSYMLINK 0x010000 /* symlink needs interpretation */
+#define REALPATH 0x020000 /* save pathname buffer for realpath */
+#define REQUIREDIR 0x080000 /* must be a directory */
+#define STRIPSLASHES 0x100000 /* strip trailing slashes */
+#define PDIRUNLOCK 0x200000 /* vfs_lookup() unlocked parent dir */
+#define BYPASSUNVEIL 0x400000 /* bypass pledgepath check */
+#define KERNELPATH 0x800000 /* access file as kernel, not process */
+
+/*
+ * Initialization of an nameidata structure.
+ */
+void ndinitat(struct nameidata *ndp, u_long op, u_long flags,
+ enum uio_seg segflg, int dirfd, const char *namep, struct proc *p);
+
+#define NDINITAT(ndp, op, flags, segflg, dirfd, namep, p) \
+ ndinitat(ndp, op, flags, segflg, dirfd, namep, p)
+
+#define NDINIT(ndp, op, flags, segflp, namep, p) \
+ ndinitat(ndp, op, flags, segflp, AT_FDCWD, namep, p)
+
+/* Defined for users of NDINIT(). */
+#define AT_FDCWD -100
+#endif
+
+/*
+ * This structure describes the elements in the cache of recent
+ * names looked up by namei.
+ */
+
+#define NAMECACHE_MAXLEN 31 /* maximum name segment length we bother with */
+
+struct namecache {
+ TAILQ_ENTRY(namecache) nc_lru; /* Regular Entry LRU chain */
+ TAILQ_ENTRY(namecache) nc_neg; /* Negative Entry LRU chain */
+ RBT_ENTRY(namecache) n_rbcache; /* Namecache rb tree from vnode */
+ TAILQ_ENTRY(namecache) nc_me; /* ncp's referring to me */
+ struct vnode *nc_dvp; /* vnode of parent of name */
+ u_long nc_dvpid; /* capability number of nc_dvp */
+ struct vnode *nc_vp; /* vnode the name refers to */
+ u_long nc_vpid; /* capability number of nc_vp */
+ char nc_nlen; /* length of name */
+ char nc_name[NAMECACHE_MAXLEN]; /* segment name */
+};
+
+#ifdef _KERNEL
+struct namecache_rb_cache;
+
+int namei(struct nameidata *ndp);
+int vfs_lookup(struct nameidata *ndp);
+int vfs_relookup(struct vnode *dvp, struct vnode **vpp,
+ struct componentname *cnp);
+void cache_tree_init(struct namecache_rb_cache *);
+void cache_purge(struct vnode *);
+int cache_lookup(struct vnode *, struct vnode **, struct componentname *);
+void cache_enter(struct vnode *, struct vnode *, struct componentname *);
+int cache_revlookup(struct vnode *, struct vnode **, char **, char *);
+void nchinit(void);
+struct mount;
+void cache_purgevfs(struct mount *);
+
+int unveil_add(struct proc *, struct nameidata *, const char *);
+void unveil_removevnode(struct vnode *);
+void unveil_free_traversed_vnodes(struct nameidata *);
+ssize_t unveil_find_cover(struct vnode *, struct proc *);
+struct unveil *unveil_lookup(struct vnode *, struct process *, ssize_t *);
+void unveil_start_relative(struct proc *, struct nameidata *, struct vnode *);
+void unveil_check_component(struct proc *, struct nameidata *, struct vnode *);
+int unveil_check_final(struct proc *, struct nameidata *);
+
+extern struct pool namei_pool;
+
+#endif
+
+/*
+ * Stats on usefulness of namei caches.
+ */
+struct nchstats {
+ u_int64_t ncs_goodhits; /* hits that we can really use */
+ u_int64_t ncs_neghits; /* negative hits that we can use */
+ u_int64_t ncs_badhits; /* hits we must drop */
+ u_int64_t ncs_falsehits; /* hits with id mismatch */
+ u_int64_t ncs_miss; /* misses */
+ u_int64_t ncs_long; /* long names that ignore cache */
+ u_int64_t ncs_pass2; /* names found with passes == 2 */
+ u_int64_t ncs_2passes; /* number of times we attempt it */
+ u_int64_t ncs_revhits; /* reverse-cache hits */
+ u_int64_t ncs_revmiss; /* reverse-cache misses */
+ u_int64_t ncs_dothits; /* hits on '.' lookups */
+ u_int64_t ncs_dotdothits; /* hits on '..' lookups */
+};
+
+/* These sysctl names are only really used by sysctl(8) */
+#define KERN_NCHSTATS_GOODHITS 1
+#define KERN_NCHSTATS_NEGHITS 2
+#define KERN_NCHSTATS_BADHITS 3
+#define KERN_NCHSTATS_FALSEHITS 4
+#define KERN_NCHSTATS_MISS 5
+#define KERN_NCHSTATS_LONG 6
+#define KERN_NCHSTATS_PASS2 7
+#define KERN_NCHSTATS_2PASSES 8
+#define KERN_NCHSTATS_REVHITS 9
+#define KERN_NCHSTATS_REVMISS 10
+#define KERN_NCHSTATS_DOTHITS 11
+#define KERN_NCHSTATS_DOTDOTHITS 12
+#define KERN_NCHSTATS_MAXID 13
+
+#define CTL_KERN_NCHSTATS_NAMES { \
+ { 0, 0 }, \
+ { "good_hits", CTLTYPE_QUAD }, \
+ { "negative_hits", CTLTYPE_QUAD }, \
+ { "bad_hits", CTLTYPE_QUAD }, \
+ { "false_hits", CTLTYPE_QUAD }, \
+ { "misses", CTLTYPE_QUAD }, \
+ { "long_names", CTLTYPE_QUAD }, \
+ { "pass2", CTLTYPE_QUAD }, \
+ { "2passes", CTLTYPE_QUAD }, \
+ { "ncs_revhits", CTLTYPE_QUAD }, \
+ { "ncs_revmiss", CTLTYPE_QUAD }, \
+ { "ncs_dothits", CTLTYPE_QUAD }, \
+ { "nch_dotdothits", CTLTYPE_QUAD }, \
+}
+
+/* Unveil flags for namei */
+#define UNVEIL_READ 0x01
+#define UNVEIL_WRITE 0x02
+#define UNVEIL_CREATE 0x04
+#define UNVEIL_EXEC 0x08
+#define UNVEIL_USERSET 0x0F
+#define UNVEIL_INSPECT 0x80
+
+#endif /* !_SYS_NAMEI_H_ */
diff --git a/sys/sys/param.h b/sys/sys/param.h
new file mode 100644
index 0000000..76c5e2f
--- /dev/null
+++ b/sys/sys/param.h
@@ -0,0 +1,223 @@
+/* $OpenBSD: param.h,v 1.130 2020/04/05 06:34:20 deraadt Exp $ */
+
+/*-
+ * Copyright (c) 1982, 1986, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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 _SYS_PARAM_H_
+#define _SYS_PARAM_H_
+
+#define BSD 199306 /* System version (year & month). */
+#define BSD4_3 1
+#define BSD4_4 1
+
+#define OpenBSD 202005 /* OpenBSD version (year & month). */
+#define OpenBSD6_7 1 /* OpenBSD 6.7 */
+
+#include <sys/_null.h>
+
+#ifndef _LOCORE
+#include <sys/types.h>
+#endif
+
+/*
+ * Machine-independent constants (some used in following include files).
+ * Redefined constants are from POSIX 1003.1 limits file.
+ *
+ * MAXCOMLEN should be >= sizeof(ac_comm) (see <acct.h>)
+ * MAXLOGNAME should be >= UT_NAMESIZE (see <utmp.h>)
+ */
+#include <sys/syslimits.h>
+
+#define MAXCOMLEN 16 /* max command name remembered */
+#define MAXINTERP 128 /* max interpreter file name length */
+#define MAXLOGNAME LOGIN_NAME_MAX /* max login name length w/ NUL */
+#define MAXUPRC CHILD_MAX /* max simultaneous processes */
+#define NCARGS ARG_MAX /* max bytes for an exec function */
+#define NGROUPS NGROUPS_MAX /* max number groups */
+#define NOFILE OPEN_MAX /* max open files per process (soft) */
+#define NOFILE_MAX 1024 /* max open files per process (hard) */
+#define NOGROUP 65535 /* marker for empty group set member */
+#define MAXHOSTNAMELEN 256 /* max hostname length w/ NUL */
+
+/* More types and definitions used throughout the kernel. */
+#ifdef _KERNEL
+#include <sys/errno.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+#include <sys/ucred.h>
+#include <sys/uio.h>
+#include <sys/srp.h>
+#endif
+
+/* Signals. */
+#include <sys/signal.h>
+
+/* Machine type dependent parameters. */
+#include <sys/limits.h>
+#include <machine/param.h>
+
+#ifdef _KERNEL
+/*
+ * Priorities. Note that with 32 run queues, differences less than 4 are
+ * insignificant.
+ */
+#define PSWP 0
+#define PVM 4
+#define PINOD 8
+#define PRIBIO 16
+#define PVFS 20
+#endif /* _KERNEL */
+#define PZERO 22 /* No longer magic, shouldn't be here. XXX */
+#ifdef _KERNEL
+#define PSOCK 24
+#define PWAIT 32
+#define PLOCK 36
+#define PPAUSE 40
+#define PUSER 50
+#define MAXPRI 127 /* Priorities range from 0 through MAXPRI. */
+
+#define PRIMASK 0x0ff
+#define PCATCH 0x100 /* OR'd with pri for tsleep to check signals */
+#define PNORELOCK 0x200 /* OR'd with pri for msleep to not reaquire
+ the mutex */
+#endif /* _KERNEL */
+
+#define NODEV (dev_t)(-1) /* non-existent device */
+
+#define ALIGNBYTES _ALIGNBYTES
+#define ALIGN(p) _ALIGN(p)
+#define ALIGNED_POINTER(p,t) _ALIGNED_POINTER(p,t)
+
+/*
+ * File system parameters and macros.
+ *
+ * The file system is made out of blocks of at most MAXBSIZE units, with
+ * smaller units (fragments) only in the last direct block. MAXBSIZE
+ * primarily determines the size of buffers in the buffer pool. It may be
+ * made larger without any effect on existing file systems; however making
+ * it smaller makes some file systems unmountable.
+ */
+#ifdef _KERNEL
+#define MAXPHYS (64 * 1024) /* max raw I/O transfer size */
+#endif /* _KERNEL */
+#define MAXBSIZE (64 * 1024)
+
+#define _DEV_BSHIFT 9 /* log2(DEV_BSIZE) */
+#define DEV_BSIZE (1 << _DEV_BSHIFT)
+#ifdef _KERNEL
+#define DEV_BSHIFT _DEV_BSHIFT
+#define BLKDEV_IOSIZE PAGE_SIZE
+#endif /* _KERNEL */
+
+/* pages to disk blocks */
+#ifndef ctod
+#define ctod(x) ((x) << (PAGE_SHIFT - _DEV_BSHIFT))
+#endif
+#ifndef dtoc
+#define dtoc(x) ((x) >> (PAGE_SHIFT - _DEV_BSHIFT))
+#endif
+
+/* bytes to disk blocks */
+#ifndef btodb
+#define btodb(x) ((x) >> _DEV_BSHIFT)
+#endif
+#ifndef dbtob
+#define dbtob(x) ((x) << _DEV_BSHIFT)
+#endif
+
+/*
+ * MAXPATHLEN defines the longest permissible path length after expanding
+ * symbolic links. It is used to allocate a temporary buffer from the buffer
+ * pool in which to do the name expansion, hence should be a power of two,
+ * and must be less than or equal to MAXBSIZE. MAXSYMLINKS defines the
+ * maximum number of symbolic links that may be expanded in a path name.
+ * It should be set high enough to allow all legitimate uses, but halt
+ * infinite loops reasonably quickly.
+ */
+#define MAXPATHLEN PATH_MAX
+#define MAXSYMLINKS SYMLOOP_MAX
+
+/* Macros to set/clear/test flags. */
+#ifdef _KERNEL
+#define SET(t, f) ((t) |= (f))
+#define CLR(t, f) ((t) &= ~(f))
+#define ISSET(t, f) ((t) & (f))
+#endif /* _KERNEL */
+
+/* Bit map related macros. */
+#define setbit(a,i) ((a)[(i)>>3] |= 1<<((i)&(NBBY-1)))
+#define clrbit(a,i) ((a)[(i)>>3] &= ~(1<<((i)&(NBBY-1))))
+#define isset(a,i) ((a)[(i)>>3] & (1<<((i)&(NBBY-1))))
+#define isclr(a,i) (((a)[(i)>>3] & (1<<((i)&(NBBY-1)))) == 0)
+
+/* Macros for counting and rounding. */
+#ifndef howmany
+#define howmany(x, y) (((x)+((y)-1))/(y))
+#endif
+#define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
+#define powerof2(x) ((((x)-1)&(x))==0)
+
+/* Macros for min/max. */
+#define MIN(a,b) (((a)<(b))?(a):(b))
+#define MAX(a,b) (((a)>(b))?(a):(b))
+
+/* Macros for calculating the offset of a field */
+#if !defined(offsetof) && defined(_KERNEL)
+#if __GNUC_PREREQ__(4, 0)
+#define offsetof(s, e) __builtin_offsetof(s, e)
+#else
+#define offsetof(s, e) ((size_t)&((s *)0)->e)
+#endif
+#endif /* !defined(offsetof) && defined(_KERNEL) */
+
+#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
+
+/*
+ * Scale factor for scaled integers used to count %cpu time and load avgs.
+ *
+ * The number of CPU `tick's that map to a unique `%age' can be expressed
+ * by the formula (1 / (2 ^ (FSHIFT - 11))). The maximum load average that
+ * can be calculated (assuming 32 bits) can be closely approximated using
+ * the formula (2 ^ (2 * (16 - FSHIFT))) for (FSHIFT < 15).
+ *
+ * For the scheduler to maintain a 1:1 mapping of CPU `tick' to `%age',
+ * FSHIFT must be at least 11; this gives us a maximum load avg of ~1024.
+ */
+#define _FSHIFT 11 /* bits to right of fixed binary point */
+#ifdef _KERNEL
+#define FSHIFT _FSHIFT
+#endif
+#define FSCALE (1<<_FSHIFT)
+
+#endif /* !_SYS_PARAM_H_ */
diff --git a/sys/sys/pciio.h b/sys/sys/pciio.h
new file mode 100644
index 0000000..713e798
--- /dev/null
+++ b/sys/sys/pciio.h
@@ -0,0 +1,78 @@
+/* $OpenBSD: pciio.h,v 1.7 2010/09/05 18:14:33 kettenis Exp $ */
+
+/*-
+ * Copyright (c) 1997, Stefan Esser <se@FreeBSD.ORG>
+ * Copyright (c) 1997, 1998, 1999, Kenneth D. Merry <ken@FreeBSD.ORG>
+ * 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 unmodified, 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.
+ *
+ * $FreeBSD: src/sys/sys/pciio.h,v 1.5 1999/12/08 17:44:04 ken Exp $
+ *
+ */
+
+#ifndef _SYS_PCIIO_H_
+#define _SYS_PCIIO_H_
+
+#include <sys/ioccom.h>
+
+struct pcisel {
+ u_int8_t pc_bus; /* bus number */
+ u_int8_t pc_dev; /* device on this bus */
+ u_int8_t pc_func; /* function on this device */
+};
+
+struct pci_io {
+ struct pcisel pi_sel; /* device to operate on */
+ int pi_reg; /* configuration register to examine */
+ int pi_width; /* width (in bytes) of read or write */
+ u_int32_t pi_data; /* data to write or result of read */
+};
+
+struct pci_rom {
+ struct pcisel pr_sel;
+ int pr_romlen;
+ char *pr_rom;
+};
+
+struct pci_vga {
+ struct pcisel pv_sel;
+ int pv_lock;
+ int pv_decode;
+};
+
+#define PCI_VGA_UNLOCK 0x00
+#define PCI_VGA_LOCK 0x01
+#define PCI_VGA_TRYLOCK 0x02
+
+#define PCI_VGA_IO_ENABLE 0x01
+#define PCI_VGA_MEM_ENABLE 0x02
+
+#define PCIOCREAD _IOWR('p', 2, struct pci_io)
+#define PCIOCWRITE _IOWR('p', 3, struct pci_io)
+#define PCIOCGETROMLEN _IOWR('p', 4, struct pci_rom)
+#define PCIOCGETROM _IOWR('p', 5, struct pci_rom)
+#define PCIOCGETVGA _IOWR('p', 6, struct pci_vga)
+#define PCIOCSETVGA _IOWR('p', 7, struct pci_vga)
+#define PCIOCREADMASK _IOWR('p', 8, struct pci_io)
+
+#endif /* !_SYS_PCIIO_H_ */
diff --git a/sys/sys/percpu.h b/sys/sys/percpu.h
new file mode 100644
index 0000000..53a1a88
--- /dev/null
+++ b/sys/sys/percpu.h
@@ -0,0 +1,198 @@
+/* $OpenBSD: percpu.h,v 1.8 2018/08/28 15:15:02 mpi Exp $ */
+
+/*
+ * Copyright (c) 2016 David Gwynne <dlg@openbsd.org>
+ *
+ * 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.
+ */
+
+#ifndef _SYS_PERCPU_H_
+#define _SYS_PERCPU_H_
+
+#ifndef CACHELINESIZE
+#define CACHELINESIZE 64
+#endif
+
+#ifndef __upunused /* this should go in param.h */
+#ifdef MULTIPROCESSOR
+#define __upunused
+#else
+#define __upunused __attribute__((__unused__))
+#endif
+#endif
+
+struct cpumem {
+ void *mem;
+};
+
+struct cpumem_iter {
+ unsigned int cpu;
+} __upunused;
+
+struct counters_ref {
+ uint64_t g;
+ uint64_t *c;
+};
+
+#ifdef _KERNEL
+
+#include <sys/atomic.h>
+
+struct pool;
+
+struct cpumem *cpumem_get(struct pool *);
+void cpumem_put(struct pool *, struct cpumem *);
+
+struct cpumem *cpumem_malloc(size_t, int);
+struct cpumem *cpumem_malloc_ncpus(struct cpumem *, size_t, int);
+void cpumem_free(struct cpumem *, int, size_t);
+
+void *cpumem_first(struct cpumem_iter *, struct cpumem *);
+void *cpumem_next(struct cpumem_iter *, struct cpumem *);
+
+static inline void *
+cpumem_enter(struct cpumem *cm)
+{
+#ifdef MULTIPROCESSOR
+ return (cm[cpu_number()].mem);
+#else
+ return (cm);
+#endif
+}
+
+static inline void
+cpumem_leave(struct cpumem *cm, void *mem)
+{
+ /* KDASSERT? */
+}
+
+#ifdef MULTIPROCESSOR
+
+#define CPUMEM_BOOT_MEMORY(_name, _sz) \
+static struct { \
+ unsigned char mem[_sz]; \
+ struct cpumem cpumem; \
+} __aligned(CACHELINESIZE) _name##_boot_cpumem = { \
+ .cpumem = { _name##_boot_cpumem.mem } \
+}
+
+#define CPUMEM_BOOT_INITIALIZER(_name) \
+ { &_name##_boot_cpumem.cpumem }
+
+#else /* MULTIPROCESSOR */
+
+#define CPUMEM_BOOT_MEMORY(_name, _sz) \
+static struct { \
+ unsigned char mem[_sz]; \
+} __aligned(sizeof(uint64_t)) _name##_boot_cpumem
+
+#define CPUMEM_BOOT_INITIALIZER(_name) \
+ { (struct cpumem *)&_name##_boot_cpumem.mem }
+
+#endif /* MULTIPROCESSOR */
+
+#define CPUMEM_FOREACH(_var, _iter, _cpumem) \
+ for ((_var) = cpumem_first((_iter), (_cpumem)); \
+ (_var) != NULL; \
+ (_var) = cpumem_next((_iter), (_cpumem)))
+
+/*
+ * per cpu counters
+ */
+
+struct cpumem *counters_alloc(unsigned int);
+struct cpumem *counters_alloc_ncpus(struct cpumem *, unsigned int);
+void counters_free(struct cpumem *, unsigned int);
+void counters_read(struct cpumem *, uint64_t *, unsigned int);
+void counters_zero(struct cpumem *, unsigned int);
+
+static inline uint64_t *
+counters_enter(struct counters_ref *ref, struct cpumem *cm)
+{
+ ref->c = cpumem_enter(cm);
+#ifdef MULTIPROCESSOR
+ ref->g = ++(*ref->c); /* make the generation number odd */
+ membar_producer();
+ return (ref->c + 1);
+#else
+ return (ref->c);
+#endif
+}
+
+static inline void
+counters_leave(struct counters_ref *ref, struct cpumem *cm)
+{
+#ifdef MULTIPROCESSOR
+ membar_producer();
+ (*ref->c) = ++ref->g; /* make the generation number even again */
+#endif
+ cpumem_leave(cm, ref->c);
+}
+
+static inline void
+counters_inc(struct cpumem *cm, unsigned int c)
+{
+ struct counters_ref ref;
+ uint64_t *counters;
+
+ counters = counters_enter(&ref, cm);
+ counters[c]++;
+ counters_leave(&ref, cm);
+}
+
+static inline void
+counters_dec(struct cpumem *cm, unsigned int c)
+{
+ struct counters_ref ref;
+ uint64_t *counters;
+
+ counters = counters_enter(&ref, cm);
+ counters[c]--;
+ counters_leave(&ref, cm);
+}
+
+static inline void
+counters_add(struct cpumem *cm, unsigned int c, uint64_t v)
+{
+ struct counters_ref ref;
+ uint64_t *counters;
+
+ counters = counters_enter(&ref, cm);
+ counters[c] += v;
+ counters_leave(&ref, cm);
+}
+
+static inline void
+counters_pkt(struct cpumem *cm, unsigned int c, unsigned int b, uint64_t v)
+{
+ struct counters_ref ref;
+ uint64_t *counters;
+
+ counters = counters_enter(&ref, cm);
+ counters[c]++;
+ counters[b] += v;
+ counters_leave(&ref, cm);
+}
+
+#ifdef MULTIPROCESSOR
+#define COUNTERS_BOOT_MEMORY(_name, _n) \
+ CPUMEM_BOOT_MEMORY(_name, ((_n) + 1) * sizeof(uint64_t))
+#else
+#define COUNTERS_BOOT_MEMORY(_name, _n) \
+ CPUMEM_BOOT_MEMORY(_name, (_n) * sizeof(uint64_t))
+#endif
+
+#define COUNTERS_BOOT_INITIALIZER(_name) CPUMEM_BOOT_INITIALIZER(_name)
+
+#endif /* _KERNEL */
+#endif /* _SYS_PERCPU_H_ */
diff --git a/sys/sys/pipe.h b/sys/sys/pipe.h
new file mode 100644
index 0000000..d23f266
--- /dev/null
+++ b/sys/sys/pipe.h
@@ -0,0 +1,96 @@
+/* $OpenBSD: pipe.h,v 1.24 2020/01/24 11:07:41 anton Exp $ */
+
+/*
+ * Copyright (c) 1996 John S. Dyson
+ * 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 immediately at the beginning of the file, without modification,
+ * 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. Absolutely no warranty of function or purpose is made by the author
+ * John S. Dyson.
+ * 4. This work was done expressly for inclusion into FreeBSD. Other use
+ * is allowed if this notation is included.
+ * 5. Modifications may be freely made to this file if the above conditions
+ * are met.
+ */
+
+#ifndef _SYS_PIPE_H_
+#define _SYS_PIPE_H_
+
+#ifndef _KERNEL
+#include <sys/time.h> /* for struct timespec */
+#include <sys/selinfo.h> /* for struct selinfo */
+#endif /* _KERNEL */
+
+#include <sys/sigio.h> /* for struct sigio_ref */
+
+/*
+ * Pipe buffer size, keep moderate in value, pipes take kva space.
+ */
+#ifndef PIPE_SIZE
+#define PIPE_SIZE 16384
+#endif
+
+#ifndef BIG_PIPE_SIZE
+#define BIG_PIPE_SIZE (64*1024)
+#endif
+
+/*
+ * Pipe buffer information.
+ * Separate in, out, cnt are used to simplify calculations.
+ * Buffered write is active when the buffer.cnt field is set.
+ */
+struct pipebuf {
+ u_int cnt; /* number of chars currently in buffer */
+ u_int in; /* in pointer */
+ u_int out; /* out pointer */
+ u_int size; /* size of buffer */
+ caddr_t buffer; /* kva of buffer */
+};
+
+/*
+ * Bits in pipe_state.
+ */
+#define PIPE_ASYNC 0x004 /* Async? I/O. */
+#define PIPE_WANTR 0x008 /* Reader wants some characters. */
+#define PIPE_WANTW 0x010 /* Writer wants space to put characters. */
+#define PIPE_WANTD 0x020 /* Pipe is wanted to be run-down. */
+#define PIPE_SEL 0x040 /* Pipe has a select active. */
+#define PIPE_EOF 0x080 /* Pipe is in EOF condition. */
+#define PIPE_LOCK 0x100 /* Thread has exclusive I/O access. */
+#define PIPE_LWANT 0x200 /* Thread wants exclusive I/O access. */
+
+/*
+ * Per-pipe data structure.
+ * Two of these are linked together to produce bi-directional pipes.
+ *
+ * Locking:
+ * I immutable after creation
+ * S sigio_lock
+ * p pipe_lock
+ */
+struct pipe {
+ struct rwlock *pipe_lock;
+ struct pipebuf pipe_buffer; /* [p] data storage */
+ struct selinfo pipe_sel; /* [p] for compat with select */
+ struct timespec pipe_atime; /* [p] time of last access */
+ struct timespec pipe_mtime; /* [p] time of last modify */
+ struct timespec pipe_ctime; /* [I] time of status change */
+ struct sigio_ref pipe_sigio; /* [S] async I/O registration */
+ struct pipe *pipe_peer; /* [p] link with other direction */
+ u_int pipe_state; /* [p] pipe status info */
+ int pipe_busy; /* [p] # readers/writers */
+};
+
+#ifdef _KERNEL
+void pipe_init(void);
+#endif /* _KERNEL */
+
+#endif /* !_SYS_PIPE_H_ */
diff --git a/sys/sys/pledge.h b/sys/sys/pledge.h
new file mode 100644
index 0000000..6dce461
--- /dev/null
+++ b/sys/sys/pledge.h
@@ -0,0 +1,147 @@
+/* $OpenBSD: pledge.h,v 1.41 2020/04/05 07:31:45 visa Exp $ */
+
+/*
+ * Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org>
+ * Copyright (c) 2015 Theo de Raadt <deraadt@openbsd.org>
+ *
+ * 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.
+ */
+
+#ifndef _SYS_PLEDGE_H_
+#define _SYS_PLEDGE_H_
+
+#include <sys/cdefs.h>
+
+/*
+ * pledge(2) requests
+ */
+#define PLEDGE_ALWAYS 0xffffffffffffffffULL
+#define PLEDGE_RPATH 0x0000000000000001ULL /* allow open for read */
+#define PLEDGE_WPATH 0x0000000000000002ULL /* allow open for write */
+#define PLEDGE_CPATH 0x0000000000000004ULL /* allow creat, mkdir, unlink etc */
+#define PLEDGE_STDIO 0x0000000000000008ULL /* operate on own pid */
+#define PLEDGE_TMPPATH 0x0000000000000010ULL /* for mk*temp() */
+#define PLEDGE_DNS 0x0000000000000020ULL /* DNS services */
+#define PLEDGE_INET 0x0000000000000040ULL /* AF_INET/AF_INET6 sockets */
+#define PLEDGE_FLOCK 0x0000000000000080ULL /* file locking */
+#define PLEDGE_UNIX 0x0000000000000100ULL /* AF_UNIX sockets */
+#define PLEDGE_ID 0x0000000000000200ULL /* allow setuid, setgid, etc */
+#define PLEDGE_TAPE 0x0000000000000400ULL /* Tape ioctl */
+#define PLEDGE_GETPW 0x0000000000000800ULL /* YP enables if ypbind.lock */
+#define PLEDGE_PROC 0x0000000000001000ULL /* fork, waitpid, etc */
+#define PLEDGE_SETTIME 0x0000000000002000ULL /* able to set/adj time/freq */
+#define PLEDGE_FATTR 0x0000000000004000ULL /* allow explicit file st_* mods */
+#define PLEDGE_PROTEXEC 0x0000000000008000ULL /* allow use of PROT_EXEC */
+#define PLEDGE_TTY 0x0000000000010000ULL /* tty setting */
+#define PLEDGE_SENDFD 0x0000000000020000ULL /* AF_UNIX CMSG fd sending */
+#define PLEDGE_RECVFD 0x0000000000040000ULL /* AF_UNIX CMSG fd receiving */
+#define PLEDGE_EXEC 0x0000000000080000ULL /* execve, child is free of pledge */
+#define PLEDGE_ROUTE 0x0000000000100000ULL /* routing lookups */
+#define PLEDGE_MCAST 0x0000000000200000ULL /* multicast joins */
+#define PLEDGE_VMINFO 0x0000000000400000ULL /* vminfo listings */
+#define PLEDGE_PS 0x0000000000800000ULL /* ps listings */
+#define PLEDGE_DISKLABEL 0x0000000002000000ULL /* disklabels */
+#define PLEDGE_PF 0x0000000004000000ULL /* pf ioctls */
+#define PLEDGE_AUDIO 0x0000000008000000ULL /* audio ioctls */
+#define PLEDGE_DPATH 0x0000000010000000ULL /* mknod & mkfifo */
+#define PLEDGE_DRM 0x0000000020000000ULL /* drm ioctls */
+#define PLEDGE_VMM 0x0000000040000000ULL /* vmm ioctls */
+#define PLEDGE_CHOWN 0x0000000080000000ULL /* chown(2) family */
+#define PLEDGE_CHOWNUID 0x0000000100000000ULL /* allow owner/group changes */
+#define PLEDGE_BPF 0x0000000200000000ULL /* bpf ioctl */
+#define PLEDGE_ERROR 0x0000000400000000ULL /* ENOSYS instead of kill */
+#define PLEDGE_WROUTE 0x0000000800000000ULL /* interface address ioctls */
+#define PLEDGE_UNVEIL 0x0000001000000000ULL /* allow unveil() */
+#define PLEDGE_VIDEO 0x0000002000000000ULL /* video ioctls */
+
+/*
+ * Bits outside PLEDGE_USERSET are used by the kernel itself
+ * to track program behaviours which have been observed.
+ */
+#define PLEDGE_USERSET 0x0fffffffffffffffULL
+#define PLEDGE_YPACTIVE 0x8000000000000000ULL /* YP use detected and allowed */
+
+#ifdef PLEDGENAMES
+static const struct {
+ uint64_t bits;
+ const char *name;
+} pledgenames[] = {
+ { PLEDGE_RPATH, "rpath" },
+ { PLEDGE_WPATH, "wpath" },
+ { PLEDGE_CPATH, "cpath" },
+ { PLEDGE_STDIO, "stdio" },
+ { PLEDGE_TMPPATH, "tmppath" },
+ { PLEDGE_DNS, "dns" },
+ { PLEDGE_INET, "inet" },
+ { PLEDGE_FLOCK, "flock" },
+ { PLEDGE_UNIX, "unix" },
+ { PLEDGE_ID, "id" },
+ { PLEDGE_TAPE, "tape" },
+ { PLEDGE_GETPW, "getpw" },
+ { PLEDGE_PROC, "proc" },
+ { PLEDGE_SETTIME, "settime" },
+ { PLEDGE_FATTR, "fattr" },
+ { PLEDGE_PROTEXEC, "prot_exec" },
+ { PLEDGE_TTY, "tty" },
+ { PLEDGE_SENDFD, "sendfd" },
+ { PLEDGE_RECVFD, "recvfd" },
+ { PLEDGE_EXEC, "exec" },
+ { PLEDGE_ROUTE, "route" },
+ { PLEDGE_MCAST, "mcast" },
+ { PLEDGE_VMINFO, "vminfo" },
+ { PLEDGE_PS, "ps" },
+ { PLEDGE_DISKLABEL, "disklabel" },
+ { PLEDGE_PF, "pf" },
+ { PLEDGE_AUDIO, "audio" },
+ { PLEDGE_DPATH, "dpath" },
+ { PLEDGE_DRM, "drm" },
+ { PLEDGE_VMM, "vmm" },
+ { PLEDGE_CHOWNUID, "chown" },
+ { PLEDGE_BPF, "bpf" },
+ { PLEDGE_ERROR, "error" },
+ { PLEDGE_WROUTE, "wroute" },
+ { PLEDGE_UNVEIL, "unveil" },
+ { PLEDGE_VIDEO, "video" },
+ { 0, NULL },
+};
+#endif
+
+#ifdef _KERNEL
+
+int pledge_syscall(struct proc *, int, uint64_t *);
+int pledge_fail(struct proc *, int, uint64_t);
+
+struct mbuf;
+struct nameidata;
+int pledge_namei(struct proc *, struct nameidata *, char *);
+int pledge_sendfd(struct proc *p, struct file *);
+int pledge_recvfd(struct proc *p, struct file *);
+int pledge_sysctl(struct proc *p, int namelen, int *name, void *new);
+int pledge_chown(struct proc *p, uid_t, gid_t);
+int pledge_adjtime(struct proc *p, const void *v);
+int pledge_sendit(struct proc *p, const void *to);
+int pledge_sockopt(struct proc *p, int set, int level, int optname);
+int pledge_socket(struct proc *p, int domain, unsigned int state);
+int pledge_ioctl(struct proc *p, long com, struct file *);
+int pledge_ioctl_drm(struct proc *p, long com, dev_t device);
+int pledge_ioctl_vmm(struct proc *p, long com);
+int pledge_flock(struct proc *p);
+int pledge_fcntl(struct proc *p, int cmd);
+int pledge_swapctl(struct proc *p);
+int pledge_kill(struct proc *p, pid_t pid);
+int pledge_protexec(struct proc *p, int prot);
+void ppath_destroy(struct process *ps);
+
+#endif /* _KERNEL */
+
+#endif /* _SYS_PLEDGE_H_ */
diff --git a/sys/sys/poll.h b/sys/sys/poll.h
new file mode 100644
index 0000000..30daa17
--- /dev/null
+++ b/sys/sys/poll.h
@@ -0,0 +1,89 @@
+/* $OpenBSD: poll.h,v 1.15 2016/06/07 06:12:37 deraadt Exp $ */
+
+/*
+ * Copyright (c) 1996 Theo de Raadt
+ * 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.
+ */
+
+#ifndef _SYS_POLL_H_
+#define _SYS_POLL_H_
+
+typedef struct pollfd {
+ int fd;
+ short events;
+ short revents;
+} pollfd_t;
+
+typedef unsigned int nfds_t;
+
+#define POLLIN 0x0001
+#define POLLPRI 0x0002
+#define POLLOUT 0x0004
+#define POLLERR 0x0008
+#define POLLHUP 0x0010
+#define POLLNVAL 0x0020
+#define POLLRDNORM 0x0040
+#define POLLNORM POLLRDNORM
+#define POLLWRNORM POLLOUT
+#define POLLRDBAND 0x0080
+#define POLLWRBAND 0x0100
+#ifdef _KERNEL
+#define POLL_NOHUP 0x1000 /* internal use only */
+#endif
+
+#define INFTIM (-1)
+
+#ifndef _KERNEL
+#include <sys/cdefs.h>
+
+#if __BSD_VISIBLE
+#include <sys/_types.h>
+
+#ifndef _SIGSET_T_DEFINED_
+#define _SIGSET_T_DEFINED_
+typedef unsigned int sigset_t;
+#endif
+
+#ifndef _TIME_T_DEFINED_
+#define _TIME_T_DEFINED_
+typedef __time_t time_t;
+#endif
+
+#ifndef _TIMESPEC_DECLARED
+#define _TIMESPEC_DECLARED
+struct timespec {
+ time_t tv_sec; /* seconds */
+ long tv_nsec; /* and nanoseconds */
+};
+#endif
+#endif /* __BSD_VISIBLE */
+
+__BEGIN_DECLS
+int poll(struct pollfd[], nfds_t, int);
+#if __BSD_VISIBLE
+int ppoll(struct pollfd[], nfds_t, const struct timespec *, const sigset_t *);
+#endif /* __BSD_VISIBLE */
+__END_DECLS
+#endif /* _KERNEL */
+
+#endif /* !_SYS_POLL_H_ */
diff --git a/sys/sys/pool.h b/sys/sys/pool.h
new file mode 100644
index 0000000..7f68d50
--- /dev/null
+++ b/sys/sys/pool.h
@@ -0,0 +1,295 @@
+/* $OpenBSD: pool.h,v 1.77 2019/07/19 09:03:03 bluhm Exp $ */
+/* $NetBSD: pool.h,v 1.27 2001/06/06 22:00:17 rafal Exp $ */
+
+/*-
+ * Copyright (c) 1997, 1998, 1999, 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Paul Kranenburg; by Jason R. Thorpe of the Numerical Aerospace
+ * Simulation Facility, NASA Ames Research Center.
+ *
+ * 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.
+ */
+
+#ifndef _SYS_POOL_H_
+#define _SYS_POOL_H_
+
+/*
+ * sysctls.
+ * kern.pool.npools
+ * kern.pool.name.<number>
+ * kern.pool.pool.<number>
+ */
+#define KERN_POOL_NPOOLS 1
+#define KERN_POOL_NAME 2
+#define KERN_POOL_POOL 3
+#define KERN_POOL_CACHE 4 /* global pool cache info */
+#define KERN_POOL_CACHE_CPUS 5 /* all cpus cache info */
+
+struct kinfo_pool {
+ unsigned int pr_size; /* size of a pool item */
+ unsigned int pr_pgsize; /* size of a "page" */
+ unsigned int pr_itemsperpage; /* number of items per "page" */
+ unsigned int pr_minpages; /* same in page units */
+ unsigned int pr_maxpages; /* maximum # of idle pages to keep */
+ unsigned int pr_hardlimit; /* hard limit to number of allocated
+ items */
+
+ unsigned int pr_npages; /* # of pages allocated */
+ unsigned int pr_nout; /* # items currently allocated */
+ unsigned int pr_nitems; /* # items in the pool */
+
+ unsigned long pr_nget; /* # of successful requests */
+ unsigned long pr_nput; /* # of releases */
+ unsigned long pr_nfail; /* # of unsuccessful requests */
+ unsigned long pr_npagealloc; /* # of pages allocated */
+ unsigned long pr_npagefree; /* # of pages released */
+ unsigned int pr_hiwat; /* max # of pages in pool */
+ unsigned long pr_nidle; /* # of idle pages */
+};
+
+struct kinfo_pool_cache {
+ uint64_t pr_ngc; /* # of times a list has been gc'ed */
+ unsigned int pr_len; /* current target for list len */
+ unsigned int pr_nitems; /* # of idle items in the depot */
+ unsigned int pr_contention; /* # of times mtx was busy */
+};
+
+/*
+ * KERN_POOL_CACHE_CPUS provides an array, not a single struct. ie, it
+ * provides struct kinfo_pool_cache_cpu kppc[ncpusfound].
+ */
+struct kinfo_pool_cache_cpu {
+ unsigned int pr_cpu; /* which cpu this cache is on */
+
+ /* counters for times items were handled by the cache */
+ uint64_t pr_nget; /* # of requests */
+ uint64_t pr_nfail; /* # of unsuccessful requests */
+ uint64_t pr_nput; /* # of releases */
+
+ /* counters for times the cache interacted with the pool */
+ uint64_t pr_nlget; /* # of list requests */
+ uint64_t pr_nlfail; /* # of unsuccessful list requests */
+ uint64_t pr_nlput; /* # of list releases */
+};
+
+#if defined(_KERNEL) || defined(_LIBKVM)
+
+#include <sys/queue.h>
+#include <sys/tree.h>
+#include <sys/mutex.h>
+#include <sys/rwlock.h>
+
+struct pool;
+struct pool_request;
+struct pool_lock_ops;
+TAILQ_HEAD(pool_requests, pool_request);
+
+struct pool_allocator {
+ void *(*pa_alloc)(struct pool *, int, int *);
+ void (*pa_free)(struct pool *, void *);
+ size_t pa_pagesz;
+};
+
+/*
+ * The pa_pagesz member encodes the sizes of pages that can be
+ * provided by the allocator, and whether the allocations can be
+ * aligned to their size.
+ *
+ * Page sizes can only be powers of two. Each available page size is
+ * represented by its value set as a bit. e.g., to indicate that an
+ * allocator can provide 16k and 32k pages you initialise pa_pagesz
+ * to (32768 | 16384).
+ *
+ * If the allocator can provide aligned pages the low bit in pa_pagesz
+ * is set. The POOL_ALLOC_ALIGNED macro is provided as a convenience.
+ *
+ * If pa_pagesz is unset (i.e. 0), POOL_ALLOC_DEFAULT will be used
+ * instead.
+ */
+
+#define POOL_ALLOC_ALIGNED 1UL
+#define POOL_ALLOC_SIZE(_sz, _a) ((_sz) | (_a))
+#define POOL_ALLOC_SIZES(_min, _max, _a) \
+ ((_max) | \
+ (((_max) - 1) & ~((_min) - 1)) | (_a))
+
+#define POOL_ALLOC_DEFAULT \
+ POOL_ALLOC_SIZE(PAGE_SIZE, POOL_ALLOC_ALIGNED)
+
+TAILQ_HEAD(pool_pagelist, pool_page_header);
+
+struct pool_cache_item;
+TAILQ_HEAD(pool_cache_lists, pool_cache_item);
+struct cpumem;
+
+union pool_lock {
+ struct mutex prl_mtx;
+ struct rwlock prl_rwlock;
+};
+
+struct pool {
+ union pool_lock pr_lock;
+ const struct pool_lock_ops *
+ pr_lock_ops;
+ SIMPLEQ_ENTRY(pool)
+ pr_poollist;
+ struct pool_pagelist
+ pr_emptypages; /* Empty pages */
+ struct pool_pagelist
+ pr_fullpages; /* Full pages */
+ struct pool_pagelist
+ pr_partpages; /* Partially-allocated pages */
+ struct pool_page_header *
+ pr_curpage;
+ unsigned int pr_size; /* Size of item */
+ unsigned int pr_minitems; /* minimum # of items to keep */
+ unsigned int pr_minpages; /* same in page units */
+ unsigned int pr_maxpages; /* maximum # of idle pages to keep */
+ unsigned int pr_npages; /* # of pages allocated */
+ unsigned int pr_itemsperpage;/* # items that fit in a page */
+ unsigned int pr_slack; /* unused space in a page */
+ unsigned int pr_nitems; /* number of available items in pool */
+ unsigned int pr_nout; /* # items currently allocated */
+ unsigned int pr_hardlimit; /* hard limit to number of allocated
+ items */
+ unsigned int pr_serial; /* unique serial number of the pool */
+ unsigned int pr_pgsize; /* Size of a "page" */
+ vaddr_t pr_pgmask; /* Mask with an item to get a page */
+ struct pool_allocator *
+ pr_alloc; /* backend allocator */
+ const char * pr_wchan; /* tsleep(9) identifier */
+#define PR_WAITOK 0x0001 /* M_WAITOK */
+#define PR_NOWAIT 0x0002 /* M_NOWAIT */
+#define PR_LIMITFAIL 0x0004 /* M_CANFAIL */
+#define PR_ZERO 0x0008 /* M_ZERO */
+#define PR_RWLOCK 0x0010
+#define PR_WANTED 0x0100
+
+ int pr_flags;
+ int pr_ipl;
+
+ RBT_HEAD(phtree, pool_page_header)
+ pr_phtree;
+
+ struct cpumem * pr_cache;
+ unsigned long pr_cache_magic[2];
+ union pool_lock pr_cache_lock;
+ struct pool_cache_lists
+ pr_cache_lists; /* list of idle item lists */
+ u_int pr_cache_nitems; /* # of idle items */
+ u_int pr_cache_items; /* target list length */
+ u_int pr_cache_contention;
+ u_int pr_cache_contention_prev;
+ int pr_cache_tick; /* time idle list was empty */
+ int pr_cache_nout;
+ uint64_t pr_cache_ngc; /* # of times the gc released a list */
+
+ u_int pr_align;
+ u_int pr_maxcolors; /* Cache coloring */
+ int pr_phoffset; /* Offset in page of page header */
+
+ /*
+ * Warning message to be issued, and a per-time-delta rate cap,
+ * if the hard limit is reached.
+ */
+ const char *pr_hardlimit_warning;
+ struct timeval pr_hardlimit_ratecap;
+ struct timeval pr_hardlimit_warning_last;
+
+ /*
+ * pool item requests queue
+ */
+ union pool_lock pr_requests_lock;
+ struct pool_requests
+ pr_requests;
+ unsigned int pr_requesting;
+
+ /*
+ * Instrumentation
+ */
+ unsigned long pr_nget; /* # of successful requests */
+ unsigned long pr_nfail; /* # of unsuccessful requests */
+ unsigned long pr_nput; /* # of releases */
+ unsigned long pr_npagealloc; /* # of pages allocated */
+ unsigned long pr_npagefree; /* # of pages released */
+ unsigned int pr_hiwat; /* max # of pages in pool */
+ unsigned long pr_nidle; /* # of idle pages */
+
+ /* Physical memory configuration. */
+ const struct kmem_pa_mode *
+ pr_crange;
+};
+
+#endif /* _KERNEL || _LIBKVM */
+
+#ifdef _KERNEL
+
+extern struct pool_allocator pool_allocator_single;
+extern struct pool_allocator pool_allocator_multi;
+
+struct pool_request {
+ TAILQ_ENTRY(pool_request) pr_entry;
+ void (*pr_handler)(struct pool *, void *, void *);
+ void *pr_cookie;
+ void *pr_item;
+};
+
+void pool_init(struct pool *, size_t, u_int, int, int,
+ const char *, struct pool_allocator *);
+void pool_cache_init(struct pool *);
+void pool_destroy(struct pool *);
+void pool_setlowat(struct pool *, int);
+void pool_sethiwat(struct pool *, int);
+int pool_sethardlimit(struct pool *, u_int, const char *, int);
+struct uvm_constraint_range; /* XXX */
+void pool_set_constraints(struct pool *,
+ const struct kmem_pa_mode *mode);
+
+void *pool_get(struct pool *, int) __malloc;
+void pool_request_init(struct pool_request *,
+ void (*)(struct pool *, void *, void *), void *);
+void pool_request(struct pool *, struct pool_request *);
+void pool_put(struct pool *, void *);
+void pool_wakeup(struct pool *);
+int pool_reclaim(struct pool *);
+void pool_reclaim_all(void);
+int pool_prime(struct pool *, int);
+
+#ifdef DDB
+/*
+ * Debugging and diagnostic aides.
+ */
+void pool_printit(struct pool *, const char *,
+ int (*)(const char *, ...));
+void pool_walk(struct pool *, int, int (*)(const char *, ...),
+ void (*)(void *, int, int (*)(const char *, ...)));
+#endif
+
+/* the allocator for dma-able memory is a thin layer on top of pool */
+void dma_alloc_init(void);
+void *dma_alloc(size_t size, int flags);
+void dma_free(void *m, size_t size);
+#endif /* _KERNEL */
+
+#endif /* _SYS_POOL_H_ */
diff --git a/sys/sys/proc.h b/sys/sys/proc.h
new file mode 100644
index 0000000..357c0c0
--- /dev/null
+++ b/sys/sys/proc.h
@@ -0,0 +1,655 @@
+/* $OpenBSD: proc.h,v 1.295 2020/04/28 08:29:40 mpi Exp $ */
+/* $NetBSD: proc.h,v 1.44 1996/04/22 01:23:21 christos Exp $ */
+
+/*-
+ * Copyright (c) 1986, 1989, 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)proc.h 8.8 (Berkeley) 1/21/94
+ */
+
+#ifndef _SYS_PROC_H_
+#define _SYS_PROC_H_
+
+#include <machine/proc.h> /* Machine-dependent proc substruct. */
+#include <sys/selinfo.h> /* For struct selinfo */
+#include <sys/syslimits.h> /* For LOGIN_NAME_MAX */
+#include <sys/queue.h>
+#include <sys/timeout.h> /* For struct timeout */
+#include <sys/event.h> /* For struct klist */
+#include <sys/mutex.h> /* For struct mutex */
+#include <sys/resource.h> /* For struct rusage */
+#include <sys/rwlock.h> /* For struct rwlock */
+#include <sys/sigio.h> /* For struct sigio */
+
+#ifdef _KERNEL
+#include <sys/atomic.h>
+#define __need_process
+#endif
+
+/*
+ * One structure allocated per session.
+ */
+struct process;
+struct session {
+ int s_count; /* Ref cnt; pgrps in session. */
+ struct process *s_leader; /* Session leader. */
+ struct vnode *s_ttyvp; /* Vnode of controlling terminal. */
+ struct tty *s_ttyp; /* Controlling terminal. */
+ char s_login[LOGIN_NAME_MAX]; /* Setlogin() name. */
+ pid_t s_verauthppid;
+ uid_t s_verauthuid;
+ struct timeout s_verauthto;
+};
+
+void zapverauth(/* struct session */ void *);
+
+/*
+ * One structure allocated per process group.
+ */
+struct pgrp {
+ LIST_ENTRY(pgrp) pg_hash; /* Hash chain. */
+ LIST_HEAD(, process) pg_members;/* Pointer to pgrp members. */
+ struct session *pg_session; /* Pointer to session. */
+ struct sigiolst pg_sigiolst; /* List of sigio structures. */
+ pid_t pg_id; /* Pgrp id. */
+ int pg_jobc; /* # procs qualifying pgrp for job control */
+};
+
+/*
+ * One structure allocated per emulation.
+ */
+struct exec_package;
+struct proc;
+struct ps_strings;
+struct uvm_object;
+union sigval;
+
+struct emul {
+ char e_name[8]; /* Symbolic name */
+ int *e_errno; /* Errno array */
+ int e_nosys; /* Offset of the nosys() syscall */
+ int e_nsysent; /* Number of system call entries */
+ struct sysent *e_sysent; /* System call array */
+ char **e_syscallnames; /* System call name array */
+ int e_arglen; /* Extra argument size in words */
+ /* Copy arguments on the stack */
+ void *(*e_copyargs)(struct exec_package *, struct ps_strings *,
+ void *, void *);
+ /* Set registers before execution */
+ void (*e_setregs)(struct proc *, struct exec_package *,
+ u_long, register_t *);
+ int (*e_fixup)(struct proc *, struct exec_package *);
+ int (*e_coredump)(struct proc *, void *cookie);
+ char *e_sigcode; /* Start of sigcode */
+ char *e_esigcode; /* End of sigcode */
+ char *e_esigret; /* sigaction RET position */
+ struct uvm_object *e_sigobject; /* shared sigcode object */
+};
+
+/*
+ * time usage: accumulated times in ticks
+ * Once a second, each thread's immediate counts (p_[usi]ticks) are
+ * accumulated into these.
+ */
+struct tusage {
+ struct timespec tu_runtime; /* Realtime. */
+ uint64_t tu_uticks; /* Statclock hits in user mode. */
+ uint64_t tu_sticks; /* Statclock hits in system mode. */
+ uint64_t tu_iticks; /* Statclock hits processing intr. */
+};
+
+/*
+ * Description of a process.
+ *
+ * These structures contain the information needed to manage a thread of
+ * control, known in UN*X as a process; it has references to substructures
+ * containing descriptions of things that the process uses, but may share
+ * with related processes.
+ *
+ * struct process is the higher level process containing information
+ * shared by all threads in a process, while struct proc contains the
+ * run-time information needed by threads.
+ */
+#ifdef __need_process
+struct futex;
+LIST_HEAD(futex_list, futex);
+struct tslpentry;
+TAILQ_HEAD(tslpqueue, tslpentry);
+struct unveil;
+
+/*
+ * Locks used to protect struct members in this file:
+ * a atomic operations
+ * m this process' `ps_mtx'
+ * p this process' `ps_lock'
+ * r rlimit_lock
+ */
+struct process {
+ /*
+ * ps_mainproc is the original thread in the process.
+ * It's only still special for the handling of
+ * some signal and ptrace behaviors that need to be fixed.
+ */
+ struct proc *ps_mainproc;
+ struct ucred *ps_ucred; /* Process owner's identity. */
+
+ LIST_ENTRY(process) ps_list; /* List of all processes. */
+ TAILQ_HEAD(,proc) ps_threads; /* Threads in this process. */
+
+ LIST_ENTRY(process) ps_pglist; /* List of processes in pgrp. */
+ struct process *ps_pptr; /* Pointer to parent process. */
+ LIST_ENTRY(process) ps_sibling; /* List of sibling processes. */
+ LIST_HEAD(, process) ps_children;/* Pointer to list of children. */
+ LIST_ENTRY(process) ps_hash; /* Hash chain. */
+
+ /*
+ * An orphan is the child that has been re-parented to the
+ * debugger as a result of attaching to it. Need to keep
+ * track of them for parent to be able to collect the exit
+ * status of what used to be children.
+ */
+ LIST_ENTRY(process) ps_orphan; /* List of orphan processes. */
+ LIST_HEAD(, process) ps_orphans;/* Pointer to list of orphans. */
+
+ struct sigiolst ps_sigiolst; /* List of sigio structures. */
+ struct sigacts *ps_sigacts; /* Signal actions, state */
+ struct vnode *ps_textvp; /* Vnode of executable. */
+ struct filedesc *ps_fd; /* Ptr to open files structure */
+ struct vmspace *ps_vmspace; /* Address space */
+ pid_t ps_pid; /* Process identifier. */
+
+ struct futex_list ps_ftlist; /* futexes attached to this process */
+ struct tslpqueue ps_tslpqueue; /* [p] queue of threads in thrsleep */
+ struct rwlock ps_lock; /* per-process rwlock */
+ struct mutex ps_mtx; /* per-process mutex */
+
+/* The following fields are all zeroed upon creation in process_new. */
+#define ps_startzero ps_klist
+ struct klist ps_klist; /* knotes attached to this process */
+ u_int ps_flags; /* [a] PS_* flags. */
+ int ps_siglist; /* Signals pending for the process. */
+
+ struct proc *ps_single; /* Single threading to this thread. */
+ u_int ps_singlecount; /* [a] Not yet suspended threads. */
+
+ int ps_traceflag; /* Kernel trace points. */
+ struct vnode *ps_tracevp; /* Trace to vnode. */
+ struct ucred *ps_tracecred; /* Creds for writing trace */
+
+ u_int ps_xexit; /* Exit status for wait */
+ int ps_xsig; /* Stopping or killing signal */
+
+ pid_t ps_oppid; /* Save parent pid during ptrace. */
+ int ps_ptmask; /* Ptrace event mask */
+ struct ptrace_state *ps_ptstat;/* Ptrace state */
+
+ struct rusage *ps_ru; /* sum of stats for dead threads. */
+ struct tusage ps_tu; /* accumulated times. */
+ struct rusage ps_cru; /* sum of stats for reaped children */
+ struct itimerspec ps_timer[3]; /* timers, indexed by ITIMER_* */
+ struct timeout ps_rucheck_to; /* [] resource limit check timer */
+ time_t ps_nextxcpu; /* when to send next SIGXCPU, */
+ /* in seconds of process runtime */
+
+ u_int64_t ps_wxcounter;
+
+ struct unveil *ps_uvpaths; /* unveil vnodes and names */
+ struct unveil *ps_uvpcwd; /* pointer to unveil of cwd, NULL if none */
+ ssize_t ps_uvvcount; /* count of unveil vnodes held */
+ size_t ps_uvncount; /* count of unveil names allocated */
+ int ps_uvshrink; /* do we need to shrink vnode list */
+ int ps_uvdone; /* no more unveil is permitted */
+
+/* End area that is zeroed on creation. */
+#define ps_endzero ps_startcopy
+
+/* The following fields are all copied upon creation in process_new. */
+#define ps_startcopy ps_limit
+ struct plimit *ps_limit; /* [m,r] Process limits. */
+ struct pgrp *ps_pgrp; /* Pointer to process group. */
+ struct emul *ps_emul; /* Emulation information */
+
+ char ps_comm[MAXCOMLEN+1];
+
+ vaddr_t ps_strings; /* User pointers to argv/env */
+ vaddr_t ps_sigcode; /* User pointer to the signal code */
+ vaddr_t ps_sigcoderet; /* User pointer to sigreturn retPC */
+ u_long ps_sigcookie;
+ u_int ps_rtableid; /* Process routing table/domain. */
+ char ps_nice; /* Process "nice" value. */
+
+ struct uprof { /* profile arguments */
+ caddr_t pr_base; /* buffer base */
+ size_t pr_size; /* buffer size */
+ u_long pr_off; /* pc offset */
+ u_int pr_scale; /* pc scaling */
+ } ps_prof;
+
+ u_short ps_acflag; /* Accounting flags. */
+
+ uint64_t ps_pledge;
+ uint64_t ps_execpledge;
+
+ int64_t ps_kbind_cookie;
+ u_long ps_kbind_addr;
+
+/* End area that is copied on creation. */
+#define ps_endcopy ps_refcnt
+ int ps_refcnt; /* Number of references. */
+
+ struct timespec ps_start; /* starting uptime. */
+ struct timeout ps_realit_to; /* real-time itimer trampoline. */
+};
+
+#define ps_session ps_pgrp->pg_session
+#define ps_pgid ps_pgrp->pg_id
+
+#endif /* __need_process */
+
+/*
+ * These flags are kept in ps_flags.
+ */
+#define PS_CONTROLT 0x00000001 /* Has a controlling terminal. */
+#define PS_EXEC 0x00000002 /* Process called exec. */
+#define PS_INEXEC 0x00000004 /* Process is doing an exec right now */
+#define PS_EXITING 0x00000008 /* Process is exiting. */
+#define PS_SUGID 0x00000010 /* Had set id privs since last exec. */
+#define PS_SUGIDEXEC 0x00000020 /* last execve() was set[ug]id */
+#define PS_PPWAIT 0x00000040 /* Parent waits for exec/exit. */
+#define PS_ISPWAIT 0x00000080 /* Is parent of PPWAIT child. */
+#define PS_PROFIL 0x00000100 /* Has started profiling. */
+#define PS_TRACED 0x00000200 /* Being ptraced. */
+#define PS_WAITED 0x00000400 /* Stopped proc was waited for. */
+#define PS_COREDUMP 0x00000800 /* Busy coredumping */
+#define PS_SINGLEEXIT 0x00001000 /* Other threads must die. */
+#define PS_SINGLEUNWIND 0x00002000 /* Other threads must unwind. */
+#define PS_NOZOMBIE 0x00004000 /* No signal or zombie at exit. */
+#define PS_STOPPED 0x00008000 /* Just stopped, need sig to parent. */
+#define PS_SYSTEM 0x00010000 /* No sigs, stats or swapping. */
+#define PS_EMBRYO 0x00020000 /* New process, not yet fledged */
+#define PS_ZOMBIE 0x00040000 /* Dead and ready to be waited for */
+#define PS_NOBROADCASTKILL 0x00080000 /* Process excluded from kill -1. */
+#define PS_PLEDGE 0x00100000 /* Has called pledge(2) */
+#define PS_WXNEEDED 0x00200000 /* Process may violate W^X */
+#define PS_EXECPLEDGE 0x00400000 /* Has exec pledges */
+#define PS_ORPHAN 0x00800000 /* Process is on an orphan list */
+
+#define PS_BITS \
+ ("\20" "\01CONTROLT" "\02EXEC" "\03INEXEC" "\04EXITING" "\05SUGID" \
+ "\06SUGIDEXEC" "\07PPWAIT" "\010ISPWAIT" "\011PROFIL" "\012TRACED" \
+ "\013WAITED" "\014COREDUMP" "\015SINGLEEXIT" "\016SINGLEUNWIND" \
+ "\017NOZOMBIE" "\020STOPPED" "\021SYSTEM" "\022EMBRYO" "\023ZOMBIE" \
+ "\024NOBROADCASTKILL" "\025PLEDGE" "\026WXNEEDED" "\027EXECPLEDGE" \
+ "\028ORPHAN")
+
+
+struct kcov_dev;
+struct lock_list_entry;
+
+struct p_inentry {
+ u_long ie_serial;
+ vaddr_t ie_start;
+ vaddr_t ie_end;
+};
+
+/*
+ * Locks used to protect struct members in this file:
+ * I immutable after creation
+ * s scheduler lock
+ * l read only reference, see lim_read_enter()
+ * o owned (read/modified only) by this thread
+ */
+struct proc {
+ TAILQ_ENTRY(proc) p_runq; /* [s] current run/sleep queue */
+ LIST_ENTRY(proc) p_list; /* List of all threads. */
+
+ struct process *p_p; /* [I] The process of this thread. */
+ TAILQ_ENTRY(proc) p_thr_link; /* Threads in a process linkage. */
+
+ TAILQ_ENTRY(proc) p_fut_link; /* Threads in a futex linkage. */
+ struct futex *p_futex; /* Current sleeping futex. */
+
+ /* substructures: */
+ struct filedesc *p_fd; /* copy of p_p->ps_fd */
+ struct vmspace *p_vmspace; /* [I] copy of p_p->ps_vmspace */
+ struct p_inentry p_spinentry; /* [o] cache for SP check */
+ struct p_inentry p_pcinentry; /* [o] cache for PC check */
+
+ int p_flag; /* P_* flags. */
+ u_char p_spare; /* unused */
+ char p_stat; /* [s] S* process status. */
+ u_char p_runpri; /* [s] Runqueue priority */
+ u_char p_descfd; /* if not 255, fdesc permits this fd */
+
+ pid_t p_tid; /* Thread identifier. */
+ LIST_ENTRY(proc) p_hash; /* Hash chain. */
+
+/* The following fields are all zeroed upon creation in fork. */
+#define p_startzero p_dupfd
+ int p_dupfd; /* Sideways return value from filedescopen. XXX */
+
+ /* scheduling */
+ int p_cpticks; /* Ticks of cpu time. */
+ const volatile void *p_wchan; /* [s] Sleep address. */
+ struct timeout p_sleep_to;/* timeout for tsleep() */
+ const char *p_wmesg; /* [s] Reason for sleep. */
+ fixpt_t p_pctcpu; /* [s] %cpu for this thread */
+ u_int p_slptime; /* [s] Time since last blocked. */
+ u_int p_uticks; /* Statclock hits in user mode. */
+ u_int p_sticks; /* Statclock hits in system mode. */
+ u_int p_iticks; /* Statclock hits processing intr. */
+ struct cpu_info * volatile p_cpu; /* [s] CPU we're running on. */
+
+ struct rusage p_ru; /* Statistics */
+ struct tusage p_tu; /* accumulated times. */
+ struct timespec p_rtime; /* Real time. */
+
+ struct plimit *p_limit; /* [l] read ref. of p_p->ps_limit */
+ struct kcov_dev *p_kd; /* kcov device handle */
+ struct lock_list_entry *p_sleeplocks; /* WITNESS lock tracking */
+
+ int p_siglist; /* Signals arrived but not delivered. */
+
+/* End area that is zeroed on creation. */
+#define p_endzero p_startcopy
+
+/* The following fields are all copied upon creation in fork. */
+#define p_startcopy p_sigmask
+ sigset_t p_sigmask; /* Current signal mask. */
+
+ u_char p_slppri; /* [s] Sleeping priority */
+ u_char p_usrpri; /* [s] Priority based on p_estcpu & ps_nice */
+ u_int p_estcpu; /* [s] Time averaged val of p_cpticks */
+ int p_pledge_syscall; /* Cache of current syscall */
+
+ struct ucred *p_ucred; /* [o] cached credentials */
+ struct sigaltstack p_sigstk; /* sp & on stack state variable */
+
+ u_long p_prof_addr; /* tmp storage for profiling addr until AST */
+ u_long p_prof_ticks; /* tmp storage for profiling ticks until AST */
+
+/* End area that is copied on creation. */
+#define p_endcopy p_addr
+ struct user *p_addr; /* Kernel virtual addr of u-area */
+ struct mdproc p_md; /* Any machine-dependent fields. */
+
+ sigset_t p_oldmask; /* Saved mask from before sigpause */
+ int p_sisig; /* For core dump/debugger XXX */
+ union sigval p_sigval; /* For core dump/debugger XXX */
+ long p_sitrapno; /* For core dump/debugger XXX */
+ int p_sicode; /* For core dump/debugger XXX */
+};
+
+/* Status values. */
+#define SIDL 1 /* Thread being created by fork. */
+#define SRUN 2 /* Currently runnable. */
+#define SSLEEP 3 /* Sleeping on an address. */
+#define SSTOP 4 /* Debugging or suspension. */
+#define SZOMB 5 /* unused */
+#define SDEAD 6 /* Thread is almost gone */
+#define SONPROC 7 /* Thread is currently on a CPU. */
+
+#define P_ZOMBIE(p) ((p)->p_stat == SDEAD)
+#define P_HASSIBLING(p) (TAILQ_FIRST(&(p)->p_p->ps_threads) != (p) || \
+ TAILQ_NEXT((p), p_thr_link) != NULL)
+
+/*
+ * These flags are per-thread and kept in p_flag
+ */
+#define P_INKTR 0x00000001 /* In a ktrace op, don't recurse */
+#define P_PROFPEND 0x00000002 /* SIGPROF needs to be posted */
+#define P_ALRMPEND 0x00000004 /* SIGVTALRM needs to be posted */
+#define P_SIGSUSPEND 0x00000008 /* Need to restore before-suspend mask*/
+#define P_CANTSLEEP 0x00000010 /* insomniac thread */
+#define P_SELECT 0x00000040 /* Selecting; wakeup/waiting danger. */
+#define P_SINTR 0x00000080 /* Sleep is interruptible. */
+#define P_SYSTEM 0x00000200 /* No sigs, stats or swapping. */
+#define P_TIMEOUT 0x00000400 /* Timing out during sleep. */
+#define P_WEXIT 0x00002000 /* Working on exiting. */
+#define P_OWEUPC 0x00008000 /* Owe proc an addupc() at next ast. */
+#define P_SUSPSINGLE 0x00080000 /* Need to stop for single threading. */
+#define P_CONTINUED 0x00800000 /* Proc has continued from a stopped state. */
+#define P_THREAD 0x04000000 /* Only a thread, not a real process */
+#define P_SUSPSIG 0x08000000 /* Stopped from signal. */
+#define P_SOFTDEP 0x10000000 /* Stuck processing softdep worklist */
+#define P_CPUPEG 0x40000000 /* Do not move to another cpu. */
+
+#define P_BITS \
+ ("\20" "\01INKTR" "\02PROFPEND" "\03ALRMPEND" "\04SIGSUSPEND" \
+ "\05CANTSLEEP" "\07SELECT" "\010SINTR" "\012SYSTEM" "\013TIMEOUT" \
+ "\016WEXIT" "\020OWEUPC" "\024SUSPSINGLE" "\027XX" \
+ "\030CONTINUED" "\033THREAD" "\034SUSPSIG" "\035SOFTDEP" "\037CPUPEG")
+
+#define THREAD_PID_OFFSET 100000
+
+#ifdef _KERNEL
+
+struct uidinfo {
+ LIST_ENTRY(uidinfo) ui_hash;
+ uid_t ui_uid;
+ long ui_proccnt; /* proc structs */
+ long ui_lockcnt; /* lockf structs */
+};
+
+struct uidinfo *uid_find(uid_t);
+void uid_release(struct uidinfo *);
+
+/*
+ * We use process IDs <= PID_MAX; PID_MAX + 1 must also fit in a pid_t,
+ * as it is used to represent "no process group".
+ * We set PID_MAX to 99999 to keep it in 5 columns in ps
+ * When exposed to userspace, thread IDs have THREAD_PID_OFFSET
+ * added to keep them from overlapping the PID range. For them,
+ * we use a * a (0 .. 2^n] range for cheapness, picking 'n' such
+ * that 2^n + THREAD_PID_OFFSET and THREAD_PID_OFFSET have
+ * the same number of columns when printed.
+ */
+#define PID_MAX 99999
+#define TID_MASK 0x7ffff
+
+#define NO_PID (PID_MAX+1)
+
+#define SESS_LEADER(pr) ((pr)->ps_session->s_leader == (pr))
+#define SESSHOLD(s) ((s)->s_count++)
+#define SESSRELE(s) do { \
+ if (--(s)->s_count == 0) { \
+ timeout_del(&(s)->s_verauthto); \
+ pool_put(&session_pool, (s)); \
+ } \
+} while (/* CONSTCOND */ 0)
+
+/*
+ * Flags to fork1().
+ */
+#define FORK_FORK 0x00000001
+#define FORK_VFORK 0x00000002
+#define FORK_IDLE 0x00000004
+#define FORK_PPWAIT 0x00000008
+#define FORK_SHAREFILES 0x00000010
+#define FORK_SYSTEM 0x00000020
+#define FORK_NOZOMBIE 0x00000040
+#define FORK_SHAREVM 0x00000080
+#define FORK_PTRACE 0x00000400
+
+#define EXIT_NORMAL 0x00000001
+#define EXIT_THREAD 0x00000002
+#define EXIT_THREAD_NOCHECK 0x00000003
+
+#define TIDHASH(tid) (&tidhashtbl[(tid) & tidhash])
+extern LIST_HEAD(tidhashhead, proc) *tidhashtbl;
+extern u_long tidhash;
+
+#define PIDHASH(pid) (&pidhashtbl[(pid) & pidhash])
+extern LIST_HEAD(pidhashhead, process) *pidhashtbl;
+extern u_long pidhash;
+
+#define PGRPHASH(pgid) (&pgrphashtbl[(pgid) & pgrphash])
+extern LIST_HEAD(pgrphashhead, pgrp) *pgrphashtbl;
+extern u_long pgrphash;
+
+extern struct proc proc0; /* Process slot for swapper. */
+extern struct process process0; /* Process slot for kernel threads. */
+extern int nprocesses, maxprocess; /* Cur and max number of processes. */
+extern int nthreads, maxthread; /* Cur and max number of threads. */
+extern int randompid; /* fork() should create random pid's */
+
+LIST_HEAD(proclist, proc);
+LIST_HEAD(processlist, process);
+extern struct processlist allprocess; /* List of all processes. */
+extern struct processlist zombprocess; /* List of zombie processes. */
+extern struct proclist allproc; /* List of all threads. */
+
+extern struct process *initprocess; /* Process slot for init. */
+extern struct proc *reaperproc; /* Thread slot for reaper. */
+extern struct proc *syncerproc; /* filesystem syncer daemon */
+
+extern struct pool process_pool; /* memory pool for processes */
+extern struct pool proc_pool; /* memory pool for procs */
+extern struct pool rusage_pool; /* memory pool for zombies */
+extern struct pool ucred_pool; /* memory pool for ucreds */
+extern struct pool session_pool; /* memory pool for sessions */
+extern struct pool pgrp_pool; /* memory pool for pgrps */
+
+void freepid(pid_t);
+
+struct process *prfind(pid_t); /* Find process by id. */
+struct process *zombiefind(pid_t); /* Find zombie process by id. */
+struct proc *tfind(pid_t); /* Find thread by id. */
+struct pgrp *pgfind(pid_t); /* Find process group by id. */
+void proc_printit(struct proc *p, const char *modif,
+ int (*pr)(const char *, ...));
+
+int chgproccnt(uid_t uid, int diff);
+void enternewpgrp(struct process *, struct pgrp *, struct session *);
+void enterthispgrp(struct process *, struct pgrp *);
+int inferior(struct process *, struct process *);
+void leavepgrp(struct process *);
+void killjobc(struct process *);
+void preempt(void);
+void procinit(void);
+void setpriority(struct proc *, uint32_t, uint8_t);
+void setrunnable(struct proc *);
+void endtsleep(void *);
+int wakeup_proc(struct proc *, const volatile void *);
+void unsleep(struct proc *);
+void reaper(void *);
+void exit1(struct proc *, int, int, int);
+void exit2(struct proc *);
+int dowait4(struct proc *, pid_t, int *, int, struct rusage *,
+ register_t *);
+void cpu_fork(struct proc *_curp, struct proc *_child, void *_stack,
+ void *_tcb, void (*_func)(void *), void *_arg);
+void cpu_exit(struct proc *);
+void process_initialize(struct process *, struct proc *);
+int fork1(struct proc *_curp, int _flags, void (*_func)(void *),
+ void *_arg, register_t *_retval, struct proc **_newprocp);
+int thread_fork(struct proc *_curp, void *_stack, void *_tcb,
+ pid_t *_tidptr, register_t *_retval);
+int groupmember(gid_t, struct ucred *);
+void dorefreshcreds(struct process *, struct proc *);
+void dosigsuspend(struct proc *, sigset_t);
+
+static inline void
+refreshcreds(struct proc *p)
+{
+ struct process *pr = p->p_p;
+
+ /* this is an unlocked access to ps_ucred, but the result is benign */
+ if (pr->ps_ucred != p->p_ucred)
+ dorefreshcreds(pr, p);
+}
+
+enum single_thread_mode {
+ SINGLE_SUSPEND, /* other threads to stop wherever they are */
+ SINGLE_PTRACE, /* other threads to stop but don't wait */
+ SINGLE_UNWIND, /* other threads to unwind and stop */
+ SINGLE_EXIT /* other threads to unwind and then exit */
+};
+int single_thread_set(struct proc *, enum single_thread_mode, int);
+int single_thread_wait(struct process *, int);
+void single_thread_clear(struct proc *, int);
+int single_thread_check(struct proc *, int);
+
+void child_return(void *);
+
+int proc_cansugid(struct proc *);
+
+struct sleep_state {
+ int sls_s;
+ int sls_catch;
+ int sls_do_sleep;
+ int sls_locked;
+ int sls_sig;
+ int sls_unwind;
+ int sls_timeout;
+};
+
+struct cond {
+ int c_wait;
+};
+
+#define COND_INITIALIZER() { 1 }
+
+#if defined(MULTIPROCESSOR)
+void proc_trampoline_mp(void); /* XXX */
+#endif
+
+/*
+ * functions to handle sets of cpus.
+ *
+ * For now we keep the cpus in ints so that we can use the generic
+ * atomic ops.
+ */
+#define CPUSET_ASIZE(x) (((x) - 1)/32 + 1)
+#define CPUSET_SSIZE CPUSET_ASIZE(MAXCPUS)
+struct cpuset {
+ int cs_set[CPUSET_SSIZE];
+};
+
+void cpuset_init_cpu(struct cpu_info *);
+
+void cpuset_clear(struct cpuset *);
+void cpuset_add(struct cpuset *, struct cpu_info *);
+void cpuset_del(struct cpuset *, struct cpu_info *);
+int cpuset_isset(struct cpuset *, struct cpu_info *);
+void cpuset_add_all(struct cpuset *);
+void cpuset_copy(struct cpuset *, struct cpuset *);
+void cpuset_union(struct cpuset *, struct cpuset *, struct cpuset *);
+void cpuset_intersection(struct cpuset *t, struct cpuset *, struct cpuset *);
+void cpuset_complement(struct cpuset *, struct cpuset *, struct cpuset *);
+int cpuset_cardinality(struct cpuset *);
+struct cpu_info *cpuset_first(struct cpuset *);
+
+#endif /* _KERNEL */
+#endif /* !_SYS_PROC_H_ */
+
diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h
new file mode 100644
index 0000000..995a038
--- /dev/null
+++ b/sys/sys/protosw.h
@@ -0,0 +1,237 @@
+/* $OpenBSD: protosw.h,v 1.31 2018/01/23 20:49:58 bluhm Exp $ */
+/* $NetBSD: protosw.h,v 1.10 1996/04/09 20:55:32 cgd 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.
+ * 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.
+ *
+ * @(#)protosw.h 8.1 (Berkeley) 6/2/93
+ */
+
+/*
+ * Protocol switch table.
+ *
+ * Each protocol has a handle initializing one of these structures,
+ * which is used for protocol-protocol and system-protocol communication.
+ *
+ * A protocol is called through the pr_init entry before any other.
+ * Thereafter it is called every 200ms through the pr_fasttimo entry and
+ * every 500ms through the pr_slowtimo for timer based actions.
+ *
+ * Protocols pass data between themselves as chains of mbufs using
+ * the pr_input and pr_output hooks. Pr_input passes data up (towards
+ * UNIX) and pr_output passes it down (towards the imps); control
+ * information passes up and down on pr_ctlinput and pr_ctloutput.
+ * The protocol is responsible for the space occupied by any the
+ * arguments to these entries and must dispose it.
+ *
+ * The userreq routine interfaces protocols to the system and is
+ * described below.
+ */
+
+struct mbuf;
+struct sockaddr;
+struct socket;
+struct domain;
+struct proc;
+
+struct protosw {
+ short pr_type; /* socket type used for */
+ struct domain *pr_domain; /* domain protocol a member of */
+ short pr_protocol; /* protocol number */
+ short pr_flags; /* see below */
+
+/* protocol-protocol hooks */
+ /* input to protocol (from below) */
+ int (*pr_input)(struct mbuf **, int *, int, int);
+ /* output to protocol (from above) */
+ int (*pr_output)(struct mbuf *, struct socket *, struct sockaddr *,
+ struct mbuf *);
+ /* control input (from below) */
+ void (*pr_ctlinput)(int, struct sockaddr *, u_int, void *);
+ /* control output (from above) */
+ int (*pr_ctloutput)(int, struct socket *, int, int, struct mbuf *);
+
+/* user-protocol hook */
+ /* user request: see list below */
+ int (*pr_usrreq)(struct socket *, int, struct mbuf *,
+ struct mbuf *, struct mbuf *, struct proc *);
+
+ int (*pr_attach)(struct socket *, int);
+ int (*pr_detach)(struct socket *);
+
+/* utility hooks */
+ void (*pr_init)(void); /* initialization hook */
+ void (*pr_fasttimo)(void); /* fast timeout (200ms) */
+ void (*pr_slowtimo)(void); /* slow timeout (500ms) */
+ /* sysctl for protocol */
+ int (*pr_sysctl)(int *, u_int, void *, size_t *, void *, size_t);
+};
+
+#define PR_SLOWHZ 2 /* 2 slow timeouts per second */
+#define PR_FASTHZ 5 /* 5 fast timeouts per second */
+
+/*
+ * Values for pr_flags.
+ * PR_ADDR requires PR_ATOMIC;
+ * PR_ADDR and PR_CONNREQUIRED are mutually exclusive.
+ */
+#define PR_ATOMIC 0x01 /* exchange atomic messages only */
+#define PR_ADDR 0x02 /* addresses given with messages */
+#define PR_CONNREQUIRED 0x04 /* connection required by protocol */
+#define PR_WANTRCVD 0x08 /* want PRU_RCVD calls */
+#define PR_RIGHTS 0x10 /* passes capabilities */
+#define PR_ABRTACPTDIS 0x20 /* abort on accept(2) to disconnected
+ socket */
+#define PR_SPLICE 0x40 /* socket splicing is possible */
+
+/*
+ * The arguments to usrreq are:
+ * (*protosw[].pr_usrreq)(up, req, m, nam, opt);
+ * where up is a (struct socket *), req is one of these requests,
+ * m is a optional mbuf chain containing a message,
+ * nam is an optional mbuf chain containing an address,
+ * and opt is a pointer to a socketopt structure or nil.
+ * The protocol is responsible for disposal of the mbuf chain m,
+ * the caller is responsible for any space held by nam and opt.
+ * A non-zero return from usrreq gives an
+ * UNIX error number which should be passed to higher level software.
+ */
+#define PRU_ATTACH 0 /* attach protocol to up */
+#define PRU_DETACH 1 /* detach protocol from up */
+#define PRU_BIND 2 /* bind socket to address */
+#define PRU_LISTEN 3 /* listen for connection */
+#define PRU_CONNECT 4 /* establish connection to peer */
+#define PRU_ACCEPT 5 /* accept connection from peer */
+#define PRU_DISCONNECT 6 /* disconnect from peer */
+#define PRU_SHUTDOWN 7 /* won't send any more data */
+#define PRU_RCVD 8 /* have taken data; more room now */
+#define PRU_SEND 9 /* send this data */
+#define PRU_ABORT 10 /* abort (fast DISCONNECT, DETACH) */
+#define PRU_CONTROL 11 /* control operations on protocol */
+#define PRU_SENSE 12 /* return status into m */
+#define PRU_RCVOOB 13 /* retrieve out of band data */
+#define PRU_SENDOOB 14 /* send out of band data */
+#define PRU_SOCKADDR 15 /* fetch socket's address */
+#define PRU_PEERADDR 16 /* fetch peer's address */
+#define PRU_CONNECT2 17 /* connect two sockets */
+/* begin for protocols internal use */
+#define PRU_FASTTIMO 18 /* 200ms timeout */
+#define PRU_SLOWTIMO 19 /* 500ms timeout */
+#define PRU_PROTORCV 20 /* receive from below */
+#define PRU_PROTOSEND 21 /* send to below */
+
+#define PRU_NREQ 22
+
+#ifdef PRUREQUESTS
+const char *prurequests[] = {
+ "ATTACH", "DETACH", "BIND", "LISTEN",
+ "CONNECT", "ACCEPT", "DISCONNECT", "SHUTDOWN",
+ "RCVD", "SEND", "ABORT", "CONTROL",
+ "SENSE", "RCVOOB", "SENDOOB", "SOCKADDR",
+ "PEERADDR", "CONNECT2", "FASTTIMO", "SLOWTIMO",
+ "PROTORCV", "PROTOSEND",
+};
+#endif
+
+/*
+ * The arguments to the ctlinput routine are
+ * (*protosw[].pr_ctlinput)(cmd, sa, arg);
+ * where cmd is one of the commands below, sa is a pointer to a sockaddr,
+ * and arg is an optional caddr_t argument used within a protocol family.
+ */
+#define PRC_IFDOWN 0 /* interface transition */
+#define PRC_ROUTEDEAD 1 /* select new route if possible ??? */
+#define PRC_MTUINC 2 /* increase in mtu to host */
+#define PRC_QUENCH2 3 /* DEC congestion bit says slow down */
+#define PRC_QUENCH 4 /* some one said to slow down */
+#define PRC_MSGSIZE 5 /* message size forced drop */
+#define PRC_HOSTDEAD 6 /* host appears to be down */
+#define PRC_HOSTUNREACH 7 /* deprecated (use PRC_UNREACH_HOST) */
+#define PRC_UNREACH_NET 8 /* no route to network */
+#define PRC_UNREACH_HOST 9 /* no route to host */
+#define PRC_UNREACH_PROTOCOL 10 /* dst says bad protocol */
+#define PRC_UNREACH_PORT 11 /* bad port # */
+/* was PRC_UNREACH_NEEDFRAG 12 (use PRC_MSGSIZE) */
+#define PRC_UNREACH_SRCFAIL 13 /* source route failed */
+#define PRC_REDIRECT_NET 14 /* net routing redirect */
+#define PRC_REDIRECT_HOST 15 /* host routing redirect */
+#define PRC_REDIRECT_TOSNET 16 /* redirect for type of service & net */
+#define PRC_REDIRECT_TOSHOST 17 /* redirect for tos & host */
+#define PRC_TIMXCEED_INTRANS 18 /* packet lifetime expired in transit */
+#define PRC_TIMXCEED_REASS 19 /* lifetime expired on reass q */
+#define PRC_PARAMPROB 20 /* header incorrect */
+
+#define PRC_NCMDS 21
+
+#define PRC_IS_REDIRECT(cmd) \
+ ((cmd) >= PRC_REDIRECT_NET && (cmd) <= PRC_REDIRECT_TOSHOST)
+
+#ifdef PRCREQUESTS
+char *prcrequests[] = {
+ "IFDOWN", "ROUTEDEAD", "MTUINC", "DEC-BIT-QUENCH2",
+ "QUENCH", "MSGSIZE", "HOSTDEAD", "#7",
+ "NET-UNREACH", "HOST-UNREACH", "PROTO-UNREACH", "PORT-UNREACH",
+ "#12", "SRCFAIL-UNREACH", "NET-REDIRECT", "HOST-REDIRECT",
+ "TOSNET-REDIRECT", "TOSHOST-REDIRECT", "TX-INTRANS", "TX-REASS",
+ "PARAMPROB"
+};
+#endif
+
+/*
+ * The arguments to ctloutput are:
+ * (*protosw[].pr_ctloutput)(req, so, level, optname, optval);
+ * req is one of the actions listed below, so is a (struct socket *),
+ * level is an indication of which protocol layer the option is intended.
+ * optname is a protocol dependent socket option request,
+ * optval is a pointer to a mbuf-chain pointer, for value-return results.
+ * The protocol is responsible for disposal of the mbuf chain *optval
+ * if supplied,
+ * the caller is responsible for any space held by *optval, when returned.
+ * A non-zero return from usrreq gives an
+ * UNIX error number which should be passed to higher level software.
+ */
+#define PRCO_GETOPT 0
+#define PRCO_SETOPT 1
+
+#define PRCO_NCMDS 2
+
+#ifdef PRCOREQUESTS
+char *prcorequests[] = {
+ "GETOPT", "SETOPT",
+};
+#endif
+
+#ifdef _KERNEL
+struct sockaddr;
+const struct protosw *pffindproto(int, int, int);
+const struct protosw *pffindtype(int, int);
+void pfctlinput(int, struct sockaddr *);
+
+extern u_char ip_protox[];
+extern const struct protosw inetsw[];
+#endif
diff --git a/sys/sys/ptrace.h b/sys/sys/ptrace.h
new file mode 100644
index 0000000..8e127c5
--- /dev/null
+++ b/sys/sys/ptrace.h
@@ -0,0 +1,137 @@
+/* $OpenBSD: ptrace.h,v 1.16 2020/03/16 11:58:46 mpi Exp $ */
+/* $NetBSD: ptrace.h,v 1.21 1996/02/09 18:25:26 christos Exp $ */
+
+/*-
+ * Copyright (c) 1984, 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.
+ *
+ * @(#)ptrace.h 8.2 (Berkeley) 1/4/94
+ */
+
+#ifndef _SYS_PTRACE_H_
+#define _SYS_PTRACE_H_
+
+#define PT_TRACE_ME 0 /* child declares it's being traced */
+#define PT_READ_I 1 /* read word in child's I space */
+#define PT_READ_D 2 /* read word in child's D space */
+#define PT_WRITE_I 4 /* write word in child's I space */
+#define PT_WRITE_D 5 /* write word in child's D space */
+#define PT_CONTINUE 7 /* continue the child */
+#define PT_KILL 8 /* kill the child process */
+#define PT_ATTACH 9 /* attach to running process */
+#define PT_DETACH 10 /* detach from running process */
+#define PT_IO 11 /* do I/O to/from the stopped process. */
+
+struct ptrace_io_desc {
+ int piod_op; /* I/O operation */
+ void *piod_offs; /* child offset */
+ void *piod_addr; /* parent offset */
+ size_t piod_len; /* request length */
+};
+
+/*
+ * Operations in piod_op.
+ */
+#define PIOD_READ_D 1 /* Read from D space */
+#define PIOD_WRITE_D 2 /* Write to D space */
+#define PIOD_READ_I 3 /* Read from I space */
+#define PIOD_WRITE_I 4 /* Write to I space */
+#define PIOD_READ_AUXV 5 /* Read from aux array */
+
+#define PT_SET_EVENT_MASK 12
+#define PT_GET_EVENT_MASK 13
+
+typedef struct ptrace_event {
+ int pe_set_event;
+} ptrace_event_t;
+
+#define PTRACE_FORK 0x0002 /* Report forks */
+
+#define PT_GET_PROCESS_STATE 14
+
+typedef struct ptrace_state {
+ int pe_report_event;
+ pid_t pe_other_pid;
+ pid_t pe_tid;
+} ptrace_state_t;
+
+#define PT_GET_THREAD_FIRST 15
+#define PT_GET_THREAD_NEXT 16
+
+struct ptrace_thread_state {
+ pid_t pts_tid;
+};
+
+#define PT_FIRSTMACH 32 /* for machine-specific requests */
+#include <machine/ptrace.h> /* machine-specific requests, if any */
+
+#ifdef _KERNEL
+
+/*
+ * There is a bunch of PT_ requests that are machine dependent, but not
+ * optional. Check if they were defined by MD code here.
+ */
+#if !defined(PT_GETREGS) || !defined(PT_SETREGS)
+#error Machine dependent ptrace not complete.
+#endif
+
+struct reg;
+#if defined(PT_GETFPREGS) || defined(PT_SETFPREGS)
+struct fpreg;
+#endif
+
+void process_reparent(struct process *_child, struct process *_newparent);
+void process_untrace(struct process *_tr);
+#ifdef PT_GETFPREGS
+int process_read_fpregs(struct proc *_t, struct fpreg *);
+#endif
+int process_read_regs(struct proc *_t, struct reg *);
+int process_set_pc(struct proc *_t, caddr_t _addr);
+int process_sstep(struct proc *_t, int _sstep);
+#ifdef PT_SETFPREGS
+int process_write_fpregs(struct proc *_t, struct fpreg *);
+#endif
+int process_write_regs(struct proc *_t, struct reg *);
+int process_checkioperm(struct proc *_curp, struct process *_tr);
+int process_domem(struct proc *_curp, struct process *_tr, struct uio *,
+ int _req);
+
+#ifndef FIX_SSTEP
+#define FIX_SSTEP(p)
+#endif
+
+#else /* !_KERNEL */
+
+#include <sys/cdefs.h>
+
+__BEGIN_DECLS
+int ptrace(int _request, pid_t _pid, caddr_t _addr, int _data);
+__END_DECLS
+
+#endif /* !_KERNEL */
+
+#endif /* !_SYS_PTRACE_H_ */
diff --git a/sys/sys/queue.h b/sys/sys/queue.h
new file mode 100644
index 0000000..f28ba89
--- /dev/null
+++ b/sys/sys/queue.h
@@ -0,0 +1,536 @@
+/* $OpenBSD: queue.h,v 1.45 2018/07/12 14:22:54 sashan Exp $ */
+/* $NetBSD: queue.h,v 1.11 1996/05/16 05:17:14 mycroft Exp $ */
+
+/*
+ * Copyright (c) 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.
+ * 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.
+ *
+ * @(#)queue.h 8.5 (Berkeley) 8/20/94
+ */
+
+#ifndef _SYS_QUEUE_H_
+#define _SYS_QUEUE_H_
+
+#include <sys/_null.h>
+
+/*
+ * This file defines five types of data structures: singly-linked lists,
+ * lists, simple queues, tail queues and XOR simple queues.
+ *
+ *
+ * A singly-linked list is headed by a single forward pointer. The elements
+ * are singly linked for minimum space and pointer manipulation overhead at
+ * the expense of O(n) removal for arbitrary elements. New elements can be
+ * added to the list after an existing element or at the head of the list.
+ * Elements being removed from the head of the list should use the explicit
+ * macro for this purpose for optimum efficiency. A singly-linked list may
+ * only be traversed in the forward direction. Singly-linked lists are ideal
+ * for applications with large datasets and few or no removals or for
+ * implementing a LIFO queue.
+ *
+ * A list is headed by a single forward pointer (or an array of forward
+ * pointers for a hash table header). The elements are doubly linked
+ * so that an arbitrary element can be removed without a need to
+ * traverse the list. New elements can be added to the list before
+ * or after an existing element or at the head of the list. A list
+ * may only be traversed in the forward direction.
+ *
+ * A simple queue is headed by a pair of pointers, one to the head of the
+ * list and the other to the tail of the list. The elements are singly
+ * linked to save space, so elements can only be removed from the
+ * head of the list. New elements can be added to the list before or after
+ * an existing element, at the head of the list, or at the end of the
+ * list. A simple queue may only be traversed in the forward direction.
+ *
+ * A tail queue is headed by a pair of pointers, one to the head of the
+ * list and the other to the tail of the list. The elements are doubly
+ * linked so that an arbitrary element can be removed without a need to
+ * traverse the list. New elements can be added to the list before or
+ * after an existing element, at the head of the list, or at the end of
+ * the list. A tail queue may be traversed in either direction.
+ *
+ * An XOR simple queue is used in the same way as a regular simple queue.
+ * The difference is that the head structure also includes a "cookie" that
+ * is XOR'd with the queue pointer (first, last or next) to generate the
+ * real pointer value.
+ *
+ * For details on the use of these macros, see the queue(3) manual page.
+ */
+
+#if defined(QUEUE_MACRO_DEBUG) || (defined(_KERNEL) && defined(DIAGNOSTIC))
+#define _Q_INVALID ((void *)-1)
+#define _Q_INVALIDATE(a) (a) = _Q_INVALID
+#else
+#define _Q_INVALIDATE(a)
+#endif
+
+/*
+ * Singly-linked List definitions.
+ */
+#define SLIST_HEAD(name, type) \
+struct name { \
+ struct type *slh_first; /* first element */ \
+}
+
+#define SLIST_HEAD_INITIALIZER(head) \
+ { NULL }
+
+#define SLIST_ENTRY(type) \
+struct { \
+ struct type *sle_next; /* next element */ \
+}
+
+/*
+ * Singly-linked List access methods.
+ */
+#define SLIST_FIRST(head) ((head)->slh_first)
+#define SLIST_END(head) NULL
+#define SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head))
+#define SLIST_NEXT(elm, field) ((elm)->field.sle_next)
+
+#define SLIST_FOREACH(var, head, field) \
+ for((var) = SLIST_FIRST(head); \
+ (var) != SLIST_END(head); \
+ (var) = SLIST_NEXT(var, field))
+
+#define SLIST_FOREACH_SAFE(var, head, field, tvar) \
+ for ((var) = SLIST_FIRST(head); \
+ (var) && ((tvar) = SLIST_NEXT(var, field), 1); \
+ (var) = (tvar))
+
+/*
+ * Singly-linked List functions.
+ */
+#define SLIST_INIT(head) { \
+ SLIST_FIRST(head) = SLIST_END(head); \
+}
+
+#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \
+ (elm)->field.sle_next = (slistelm)->field.sle_next; \
+ (slistelm)->field.sle_next = (elm); \
+} while (0)
+
+#define SLIST_INSERT_HEAD(head, elm, field) do { \
+ (elm)->field.sle_next = (head)->slh_first; \
+ (head)->slh_first = (elm); \
+} while (0)
+
+#define SLIST_REMOVE_AFTER(elm, field) do { \
+ (elm)->field.sle_next = (elm)->field.sle_next->field.sle_next; \
+} while (0)
+
+#define SLIST_REMOVE_HEAD(head, field) do { \
+ (head)->slh_first = (head)->slh_first->field.sle_next; \
+} while (0)
+
+#define SLIST_REMOVE(head, elm, type, field) do { \
+ if ((head)->slh_first == (elm)) { \
+ SLIST_REMOVE_HEAD((head), field); \
+ } else { \
+ struct type *curelm = (head)->slh_first; \
+ \
+ while (curelm->field.sle_next != (elm)) \
+ curelm = curelm->field.sle_next; \
+ curelm->field.sle_next = \
+ curelm->field.sle_next->field.sle_next; \
+ } \
+ _Q_INVALIDATE((elm)->field.sle_next); \
+} while (0)
+
+/*
+ * List definitions.
+ */
+#define LIST_HEAD(name, type) \
+struct name { \
+ struct type *lh_first; /* first element */ \
+}
+
+#define LIST_HEAD_INITIALIZER(head) \
+ { NULL }
+
+#define LIST_ENTRY(type) \
+struct { \
+ struct type *le_next; /* next element */ \
+ struct type **le_prev; /* address of previous next element */ \
+}
+
+/*
+ * List access methods.
+ */
+#define LIST_FIRST(head) ((head)->lh_first)
+#define LIST_END(head) NULL
+#define LIST_EMPTY(head) (LIST_FIRST(head) == LIST_END(head))
+#define LIST_NEXT(elm, field) ((elm)->field.le_next)
+
+#define LIST_FOREACH(var, head, field) \
+ for((var) = LIST_FIRST(head); \
+ (var)!= LIST_END(head); \
+ (var) = LIST_NEXT(var, field))
+
+#define LIST_FOREACH_SAFE(var, head, field, tvar) \
+ for ((var) = LIST_FIRST(head); \
+ (var) && ((tvar) = LIST_NEXT(var, field), 1); \
+ (var) = (tvar))
+
+/*
+ * List functions.
+ */
+#define LIST_INIT(head) do { \
+ LIST_FIRST(head) = LIST_END(head); \
+} while (0)
+
+#define LIST_INSERT_AFTER(listelm, elm, field) do { \
+ if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \
+ (listelm)->field.le_next->field.le_prev = \
+ &(elm)->field.le_next; \
+ (listelm)->field.le_next = (elm); \
+ (elm)->field.le_prev = &(listelm)->field.le_next; \
+} while (0)
+
+#define LIST_INSERT_BEFORE(listelm, elm, field) do { \
+ (elm)->field.le_prev = (listelm)->field.le_prev; \
+ (elm)->field.le_next = (listelm); \
+ *(listelm)->field.le_prev = (elm); \
+ (listelm)->field.le_prev = &(elm)->field.le_next; \
+} while (0)
+
+#define LIST_INSERT_HEAD(head, elm, field) do { \
+ if (((elm)->field.le_next = (head)->lh_first) != NULL) \
+ (head)->lh_first->field.le_prev = &(elm)->field.le_next;\
+ (head)->lh_first = (elm); \
+ (elm)->field.le_prev = &(head)->lh_first; \
+} while (0)
+
+#define LIST_REMOVE(elm, field) do { \
+ if ((elm)->field.le_next != NULL) \
+ (elm)->field.le_next->field.le_prev = \
+ (elm)->field.le_prev; \
+ *(elm)->field.le_prev = (elm)->field.le_next; \
+ _Q_INVALIDATE((elm)->field.le_prev); \
+ _Q_INVALIDATE((elm)->field.le_next); \
+} while (0)
+
+#define LIST_REPLACE(elm, elm2, field) do { \
+ if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \
+ (elm2)->field.le_next->field.le_prev = \
+ &(elm2)->field.le_next; \
+ (elm2)->field.le_prev = (elm)->field.le_prev; \
+ *(elm2)->field.le_prev = (elm2); \
+ _Q_INVALIDATE((elm)->field.le_prev); \
+ _Q_INVALIDATE((elm)->field.le_next); \
+} while (0)
+
+/*
+ * Simple queue definitions.
+ */
+#define SIMPLEQ_HEAD(name, type) \
+struct name { \
+ struct type *sqh_first; /* first element */ \
+ struct type **sqh_last; /* addr of last next element */ \
+}
+
+#define SIMPLEQ_HEAD_INITIALIZER(head) \
+ { NULL, &(head).sqh_first }
+
+#define SIMPLEQ_ENTRY(type) \
+struct { \
+ struct type *sqe_next; /* next element */ \
+}
+
+/*
+ * Simple queue access methods.
+ */
+#define SIMPLEQ_FIRST(head) ((head)->sqh_first)
+#define SIMPLEQ_END(head) NULL
+#define SIMPLEQ_EMPTY(head) (SIMPLEQ_FIRST(head) == SIMPLEQ_END(head))
+#define SIMPLEQ_NEXT(elm, field) ((elm)->field.sqe_next)
+
+#define SIMPLEQ_FOREACH(var, head, field) \
+ for((var) = SIMPLEQ_FIRST(head); \
+ (var) != SIMPLEQ_END(head); \
+ (var) = SIMPLEQ_NEXT(var, field))
+
+#define SIMPLEQ_FOREACH_SAFE(var, head, field, tvar) \
+ for ((var) = SIMPLEQ_FIRST(head); \
+ (var) && ((tvar) = SIMPLEQ_NEXT(var, field), 1); \
+ (var) = (tvar))
+
+/*
+ * Simple queue functions.
+ */
+#define SIMPLEQ_INIT(head) do { \
+ (head)->sqh_first = NULL; \
+ (head)->sqh_last = &(head)->sqh_first; \
+} while (0)
+
+#define SIMPLEQ_INSERT_HEAD(head, elm, field) do { \
+ if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \
+ (head)->sqh_last = &(elm)->field.sqe_next; \
+ (head)->sqh_first = (elm); \
+} while (0)
+
+#define SIMPLEQ_INSERT_TAIL(head, elm, field) do { \
+ (elm)->field.sqe_next = NULL; \
+ *(head)->sqh_last = (elm); \
+ (head)->sqh_last = &(elm)->field.sqe_next; \
+} while (0)
+
+#define SIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
+ if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\
+ (head)->sqh_last = &(elm)->field.sqe_next; \
+ (listelm)->field.sqe_next = (elm); \
+} while (0)
+
+#define SIMPLEQ_REMOVE_HEAD(head, field) do { \
+ if (((head)->sqh_first = (head)->sqh_first->field.sqe_next) == NULL) \
+ (head)->sqh_last = &(head)->sqh_first; \
+} while (0)
+
+#define SIMPLEQ_REMOVE_AFTER(head, elm, field) do { \
+ if (((elm)->field.sqe_next = (elm)->field.sqe_next->field.sqe_next) \
+ == NULL) \
+ (head)->sqh_last = &(elm)->field.sqe_next; \
+} while (0)
+
+#define SIMPLEQ_CONCAT(head1, head2) do { \
+ if (!SIMPLEQ_EMPTY((head2))) { \
+ *(head1)->sqh_last = (head2)->sqh_first; \
+ (head1)->sqh_last = (head2)->sqh_last; \
+ SIMPLEQ_INIT((head2)); \
+ } \
+} while (0)
+
+/*
+ * XOR Simple queue definitions.
+ */
+#define XSIMPLEQ_HEAD(name, type) \
+struct name { \
+ struct type *sqx_first; /* first element */ \
+ struct type **sqx_last; /* addr of last next element */ \
+ unsigned long sqx_cookie; \
+}
+
+#define XSIMPLEQ_ENTRY(type) \
+struct { \
+ struct type *sqx_next; /* next element */ \
+}
+
+/*
+ * XOR Simple queue access methods.
+ */
+#define XSIMPLEQ_XOR(head, ptr) ((__typeof(ptr))((head)->sqx_cookie ^ \
+ (unsigned long)(ptr)))
+#define XSIMPLEQ_FIRST(head) XSIMPLEQ_XOR(head, ((head)->sqx_first))
+#define XSIMPLEQ_END(head) NULL
+#define XSIMPLEQ_EMPTY(head) (XSIMPLEQ_FIRST(head) == XSIMPLEQ_END(head))
+#define XSIMPLEQ_NEXT(head, elm, field) XSIMPLEQ_XOR(head, ((elm)->field.sqx_next))
+
+
+#define XSIMPLEQ_FOREACH(var, head, field) \
+ for ((var) = XSIMPLEQ_FIRST(head); \
+ (var) != XSIMPLEQ_END(head); \
+ (var) = XSIMPLEQ_NEXT(head, var, field))
+
+#define XSIMPLEQ_FOREACH_SAFE(var, head, field, tvar) \
+ for ((var) = XSIMPLEQ_FIRST(head); \
+ (var) && ((tvar) = XSIMPLEQ_NEXT(head, var, field), 1); \
+ (var) = (tvar))
+
+/*
+ * XOR Simple queue functions.
+ */
+#define XSIMPLEQ_INIT(head) do { \
+ arc4random_buf(&(head)->sqx_cookie, sizeof((head)->sqx_cookie)); \
+ (head)->sqx_first = XSIMPLEQ_XOR(head, NULL); \
+ (head)->sqx_last = XSIMPLEQ_XOR(head, &(head)->sqx_first); \
+} while (0)
+
+#define XSIMPLEQ_INSERT_HEAD(head, elm, field) do { \
+ if (((elm)->field.sqx_next = (head)->sqx_first) == \
+ XSIMPLEQ_XOR(head, NULL)) \
+ (head)->sqx_last = XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \
+ (head)->sqx_first = XSIMPLEQ_XOR(head, (elm)); \
+} while (0)
+
+#define XSIMPLEQ_INSERT_TAIL(head, elm, field) do { \
+ (elm)->field.sqx_next = XSIMPLEQ_XOR(head, NULL); \
+ *(XSIMPLEQ_XOR(head, (head)->sqx_last)) = XSIMPLEQ_XOR(head, (elm)); \
+ (head)->sqx_last = XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \
+} while (0)
+
+#define XSIMPLEQ_INSERT_AFTER(head, listelm, elm, field) do { \
+ if (((elm)->field.sqx_next = (listelm)->field.sqx_next) == \
+ XSIMPLEQ_XOR(head, NULL)) \
+ (head)->sqx_last = XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \
+ (listelm)->field.sqx_next = XSIMPLEQ_XOR(head, (elm)); \
+} while (0)
+
+#define XSIMPLEQ_REMOVE_HEAD(head, field) do { \
+ if (((head)->sqx_first = XSIMPLEQ_XOR(head, \
+ (head)->sqx_first)->field.sqx_next) == XSIMPLEQ_XOR(head, NULL)) \
+ (head)->sqx_last = XSIMPLEQ_XOR(head, &(head)->sqx_first); \
+} while (0)
+
+#define XSIMPLEQ_REMOVE_AFTER(head, elm, field) do { \
+ if (((elm)->field.sqx_next = XSIMPLEQ_XOR(head, \
+ (elm)->field.sqx_next)->field.sqx_next) \
+ == XSIMPLEQ_XOR(head, NULL)) \
+ (head)->sqx_last = \
+ XSIMPLEQ_XOR(head, &(elm)->field.sqx_next); \
+} while (0)
+
+
+/*
+ * Tail queue definitions.
+ */
+#define TAILQ_HEAD(name, type) \
+struct name { \
+ struct type *tqh_first; /* first element */ \
+ struct type **tqh_last; /* addr of last next element */ \
+}
+
+#define TAILQ_HEAD_INITIALIZER(head) \
+ { NULL, &(head).tqh_first }
+
+#define TAILQ_ENTRY(type) \
+struct { \
+ struct type *tqe_next; /* next element */ \
+ struct type **tqe_prev; /* address of previous next element */ \
+}
+
+/*
+ * Tail queue access methods.
+ */
+#define TAILQ_FIRST(head) ((head)->tqh_first)
+#define TAILQ_END(head) NULL
+#define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next)
+#define TAILQ_LAST(head, headname) \
+ (*(((struct headname *)((head)->tqh_last))->tqh_last))
+/* XXX */
+#define TAILQ_PREV(elm, headname, field) \
+ (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last))
+#define TAILQ_EMPTY(head) \
+ (TAILQ_FIRST(head) == TAILQ_END(head))
+
+#define TAILQ_FOREACH(var, head, field) \
+ for((var) = TAILQ_FIRST(head); \
+ (var) != TAILQ_END(head); \
+ (var) = TAILQ_NEXT(var, field))
+
+#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
+ for ((var) = TAILQ_FIRST(head); \
+ (var) != TAILQ_END(head) && \
+ ((tvar) = TAILQ_NEXT(var, field), 1); \
+ (var) = (tvar))
+
+
+#define TAILQ_FOREACH_REVERSE(var, head, headname, field) \
+ for((var) = TAILQ_LAST(head, headname); \
+ (var) != TAILQ_END(head); \
+ (var) = TAILQ_PREV(var, headname, field))
+
+#define TAILQ_FOREACH_REVERSE_SAFE(var, head, headname, field, tvar) \
+ for ((var) = TAILQ_LAST(head, headname); \
+ (var) != TAILQ_END(head) && \
+ ((tvar) = TAILQ_PREV(var, headname, field), 1); \
+ (var) = (tvar))
+
+/*
+ * Tail queue functions.
+ */
+#define TAILQ_INIT(head) do { \
+ (head)->tqh_first = NULL; \
+ (head)->tqh_last = &(head)->tqh_first; \
+} while (0)
+
+#define TAILQ_INSERT_HEAD(head, elm, field) do { \
+ if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \
+ (head)->tqh_first->field.tqe_prev = \
+ &(elm)->field.tqe_next; \
+ else \
+ (head)->tqh_last = &(elm)->field.tqe_next; \
+ (head)->tqh_first = (elm); \
+ (elm)->field.tqe_prev = &(head)->tqh_first; \
+} while (0)
+
+#define TAILQ_INSERT_TAIL(head, elm, field) do { \
+ (elm)->field.tqe_next = NULL; \
+ (elm)->field.tqe_prev = (head)->tqh_last; \
+ *(head)->tqh_last = (elm); \
+ (head)->tqh_last = &(elm)->field.tqe_next; \
+} while (0)
+
+#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \
+ if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\
+ (elm)->field.tqe_next->field.tqe_prev = \
+ &(elm)->field.tqe_next; \
+ else \
+ (head)->tqh_last = &(elm)->field.tqe_next; \
+ (listelm)->field.tqe_next = (elm); \
+ (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \
+} while (0)
+
+#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \
+ (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \
+ (elm)->field.tqe_next = (listelm); \
+ *(listelm)->field.tqe_prev = (elm); \
+ (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \
+} while (0)
+
+#define TAILQ_REMOVE(head, elm, field) do { \
+ if (((elm)->field.tqe_next) != NULL) \
+ (elm)->field.tqe_next->field.tqe_prev = \
+ (elm)->field.tqe_prev; \
+ else \
+ (head)->tqh_last = (elm)->field.tqe_prev; \
+ *(elm)->field.tqe_prev = (elm)->field.tqe_next; \
+ _Q_INVALIDATE((elm)->field.tqe_prev); \
+ _Q_INVALIDATE((elm)->field.tqe_next); \
+} while (0)
+
+#define TAILQ_REPLACE(head, elm, elm2, field) do { \
+ if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \
+ (elm2)->field.tqe_next->field.tqe_prev = \
+ &(elm2)->field.tqe_next; \
+ else \
+ (head)->tqh_last = &(elm2)->field.tqe_next; \
+ (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \
+ *(elm2)->field.tqe_prev = (elm2); \
+ _Q_INVALIDATE((elm)->field.tqe_prev); \
+ _Q_INVALIDATE((elm)->field.tqe_next); \
+} while (0)
+
+#define TAILQ_CONCAT(head1, head2, field) do { \
+ if (!TAILQ_EMPTY(head2)) { \
+ *(head1)->tqh_last = (head2)->tqh_first; \
+ (head2)->tqh_first->field.tqe_prev = (head1)->tqh_last; \
+ (head1)->tqh_last = (head2)->tqh_last; \
+ TAILQ_INIT((head2)); \
+ } \
+} while (0)
+
+#endif /* !_SYS_QUEUE_H_ */
diff --git a/sys/sys/radioio.h b/sys/sys/radioio.h
new file mode 100644
index 0000000..343d730
--- /dev/null
+++ b/sys/sys/radioio.h
@@ -0,0 +1,76 @@
+/* $OpenBSD: radioio.h,v 1.5 2015/01/14 21:15:36 deraadt Exp $ */
+/* $RuOBSD: radioio.h,v 1.4 2001/10/18 16:51:36 pva Exp $ */
+
+/*
+ * Copyright (c) 2001 Maxim Tsyplakov <tm@oganer.net>,
+ * Vladimir Popov <jumbo@narod.ru>
+ * 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 AUTHORS ``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 AUTHORS 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 _SYS_RADIOIO_H_
+#define _SYS_RADIOIO_H_
+
+#include <sys/types.h>
+
+#define MIN_FM_FREQ 87500
+#define MAX_FM_FREQ 108000
+
+#define MIN_TV_CHAN 0
+#define MAX_TV_CHAN 150
+
+#define IF_FREQ 10700
+
+struct radio_info {
+ int mute;
+ int volume;
+ int stereo;
+ int rfreq; /* reference frequency */
+ int lock; /* locking field strength during an automatic search */
+ u_int32_t freq; /* in kHz */
+ u_int32_t caps; /* card capabilities */
+#define RADIO_CAPS_DETECT_STEREO (1<<0)
+#define RADIO_CAPS_DETECT_SIGNAL (1<<1)
+#define RADIO_CAPS_SET_MONO (1<<2)
+#define RADIO_CAPS_HW_SEARCH (1<<3)
+#define RADIO_CAPS_HW_AFC (1<<4)
+#define RADIO_CAPS_REFERENCE_FREQ (1<<5)
+#define RADIO_CAPS_LOCK_SENSITIVITY (1<<6)
+#define RADIO_CAPS_RESERVED1 (1<<7)
+#define RADIO_CAPS_RESERVED2 (0xFF<<8)
+#define RADIO_CARD_TYPE (0xFF<<16)
+ u_int32_t info;
+#define RADIO_INFO_STEREO (1<<0)
+#define RADIO_INFO_SIGNAL (1<<1)
+ u_int32_t tuner_mode;
+#define RADIO_TUNER_MODE_RADIO (1<<0)
+#define RADIO_TUNER_MODE_TV (1<<1)
+ u_int32_t chan;
+ u_int32_t chnlset;
+};
+
+/* Radio device operations */
+#define RIOCGINFO _IOR('R', 21, struct radio_info) /* get info */
+#define RIOCSINFO _IOWR('R', 22, struct radio_info) /* set info */
+#define RIOCSSRCH _IOW('R', 23, int) /* search up/down */
+
+#endif /* _SYS_RADIOIO_H_ */
diff --git a/sys/sys/reboot.h b/sys/sys/reboot.h
new file mode 100644
index 0000000..492b554
--- /dev/null
+++ b/sys/sys/reboot.h
@@ -0,0 +1,106 @@
+/* $OpenBSD: reboot.h,v 1.18 2019/04/01 07:00:52 tedu Exp $ */
+/* $NetBSD: reboot.h,v 1.9 1996/04/22 01:23:25 christos Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 1988, 1993, 1994
+ * 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.
+ *
+ * @(#)reboot.h 8.2 (Berkeley) 7/10/94
+ */
+
+#ifndef _SYS_REBOOT_H_
+#define _SYS_REBOOT_H_
+
+/*
+ * Arguments to reboot system call. These are passed to the boot program,
+ * and then on to init.
+ */
+#define RB_AUTOBOOT 0 /* flags for system auto-booting itself */
+
+#define RB_ASKNAME 0x0001 /* ask for file name to reboot from */
+#define RB_SINGLE 0x0002 /* reboot to single user only */
+#define RB_NOSYNC 0x0004 /* dont sync before reboot */
+#define RB_HALT 0x0008 /* don't reboot, just halt */
+#define RB_INITNAME 0x0010 /* name given for /etc/init (unused) */
+#define RB_DFLTROOT 0x0020 /* use compiled-in rootdev */
+#define RB_KDB 0x0040 /* give control to kernel debugger */
+#define RB_RDONLY 0x0080 /* mount root fs read-only */
+#define RB_DUMP 0x0100 /* dump kernel memory before reboot */
+#define RB_MINIROOT 0x0200 /* mini-root present in memory at boot time */
+#define RB_CONFIG 0x0400 /* change configured devices */
+#define RB_TIMEBAD 0x0800 /* don't call resettodr() in boot() */
+#define RB_POWERDOWN 0x1000 /* attempt to power down machine */
+#define RB_SERCONS 0x2000 /* use serial console if available */
+#define RB_USERREQ 0x4000 /* boot() called at user request (e.g. ddb) */
+#define RB_RESET 0x8000 /* just reset, no cleanup */
+
+/*
+ * Constants for converting boot-style device number to type,
+ * adaptor (uba, mba, etc), unit number and partition number.
+ * Type (== major device number) is in the low byte
+ * for backward compatibility. Except for that of the "magic
+ * number", each mask applies to the shifted value.
+ * Format:
+ * (4) (4) (4) (4) (8) (8)
+ * --------------------------------
+ * |MA | AD| CT| UN| PART | TYPE |
+ * --------------------------------
+ */
+#define B_ADAPTORSHIFT 24
+#define B_ADAPTORMASK 0x0f
+#define B_ADAPTOR(val) (((val) >> B_ADAPTORSHIFT) & B_ADAPTORMASK)
+#define B_CONTROLLERSHIFT 20
+#define B_CONTROLLERMASK 0xf
+#define B_CONTROLLER(val) (((val)>>B_CONTROLLERSHIFT) & B_CONTROLLERMASK)
+#define B_UNITSHIFT 16
+#define B_UNITMASK 0xf
+#define B_UNIT(val) (((val) >> B_UNITSHIFT) & B_UNITMASK)
+#define B_PARTITIONSHIFT 8
+#define B_PARTITIONMASK 0xff
+#define B_PARTITION(val) (((val) >> B_PARTITIONSHIFT) & B_PARTITIONMASK)
+#define B_TYPESHIFT 0
+#define B_TYPEMASK 0xff
+#define B_TYPE(val) (((val) >> B_TYPESHIFT) & B_TYPEMASK)
+
+#define B_MAGICMASK 0xf0000000
+#define B_DEVMAGIC 0xa0000000
+
+#define MAKEBOOTDEV(type, adaptor, controller, unit, partition) \
+ (((type) << B_TYPESHIFT) | ((adaptor) << B_ADAPTORSHIFT) | \
+ ((controller) << B_CONTROLLERSHIFT) | ((unit) << B_UNITSHIFT) | \
+ ((partition) << B_PARTITIONSHIFT) | B_DEVMAGIC)
+
+#if defined(_KERNEL) && !defined(_STANDALONE) && !defined(_LOCORE)
+
+__BEGIN_DECLS
+__dead void reboot(int);
+__dead void boot(int);
+__END_DECLS
+
+#endif /* _KERNEL */
+
+#endif /* !_SYS_REBOOT_H_ */
diff --git a/sys/sys/refcnt.h b/sys/sys/refcnt.h
new file mode 100644
index 0000000..85e84cf
--- /dev/null
+++ b/sys/sys/refcnt.h
@@ -0,0 +1,38 @@
+/* $OpenBSD: refcnt.h,v 1.4 2016/06/07 07:53:33 mpi Exp $ */
+
+/*
+ * Copyright (c) 2015 David Gwynne <dlg@openbsd.org>
+ *
+ * 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.
+ */
+
+#ifndef _SYS_REFCNT_H_
+#define _SYS_REFCNT_H_
+
+struct refcnt {
+ unsigned int refs;
+};
+
+#define REFCNT_INITIALIZER() { .refs = 1 }
+
+#ifdef _KERNEL
+
+void refcnt_init(struct refcnt *);
+void refcnt_take(struct refcnt *);
+int refcnt_rele(struct refcnt *);
+void refcnt_rele_wake(struct refcnt *);
+void refcnt_finalize(struct refcnt *, const char *);
+
+#endif /* _KERNEL */
+
+#endif /* _SYS_REFCNT_H_ */
diff --git a/sys/sys/resource.h b/sys/sys/resource.h
new file mode 100644
index 0000000..9ca4bb6
--- /dev/null
+++ b/sys/sys/resource.h
@@ -0,0 +1,128 @@
+/* $OpenBSD: resource.h,v 1.14 2013/10/25 04:42:48 guenther Exp $ */
+/* $NetBSD: resource.h,v 1.14 1996/02/09 18:25:27 christos 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.
+ * 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.
+ *
+ * @(#)resource.h 8.2 (Berkeley) 1/4/94
+ */
+
+#ifndef _SYS_RESOURCE_H_
+#define _SYS_RESOURCE_H_
+
+#include <sys/time.h>
+
+/*
+ * Process priority specifications to get/setpriority.
+ */
+#define PRIO_MIN (-20)
+#define PRIO_MAX 20
+
+#define PRIO_PROCESS 0
+#define PRIO_PGRP 1
+#define PRIO_USER 2
+
+/*
+ * Resource utilization information.
+ */
+
+#define RUSAGE_SELF 0
+#define RUSAGE_CHILDREN (-1)
+#define RUSAGE_THREAD 1
+
+struct rusage {
+ struct timeval ru_utime; /* user time used */
+ struct timeval ru_stime; /* system time used */
+ long ru_maxrss; /* max resident set size */
+#define ru_first ru_ixrss
+ long ru_ixrss; /* integral shared text memory size */
+ long ru_idrss; /* integral unshared data " */
+ long ru_isrss; /* integral unshared stack " */
+ long ru_minflt; /* page reclaims */
+ long ru_majflt; /* page faults */
+ long ru_nswap; /* swaps */
+ long ru_inblock; /* block input operations */
+ long ru_oublock; /* block output operations */
+ long ru_msgsnd; /* messages sent */
+ long ru_msgrcv; /* messages received */
+ long ru_nsignals; /* signals received */
+ long ru_nvcsw; /* voluntary context switches */
+ long ru_nivcsw; /* involuntary " */
+#define ru_last ru_nivcsw
+};
+
+/*
+ * Resource limits
+ */
+#define RLIMIT_CPU 0 /* cpu time in milliseconds */
+#define RLIMIT_FSIZE 1 /* maximum file size */
+#define RLIMIT_DATA 2 /* data size */
+#define RLIMIT_STACK 3 /* stack size */
+#define RLIMIT_CORE 4 /* core file size */
+#define RLIMIT_RSS 5 /* resident set size */
+#define RLIMIT_MEMLOCK 6 /* locked-in-memory address space */
+#define RLIMIT_NPROC 7 /* number of processes */
+#define RLIMIT_NOFILE 8 /* number of open files */
+
+#define RLIM_NLIMITS 9 /* number of resource limits */
+
+#define RLIM_INFINITY (((rlim_t)1 << 63) - 1)
+#define RLIM_SAVED_MAX RLIM_INFINITY
+#define RLIM_SAVED_CUR RLIM_INFINITY
+
+struct rlimit {
+ rlim_t rlim_cur; /* current (soft) limit */
+ rlim_t rlim_max; /* maximum value for rlim_cur */
+};
+
+#if __BSD_VISIBLE
+/* Load average structure. */
+struct loadavg {
+ fixpt_t ldavg[3];
+ long fscale;
+};
+#endif /* __BSD_VISIBLE */
+
+#ifdef _KERNEL
+extern struct loadavg averunnable;
+struct process;
+int dosetrlimit(struct proc *, u_int, struct rlimit *);
+int donice(struct proc *, struct process *, int);
+int dogetrusage(struct proc *, int, struct rusage *);
+
+#else
+__BEGIN_DECLS
+int getpriority(int, id_t);
+int getrlimit(int, struct rlimit *);
+int getrusage(int, struct rusage *);
+int setpriority(int, id_t, int);
+int setrlimit(int, const struct rlimit *);
+__END_DECLS
+
+#endif /* _KERNEL */
+#endif /* !_SYS_RESOURCE_H_ */
diff --git a/sys/sys/resourcevar.h b/sys/sys/resourcevar.h
new file mode 100644
index 0000000..4200758
--- /dev/null
+++ b/sys/sys/resourcevar.h
@@ -0,0 +1,107 @@
+/* $OpenBSD: resourcevar.h,v 1.24 2019/06/21 09:39:48 visa Exp $ */
+/* $NetBSD: resourcevar.h,v 1.12 1995/11/22 23:01:53 cgd Exp $ */
+
+/*
+ * Copyright (c) 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.
+ * 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.
+ *
+ * @(#)resourcevar.h 8.3 (Berkeley) 2/22/94
+ */
+
+#ifndef _SYS_RESOURCEVAR_H_
+#define _SYS_RESOURCEVAR_H_
+
+#include <sys/timeout.h>
+
+/*
+ * Kernel shareable process resource limits. Because this structure
+ * is moderately large but changes infrequently, it is shared
+ * copy-on-write after forks.
+ */
+struct plimit {
+ struct rlimit pl_rlimit[RLIM_NLIMITS];
+ u_int pl_refcnt; /* number of references */
+};
+
+/* add user profiling from AST */
+#define ADDUPROF(p) \
+do { \
+ atomic_clearbits_int(&(p)->p_flag, P_OWEUPC); \
+ addupc_task((p), (p)->p_prof_addr, (p)->p_prof_ticks); \
+ (p)->p_prof_ticks = 0; \
+} while (0)
+
+#ifdef _KERNEL
+
+#include <lib/libkern/libkern.h> /* for KASSERT() */
+
+void addupc_intr(struct proc *, u_long);
+void addupc_task(struct proc *, u_long, u_int);
+void tuagg_unlocked(struct process *, struct proc *);
+void tuagg(struct process *, struct proc *);
+struct tusage;
+void calctsru(struct tusage *, struct timespec *, struct timespec *,
+ struct timespec *);
+void calcru(struct tusage *, struct timeval *, struct timeval *,
+ struct timeval *);
+void lim_startup(struct plimit *);
+void lim_free(struct plimit *);
+void lim_fork(struct process *, struct process *);
+struct plimit *lim_read_enter(void);
+
+/*
+ * Finish read access to resource limits.
+ */
+static inline void
+lim_read_leave(struct plimit *limit)
+{
+ /* nothing */
+}
+
+/*
+ * Get the value of the resource limit in current process.
+ */
+static inline rlim_t
+lim_cur(int which)
+{
+ struct plimit *limit;
+ rlim_t val;
+
+ KASSERT(which >= 0 && which < RLIM_NLIMITS);
+
+ limit = lim_read_enter();
+ val = limit->pl_rlimit[which].rlim_cur;
+ lim_read_leave(limit);
+ return (val);
+}
+
+rlim_t lim_cur_proc(struct proc *, int);
+
+void ruadd(struct rusage *, struct rusage *);
+void rucheck(void *);
+#endif
+#endif /* !_SYS_RESOURCEVAR_H_ */
diff --git a/sys/sys/rwlock.h b/sys/sys/rwlock.h
new file mode 100644
index 0000000..4b32e38
--- /dev/null
+++ b/sys/sys/rwlock.h
@@ -0,0 +1,191 @@
+/* $OpenBSD: rwlock.h,v 1.26 2019/07/16 01:40:49 jsg Exp $ */
+/*
+ * Copyright (c) 2002 Artur Grabowski <art@openbsd.org>
+ *
+ * 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.
+ */
+
+/*
+ * Multiple readers, single writer lock.
+ *
+ * Simplistic implementation modelled after rw locks in Solaris.
+ *
+ * The rwl_owner has the following layout:
+ * [ owner or count of readers | wrlock | wrwant | wait ]
+ *
+ * When the WAIT bit is set (bit 0), the lock has waiters sleeping on it.
+ * When the WRWANT bit is set (bit 1), at least one waiter wants a write lock.
+ * When the WRLOCK bit is set (bit 2) the lock is currently write-locked.
+ *
+ * When write locked, the upper bits contain the struct proc * pointer to
+ * the writer, otherwise they count the number of readers.
+ *
+ * We provide a simple machine independent implementation:
+ *
+ * void rw_enter_read(struct rwlock *)
+ * atomically test for RWLOCK_WRLOCK and if not set, increment the lock
+ * by RWLOCK_READ_INCR. While RWLOCK_WRLOCK is set, loop into rw_enter_wait.
+ *
+ * void rw_enter_write(struct rwlock *);
+ * atomically test for the lock being 0 (it's not possible to have
+ * owner/read count unset and waiter bits set) and if 0 set the owner to
+ * the proc and RWLOCK_WRLOCK. While not zero, loop into rw_enter_wait.
+ *
+ * void rw_exit_read(struct rwlock *);
+ * atomically decrement lock by RWLOCK_READ_INCR and unset RWLOCK_WAIT and
+ * RWLOCK_WRWANT remembering the old value of lock and if RWLOCK_WAIT was set,
+ * call rw_exit_waiters with the old contents of the lock.
+ *
+ * void rw_exit_write(struct rwlock *);
+ * atomically swap the contents of the lock with 0 and if RWLOCK_WAIT was
+ * set, call rw_exit_waiters with the old contents of the lock.
+ */
+
+#ifndef _SYS_RWLOCK_H
+#define _SYS_RWLOCK_H
+
+#include <sys/_lock.h>
+
+struct proc;
+
+struct rwlock {
+ volatile unsigned long rwl_owner;
+ const char *rwl_name;
+#ifdef WITNESS
+ struct lock_object rwl_lock_obj;
+#endif
+};
+
+#define RWLOCK_LO_FLAGS(flags) \
+ ((ISSET(flags, RWL_DUPOK) ? LO_DUPOK : 0) | \
+ (ISSET(flags, RWL_NOWITNESS) ? 0 : LO_WITNESS) | \
+ (ISSET(flags, RWL_IS_VNODE) ? LO_IS_VNODE : 0) | \
+ LO_INITIALIZED | LO_SLEEPABLE | LO_UPGRADABLE | \
+ (LO_CLASS_RWLOCK << LO_CLASSSHIFT))
+
+#define RRWLOCK_LO_FLAGS(flags) \
+ ((ISSET(flags, RWL_DUPOK) ? LO_DUPOK : 0) | \
+ (ISSET(flags, RWL_NOWITNESS) ? 0 : LO_WITNESS) | \
+ (ISSET(flags, RWL_IS_VNODE) ? LO_IS_VNODE : 0) | \
+ LO_INITIALIZED | LO_RECURSABLE | LO_SLEEPABLE | LO_UPGRADABLE | \
+ (LO_CLASS_RRWLOCK << LO_CLASSSHIFT))
+
+#define RWLOCK_LO_INITIALIZER(name, flags) \
+ { .lo_type = &(const struct lock_type){ .lt_name = name }, \
+ .lo_name = (name), \
+ .lo_flags = RWLOCK_LO_FLAGS(flags) }
+
+#define RWL_DUPOK 0x01
+#define RWL_NOWITNESS 0x02
+#define RWL_IS_VNODE 0x04
+
+#ifdef WITNESS
+#define RWLOCK_INITIALIZER(name) \
+ { 0, name, .rwl_lock_obj = RWLOCK_LO_INITIALIZER(name, 0) }
+#else
+#define RWLOCK_INITIALIZER(name) \
+ { 0, name }
+#endif
+
+#define RWLOCK_WAIT 0x01UL
+#define RWLOCK_WRWANT 0x02UL
+#define RWLOCK_WRLOCK 0x04UL
+#define RWLOCK_MASK 0x07UL
+
+#define RWLOCK_OWNER(rwl) ((struct proc *)((rwl)->rwl_owner & ~RWLOCK_MASK))
+
+#define RWLOCK_READER_SHIFT 3UL
+#define RWLOCK_READ_INCR (1UL << RWLOCK_READER_SHIFT)
+
+#define RW_WRITE 0x0001UL /* exclusive lock */
+#define RW_READ 0x0002UL /* shared lock */
+#define RW_DOWNGRADE 0x0004UL /* downgrade exclusive to shared */
+#define RW_OPMASK 0x0007UL
+
+#define RW_INTR 0x0010UL /* interruptible sleep */
+#define RW_SLEEPFAIL 0x0020UL /* fail if we slept for the lock */
+#define RW_NOSLEEP 0x0040UL /* don't wait for the lock */
+#define RW_RECURSEFAIL 0x0080UL /* Fail on recursion for RRW locks. */
+#define RW_DUPOK 0x0100UL /* Permit duplicate lock */
+
+/*
+ * for rw_status() and rrw_status() only: exclusive lock held by
+ * some other thread
+ */
+#define RW_WRITE_OTHER 0x0100UL
+
+/* recursive rwlocks; */
+struct rrwlock {
+ struct rwlock rrwl_lock;
+ uint32_t rrwl_wcnt; /* # writers. */
+};
+
+#ifdef _KERNEL
+
+void _rw_init_flags(struct rwlock *, const char *, int,
+ const struct lock_type *);
+
+#ifdef WITNESS
+#define rw_init_flags(rwl, name, flags) do { \
+ static const struct lock_type __lock_type = { .lt_name = #rwl };\
+ _rw_init_flags(rwl, name, flags, &__lock_type); \
+} while (0)
+#define rw_init(rwl, name) rw_init_flags(rwl, name, 0)
+#else /* WITNESS */
+#define rw_init_flags(rwl, name, flags) \
+ _rw_init_flags(rwl, name, flags, NULL)
+#define rw_init(rwl, name) _rw_init_flags(rwl, name, 0, NULL)
+#endif /* WITNESS */
+
+void rw_enter_read(struct rwlock *);
+void rw_enter_write(struct rwlock *);
+void rw_exit_read(struct rwlock *);
+void rw_exit_write(struct rwlock *);
+
+#ifdef DIAGNOSTIC
+void rw_assert_wrlock(struct rwlock *);
+void rw_assert_rdlock(struct rwlock *);
+void rw_assert_anylock(struct rwlock *);
+void rw_assert_unlocked(struct rwlock *);
+#else
+#define rw_assert_wrlock(rwl) ((void)0)
+#define rw_assert_rdlock(rwl) ((void)0)
+#define rw_assert_anylock(rwl) ((void)0)
+#define rw_assert_unlocked(rwl) ((void)0)
+#endif
+
+int rw_enter(struct rwlock *, int);
+void rw_exit(struct rwlock *);
+int rw_status(struct rwlock *);
+
+void _rrw_init_flags(struct rrwlock *, const char *, int,
+ const struct lock_type *);
+int rrw_enter(struct rrwlock *, int);
+void rrw_exit(struct rrwlock *);
+int rrw_status(struct rrwlock *);
+
+#ifdef WITNESS
+#define rrw_init_flags(rrwl, name, flags) do { \
+ static const struct lock_type __lock_type = { .lt_name = #rrwl };\
+ _rrw_init_flags(rrwl, name, flags, &__lock_type); \
+} while (0)
+#define rrw_init(rrwl, name) rrw_init_flags(rrwl, name, 0)
+#else /* WITNESS */
+#define rrw_init_flags(rrwl, name, flags) \
+ _rrw_init_flags(rrwl, name, 0, NULL)
+#define rrw_init(rrwl, name) _rrw_init_flags(rrwl, name, 0, NULL)
+#endif /* WITNESS */
+
+#endif /* _KERNEL */
+
+#endif /* _SYS_RWLOCK_H */
diff --git a/sys/sys/sched.h b/sys/sys/sched.h
new file mode 100644
index 0000000..279d50f
--- /dev/null
+++ b/sys/sys/sched.h
@@ -0,0 +1,244 @@
+/* $OpenBSD: sched.h,v 1.56 2019/10/21 10:24:01 mpi Exp $ */
+/* $NetBSD: sched.h,v 1.2 1999/02/28 18:14:58 ross Exp $ */
+
+/*-
+ * Copyright (c) 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Ross Harvey.
+ *
+ * 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) 1982, 1986, 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)kern_clock.c 8.5 (Berkeley) 1/21/94
+ */
+
+#ifndef _SYS_SCHED_H_
+#define _SYS_SCHED_H_
+
+#include <sys/queue.h>
+
+/*
+ * Posix defines a <sched.h> which may want to include <sys/sched.h>
+ */
+
+/*
+ * CPU states.
+ * XXX Not really scheduler state, but no other good place to put
+ * it right now, and it really is per-CPU.
+ */
+#define CP_USER 0
+#define CP_NICE 1
+#define CP_SYS 2
+#define CP_SPIN 3
+#define CP_INTR 4
+#define CP_IDLE 5
+#define CPUSTATES 6
+
+#define SCHED_NQS 32 /* 32 run queues. */
+
+struct smr_entry;
+
+/*
+ * Per-CPU scheduler state.
+ */
+struct schedstate_percpu {
+ struct proc *spc_idleproc; /* idle proc for this cpu */
+ TAILQ_HEAD(prochead, proc) spc_qs[SCHED_NQS];
+ LIST_HEAD(,proc) spc_deadproc;
+ struct timespec spc_runtime; /* time curproc started running */
+ volatile int spc_schedflags; /* flags; see below */
+ u_int spc_schedticks; /* ticks for schedclock() */
+ u_int64_t spc_cp_time[CPUSTATES]; /* CPU state statistics */
+ u_char spc_curpriority; /* usrpri of curproc */
+ int spc_rrticks; /* ticks until roundrobin() */
+ int spc_pscnt; /* prof/stat counter */
+ int spc_psdiv; /* prof/stat divisor */
+
+ u_int spc_nrun; /* procs on the run queues */
+ fixpt_t spc_ldavg; /* shortest load avg. for this cpu */
+
+ volatile uint32_t spc_whichqs;
+ volatile u_int spc_spinning; /* this cpu is currently spinning */
+
+ SIMPLEQ_HEAD(, smr_entry) spc_deferred; /* deferred smr calls */
+ u_int spc_ndeferred; /* number of deferred smr calls */
+ u_int spc_smrdepth; /* level of smr nesting */
+ u_char spc_smrexpedite; /* if set, dispatch smr entries
+ * without delay */
+};
+
+struct cpustats {
+ uint64_t cs_time[CPUSTATES]; /* CPU state statistics */
+ uint64_t cs_flags; /* see below */
+};
+
+#define CPUSTATS_ONLINE 0x0001 /* CPU is schedulable */
+
+#ifdef _KERNEL
+
+/* spc_flags */
+#define SPCF_SEENRR 0x0001 /* process has seen roundrobin() */
+#define SPCF_SHOULDYIELD 0x0002 /* process should yield the CPU */
+#define SPCF_SWITCHCLEAR (SPCF_SEENRR|SPCF_SHOULDYIELD)
+#define SPCF_SHOULDHALT 0x0004 /* CPU should be vacated */
+#define SPCF_HALTED 0x0008 /* CPU has been halted */
+
+#define SCHED_PPQ (128 / SCHED_NQS) /* priorities per queue */
+#define NICE_WEIGHT 2 /* priorities per nice level */
+#define ESTCPULIM(e) min((e), NICE_WEIGHT * PRIO_MAX - SCHED_PPQ)
+
+extern int schedhz; /* ideally: 16 */
+extern int rrticks_init; /* ticks per roundrobin() */
+
+struct proc;
+void schedclock(struct proc *);
+struct cpu_info;
+void roundrobin(struct cpu_info *);
+void scheduler_start(void);
+void userret(struct proc *p);
+
+void sched_init_cpu(struct cpu_info *);
+void sched_idle(void *);
+void sched_exit(struct proc *);
+void mi_switch(void);
+void cpu_switchto(struct proc *, struct proc *);
+struct proc *sched_chooseproc(void);
+struct cpu_info *sched_choosecpu(struct proc *);
+struct cpu_info *sched_choosecpu_fork(struct proc *parent, int);
+void cpu_idle_enter(void);
+void cpu_idle_cycle(void);
+void cpu_idle_leave(void);
+void sched_peg_curproc(struct cpu_info *ci);
+void sched_barrier(struct cpu_info *ci);
+
+int sysctl_hwsetperf(void *, size_t *, void *, size_t);
+int sysctl_hwperfpolicy(void *, size_t *, void *, size_t);
+int sysctl_hwsmt(void *, size_t *, void *, size_t);
+int sysctl_hwncpuonline(void);
+
+#ifdef MULTIPROCESSOR
+void sched_start_secondary_cpus(void);
+void sched_stop_secondary_cpus(void);
+#endif
+
+#define cpu_is_idle(ci) ((ci)->ci_schedstate.spc_whichqs == 0)
+int cpu_is_online(struct cpu_info *);
+
+void sched_init_runqueues(void);
+void setrunqueue(struct cpu_info *, struct proc *, uint8_t);
+void remrunqueue(struct proc *);
+
+/* Chargeback parents for the sins of their children. */
+#define scheduler_wait_hook(parent, child) do { \
+ (parent)->p_estcpu = ESTCPULIM((parent)->p_estcpu + (child)->p_estcpu);\
+} while (0)
+
+/* Allow other processes to progress */
+#define sched_pause(func) do { \
+ if (curcpu()->ci_schedstate.spc_schedflags & SPCF_SHOULDYIELD) \
+ func(); \
+} while (0)
+
+#if defined(MULTIPROCESSOR)
+#include <sys/lock.h>
+
+/*
+ * XXX Instead of using struct lock for the kernel lock and thus requiring us
+ * XXX to implement simplelocks, causing all sorts of fine-grained locks all
+ * XXX over our tree to be activated, the sched_lock is a different kind of
+ * XXX lock to avoid introducing locking protocol bugs.
+ */
+extern struct __mp_lock sched_lock;
+
+#define SCHED_ASSERT_LOCKED() \
+do { \
+ splassert(IPL_SCHED); \
+ KASSERT(__mp_lock_held(&sched_lock, curcpu())); \
+} while (0)
+#define SCHED_ASSERT_UNLOCKED() \
+do { \
+ KASSERT(__mp_lock_held(&sched_lock, curcpu()) == 0); \
+} while (0)
+
+#define SCHED_LOCK_INIT() __mp_lock_init(&sched_lock)
+
+#define SCHED_LOCK(s) \
+do { \
+ s = splsched(); \
+ __mp_lock(&sched_lock); \
+} while (/* CONSTCOND */ 0)
+
+#define SCHED_UNLOCK(s) \
+do { \
+ __mp_unlock(&sched_lock); \
+ splx(s); \
+} while (/* CONSTCOND */ 0)
+
+#else /* ! MULTIPROCESSOR */
+
+#define SCHED_ASSERT_LOCKED() splassert(IPL_SCHED);
+#define SCHED_ASSERT_UNLOCKED() /* nothing */
+
+#define SCHED_LOCK_INIT() /* nothing */
+
+#define SCHED_LOCK(s) s = splsched()
+#define SCHED_UNLOCK(s) splx(s)
+
+#endif /* MULTIPROCESSOR */
+
+#endif /* _KERNEL */
+#endif /* _SYS_SCHED_H_ */
diff --git a/sys/sys/scsiio.h b/sys/sys/scsiio.h
new file mode 100644
index 0000000..a217355
--- /dev/null
+++ b/sys/sys/scsiio.h
@@ -0,0 +1,74 @@
+/* $OpenBSD: scsiio.h,v 1.10 2012/09/05 17:17:47 deraadt Exp $ */
+/* $NetBSD: scsiio.h,v 1.3 1994/06/29 06:45:09 cgd Exp $ */
+
+#ifndef _SYS_SCSIIO_H_
+#define _SYS_SCSIIO_H_
+
+
+#include <sys/types.h>
+#include <sys/ioctl.h>
+
+#define SENSEBUFLEN 48
+#define CMDBUFLEN 16
+
+typedef struct scsireq {
+ u_long flags; /* info about the request status and type */
+ u_long timeout;
+ u_char cmd[CMDBUFLEN];
+ u_char cmdlen;
+ caddr_t databuf; /* address in user space of buffer */
+ u_long datalen; /* size of user buffer (request) */
+ u_long datalen_used; /* size of user buffer (used)*/
+ u_char sense[SENSEBUFLEN]; /* returned sense will be in here */
+ u_char senselen; /* sensedata request size (MAX of SENSEBUFLEN)*/
+ u_char senselen_used; /* return value only */
+ u_char status; /* what the scsi status was from the adapter */
+ u_char retsts; /* the return status for the command */
+ int error; /* error bits */
+} scsireq_t;
+
+/* bit definitions for flags */
+#define SCCMD_READ 0x00000001
+#define SCCMD_WRITE 0x00000002
+#define SCCMD_IOV 0x00000004
+#define SCCMD_ESCAPE 0x00000010
+#define SCCMD_TARGET 0x00000020
+
+
+/* definitions for the return status (retsts) */
+#define SCCMD_OK 0x00
+#define SCCMD_TIMEOUT 0x01
+#define SCCMD_BUSY 0x02
+#define SCCMD_SENSE 0x03
+#define SCCMD_UNKNOWN 0x04
+
+#define SCIOCCOMMAND _IOWR('Q', 1, scsireq_t)
+
+#define SC_DB_CMDS 0x00000001 /* show all scsi cmds and errors */
+#define SC_DB_FLOW 0x00000002 /* show routines entered */
+#define SC_DB_FLOW2 0x00000004 /* show path INSIDE routines */
+#define SC_DB_DMA 0x00000008 /* show DMA segments etc */
+#define SCIOCDEBUG _IOW('Q', 2, int) /* from 0 to 15 */
+
+struct scsi_addr {
+ int type;
+#define TYPE_SCSI 0
+#define TYPE_ATAPI 1
+ int scbus; /* -1 if wildcard */
+ int target; /* -1 if wildcard */
+ int lun; /* -1 if wildcard */
+};
+
+#define SCIOCRESET _IO('Q', 7) /* reset the device */
+#define SCIOCIDENTIFY _IOR('Q', 9, struct scsi_addr)
+
+struct sbioc_device {
+ void *sd_cookie;
+ int sd_target;
+ int sd_lun;
+};
+
+#define SBIOCPROBE _IOWR('Q', 127, struct sbioc_device)
+#define SBIOCDETACH _IOWR('Q', 128, struct sbioc_device)
+
+#endif /* _SYS_SCSIIO_H_ */
diff --git a/sys/sys/select.h b/sys/sys/select.h
new file mode 100644
index 0000000..3c7aa20
--- /dev/null
+++ b/sys/sys/select.h
@@ -0,0 +1,137 @@
+/* $OpenBSD: select.h,v 1.17 2016/09/12 19:41:20 guenther Exp $ */
+
+/*-
+ * 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.
+ *
+ * @(#)select.h 8.2 (Berkeley) 1/4/94
+ */
+
+#ifndef _SYS_SELECT_H_
+#define _SYS_SELECT_H_
+
+#include <sys/types.h>
+
+#ifndef _TIMEVAL_DECLARED
+#define _TIMEVAL_DECLARED
+struct timeval {
+ time_t tv_sec; /* seconds */
+ suseconds_t tv_usec; /* and microseconds */
+};
+#endif
+
+#ifndef _TIMESPEC_DECLARED
+#define _TIMESPEC_DECLARED
+struct timespec {
+ time_t tv_sec; /* seconds */
+ long tv_nsec; /* and nanoseconds */
+};
+#endif
+
+/*
+ * Select uses bit masks of file descriptors in longs. These macros
+ * manipulate such bit fields (the filesystem macros use chars).
+ * FD_SETSIZE may be defined by the user, but the default here should
+ * be enough for most uses.
+ */
+#ifndef FD_SETSIZE
+#define FD_SETSIZE 1024
+#endif
+
+/*
+ * We don't want to pollute the namespace with select(2) internals.
+ * Non-underscore versions are exposed later #if __BSD_VISIBLE
+ */
+#define __NBBY 8 /* number of bits in a byte */
+typedef uint32_t __fd_mask;
+#define __NFDBITS ((unsigned)(sizeof(__fd_mask) * __NBBY)) /* bits per mask */
+#define __howmany(x, y) (((x) + ((y) - 1)) / (y))
+
+typedef struct fd_set {
+ __fd_mask fds_bits[__howmany(FD_SETSIZE, __NFDBITS)];
+} fd_set;
+
+static __inline void
+__fd_set(int fd, fd_set *p)
+{
+ p->fds_bits[fd / __NFDBITS] |= (1U << (fd % __NFDBITS));
+}
+#define FD_SET(n, p) __fd_set((n), (p))
+
+static __inline void
+__fd_clr(int fd, fd_set *p)
+{
+ p->fds_bits[fd / __NFDBITS] &= ~(1U << (fd % __NFDBITS));
+}
+#define FD_CLR(n, p) __fd_clr((n), (p))
+
+static __inline int
+__fd_isset(int fd, const fd_set *p)
+{
+ return (p->fds_bits[fd / __NFDBITS] & (1U << (fd % __NFDBITS)));
+}
+#define FD_ISSET(n, p) __fd_isset((n), (p))
+
+#if __BSD_VISIBLE
+#define FD_COPY(f, t) (void)(*(t) = *(f))
+#endif
+#define FD_ZERO(p) do { \
+ fd_set *_p = (p); \
+ __size_t _n = __howmany(FD_SETSIZE, __NFDBITS); \
+ \
+ while (_n > 0) \
+ _p->fds_bits[--_n] = 0; \
+} while (0)
+
+#if __BSD_VISIBLE
+#define NBBY __NBBY
+#define fd_mask __fd_mask
+#define NFDBITS __NFDBITS
+#ifndef howmany
+#define howmany(x, y) __howmany(x, y)
+#endif
+#endif /* __BSD_VISIBLE */
+
+#ifndef _KERNEL
+#ifndef _SIGSET_T_DEFINED_
+#define _SIGSET_T_DEFINED_
+typedef unsigned int sigset_t;
+#endif
+
+#ifndef _SELECT_DEFINED_
+#define _SELECT_DEFINED_
+__BEGIN_DECLS
+int select(int, fd_set * __restrict, fd_set * __restrict,
+ fd_set * __restrict, struct timeval * __restrict);
+int pselect(int, fd_set * __restrict, fd_set * __restrict,
+ fd_set * __restrict, const struct timespec * __restrict,
+ const sigset_t * __restrict);
+__END_DECLS
+#endif
+#endif /* !_KERNEL */
+
+#endif /* !_SYS_SELECT_H_ */
diff --git a/sys/sys/selinfo.h b/sys/sys/selinfo.h
new file mode 100644
index 0000000..1d9431b
--- /dev/null
+++ b/sys/sys/selinfo.h
@@ -0,0 +1,57 @@
+/* $OpenBSD: selinfo.h,v 1.5 2017/07/18 19:20:26 sf Exp $ */
+
+/*-
+ * 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.
+ *
+ * @(#)select.h 8.2 (Berkeley) 1/4/94
+ */
+
+#ifndef _SYS_SELINFO_H_
+#define _SYS_SELINFO_H_
+
+#include <sys/event.h> /* for struct klist */
+
+/*
+ * Used to maintain information about processes that wish to be
+ * notified when I/O becomes possible.
+ */
+struct selinfo {
+ struct klist si_note; /* kernel note list */
+ pid_t si_seltid; /* thread to be notified */
+ short si_flags; /* see below */
+};
+#define SI_COLL 0x0001 /* collision occurred */
+
+#ifdef _KERNEL
+struct proc;
+
+void selrecord(struct proc *selector, struct selinfo *);
+void selwakeup(struct selinfo *);
+#endif
+
+#endif /* !_SYS_SELINFO_H_ */
diff --git a/sys/sys/sem.h b/sys/sys/sem.h
new file mode 100644
index 0000000..184482d
--- /dev/null
+++ b/sys/sys/sem.h
@@ -0,0 +1,198 @@
+/* $OpenBSD: sem.h,v 1.24 2016/09/01 08:33:40 tom Exp $ */
+/* $NetBSD: sem.h,v 1.8 1996/02/09 18:25:29 christos Exp $ */
+
+/*
+ * SVID compatible sem.h file
+ *
+ * Author: Daniel Boulet
+ */
+
+#ifndef _SYS_SEM_H_
+#define _SYS_SEM_H_
+
+#ifndef _SYS_IPC_H_
+#include <sys/ipc.h>
+#endif
+
+#if __BSD_VISIBLE
+
+/* sem-specific sysctl variables corresponding to members of struct seminfo */
+#define KERN_SEMINFO_SEMMNI 1 /* int: # of semaphore identifiers */
+#define KERN_SEMINFO_SEMMNS 2 /* int: # of semaphores in system */
+#define KERN_SEMINFO_SEMMNU 3 /* int: # of undo structures in system */
+#define KERN_SEMINFO_SEMMSL 4 /* int: max semaphores per id */
+#define KERN_SEMINFO_SEMOPM 5 /* int: max operations per semop call */
+#define KERN_SEMINFO_SEMUME 6 /* int: max undo entries per process */
+#define KERN_SEMINFO_SEMUSZ 7 /* int: size in bytes of struct undo */
+#define KERN_SEMINFO_SEMVMX 8 /* int: semaphore maximum value */
+#define KERN_SEMINFO_SEMAEM 9 /* int: adjust on exit max value */
+#define KERN_SEMINFO_MAXID 10 /* number of valid semaphore sysctls */
+
+#define CTL_KERN_SEMINFO_NAMES { \
+ { 0, 0 }, \
+ { "semmni", CTLTYPE_INT }, \
+ { "semmns", CTLTYPE_INT }, \
+ { "semmnu", CTLTYPE_INT }, \
+ { "semmsl", CTLTYPE_INT }, \
+ { "semopm", CTLTYPE_INT }, \
+ { "semume", CTLTYPE_INT }, \
+ { "semusz", CTLTYPE_INT }, \
+ { "semvmx", CTLTYPE_INT }, \
+ { "semaem", CTLTYPE_INT }, \
+}
+
+#endif /* __BSD_VISIBLE */
+
+struct sem {
+ unsigned short semval; /* semaphore value */
+ pid_t sempid; /* pid of last operation */
+ unsigned short semncnt; /* # awaiting semval > cval */
+ unsigned short semzcnt; /* # awaiting semval = 0 */
+};
+
+struct semid_ds {
+ struct ipc_perm sem_perm; /* operation permission struct */
+ struct sem *sem_base; /* pointer to first semaphore in set */
+ unsigned short sem_nsems; /* number of sems in set */
+ time_t sem_otime; /* last operation time */
+ long sem_pad1; /* SVABI/386 says I need this here */
+ time_t sem_ctime; /* last change time */
+ /* Times measured in secs since */
+ /* 00:00:00 GMT, Jan. 1, 1970 */
+ long sem_pad2; /* SVABI/386 says I need this here */
+ long sem_pad3[4]; /* SVABI/386 says I need this here */
+};
+
+/*
+ * semop's sops parameter structure
+ */
+struct sembuf {
+ unsigned short sem_num; /* semaphore # */
+ short sem_op; /* semaphore operation */
+ short sem_flg; /* operation flags */
+};
+#define SEM_UNDO 010000
+
+/*
+ * semctl's arg parameter structure
+ */
+union semun {
+ int val; /* value for SETVAL */
+ struct semid_ds *buf; /* buffer for IPC_STAT & IPC_SET */
+ unsigned short *array; /* array for GETALL & SETALL */
+};
+
+/*
+ * commands for semctl
+ */
+#define GETNCNT 3 /* Return the value of semncnt {READ} */
+#define GETPID 4 /* Return the value of sempid {READ} */
+#define GETVAL 5 /* Return the value of semval {READ} */
+#define GETALL 6 /* Return semvals into arg.array {READ} */
+#define GETZCNT 7 /* Return the value of semzcnt {READ} */
+#define SETVAL 8 /* Set the value of semval to arg.val {ALTER} */
+#define SETALL 9 /* Set semvals from arg.array {ALTER} */
+
+
+/*
+ * Permissions
+ */
+#define SEM_A 0200 /* alter permission */
+#define SEM_R 0400 /* read permission */
+
+
+#ifdef _KERNEL
+#include <sys/queue.h>
+
+/*
+ * Kernel implementation stuff
+ */
+#define SEMVMX 32767 /* semaphore maximum value */
+#define SEMAEM 16384 /* adjust on exit max value */
+
+/*
+ * Undo structure (one per process)
+ */
+struct sem_undo {
+ SLIST_ENTRY(sem_undo) un_next; /* ptr to next active undo structure */
+ struct process *un_proc; /* owner of this structure */
+ short un_cnt; /* # of active entries */
+ struct undo {
+ short un_adjval; /* adjust on exit values */
+ short un_num; /* semaphore # */
+ int un_id; /* semid */
+ } un_ent[1]; /* undo entries */
+};
+
+/*
+ * semaphore info struct
+ */
+struct seminfo {
+ int semmni, /* # of semaphore identifiers */
+ semmns, /* # of semaphores in system */
+ semmnu, /* # of undo structures in system */
+ semmsl, /* max # of semaphores per id */
+ semopm, /* max # of operations per semop call */
+ semume, /* max # of undo entries per process */
+ semusz, /* size in bytes of undo structure */
+ semvmx, /* semaphore maximum value */
+ semaem; /* adjust on exit max value */
+};
+
+struct sem_sysctl_info {
+ struct seminfo seminfo;
+ struct semid_ds semids[1];
+};
+
+extern struct seminfo seminfo;
+
+/*
+ * Configuration parameters
+ */
+#ifndef SEMMNI
+#define SEMMNI 10 /* # of semaphore identifiers */
+#endif
+#ifndef SEMMNS
+#define SEMMNS 60 /* # of semaphores in system */
+#endif
+#ifndef SEMUME
+#define SEMUME 10 /* max # of undo entries per process */
+#endif
+#ifndef SEMMNU
+#define SEMMNU 30 /* # of undo structures in system */
+#endif
+
+/* shouldn't need tuning */
+#ifndef SEMMSL
+#define SEMMSL SEMMNS /* max # of semaphores per id */
+#endif
+#ifndef SEMOPM
+#define SEMOPM 100 /* max # of operations per semop call */
+#endif
+
+/* actual size of an undo structure */
+#define SEMUSZ (sizeof(struct sem_undo)+sizeof(struct undo)*SEMUME)
+
+extern struct semid_ds **sema; /* semaphore id list */
+
+struct proc;
+
+void seminit(void);
+void semexit(struct process *);
+int sysctl_sysvsem(int *, u_int, void *, size_t *, void *, size_t);
+int semctl1(struct proc *, int, int, int, union semun *, register_t *,
+ int (*)(const void *, void *, size_t),
+ int (*)(const void *, void *, size_t));
+
+#endif /* _KERNEL */
+
+#ifndef _KERNEL
+__BEGIN_DECLS
+int semctl(int, int, int, ...);
+int __semctl(int, int, int, union semun *);
+int semget(key_t, int, int);
+int semop(int, struct sembuf *, size_t);
+__END_DECLS
+#endif /* !_KERNEL */
+
+#endif /* !_SYS_SEM_H_ */
diff --git a/sys/sys/sensors.h b/sys/sys/sensors.h
new file mode 100644
index 0000000..15725a6
--- /dev/null
+++ b/sys/sys/sensors.h
@@ -0,0 +1,177 @@
+/* $OpenBSD: sensors.h,v 1.36 2018/12/10 13:35:54 landry Exp $ */
+
+/*
+ * Copyright (c) 2003, 2004 Alexander Yurchenko <grange@openbsd.org>
+ * Copyright (c) 2006 Constantine A. Murenin <cnst+openbsd@bugmail.mojo.ru>
+ * 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.
+ */
+
+#ifndef _SYS_SENSORS_H_
+#define _SYS_SENSORS_H_
+
+/* Sensor types */
+enum sensor_type {
+ SENSOR_TEMP, /* temperature (uK) */
+ SENSOR_FANRPM, /* fan revolution speed */
+ SENSOR_VOLTS_DC, /* voltage (uV DC) */
+ SENSOR_VOLTS_AC, /* voltage (uV AC) */
+ SENSOR_OHMS, /* resistance */
+ SENSOR_WATTS, /* power (uW) */
+ SENSOR_AMPS, /* current (uA) */
+ SENSOR_WATTHOUR, /* power capacity (uWh) */
+ SENSOR_AMPHOUR, /* power capacity (uAh) */
+ SENSOR_INDICATOR, /* boolean indicator */
+ SENSOR_INTEGER, /* generic integer value */
+ SENSOR_PERCENT, /* percent (m%) */
+ SENSOR_LUX, /* illuminance (ulx) */
+ SENSOR_DRIVE, /* disk */
+ SENSOR_TIMEDELTA, /* system time error (nSec) */
+ SENSOR_HUMIDITY, /* humidity (m%RH) */
+ SENSOR_FREQ, /* frequency (uHz) */
+ SENSOR_ANGLE, /* angle (uDegrees) */
+ SENSOR_DISTANCE, /* distance (uMeter) */
+ SENSOR_PRESSURE, /* pressure (mPa) */
+ SENSOR_ACCEL, /* acceleration (u m/s^2) */
+ SENSOR_VELOCITY, /* velocity (u m/s) */
+ SENSOR_MAX_TYPES
+};
+
+#ifndef _KERNEL
+static const char * const sensor_type_s[SENSOR_MAX_TYPES + 1] = {
+ "temp",
+ "fan",
+ "volt",
+ "acvolt",
+ "resistance",
+ "power",
+ "current",
+ "watthour",
+ "amphour",
+ "indicator",
+ "raw",
+ "percent",
+ "illuminance",
+ "drive",
+ "timedelta",
+ "humidity",
+ "frequency",
+ "angle",
+ "distance",
+ "pressure",
+ "acceleration",
+ "velocity",
+ "undefined"
+};
+#endif /* !_KERNEL */
+
+#define SENSOR_DRIVE_EMPTY 1
+#define SENSOR_DRIVE_READY 2
+#define SENSOR_DRIVE_POWERUP 3
+#define SENSOR_DRIVE_ONLINE 4
+#define SENSOR_DRIVE_IDLE 5
+#define SENSOR_DRIVE_ACTIVE 6
+#define SENSOR_DRIVE_REBUILD 7
+#define SENSOR_DRIVE_POWERDOWN 8
+#define SENSOR_DRIVE_FAIL 9
+#define SENSOR_DRIVE_PFAIL 10
+
+/* Sensor states */
+enum sensor_status {
+ SENSOR_S_UNSPEC, /* status is unspecified */
+ SENSOR_S_OK, /* status is ok */
+ SENSOR_S_WARN, /* status is warning */
+ SENSOR_S_CRIT, /* status is critical */
+ SENSOR_S_UNKNOWN /* status is unknown */
+};
+
+/* Sensor data:
+ * New fields should be added at the end to encourage backwards compat
+ */
+struct sensor {
+ char desc[32]; /* sensor description, may be empty */
+ struct timeval tv; /* sensor value last change time */
+ int64_t value; /* current value */
+ enum sensor_type type; /* sensor type */
+ enum sensor_status status; /* sensor status */
+ int numt; /* sensor number of .type type */
+ int flags; /* sensor flags */
+#define SENSOR_FINVALID 0x0001 /* sensor is invalid */
+#define SENSOR_FUNKNOWN 0x0002 /* sensor value is unknown */
+};
+
+/* Sensor device data:
+ * New fields should be added at the end to encourage backwards compat
+ */
+struct sensordev {
+ int num; /* sensordev number */
+ char xname[16]; /* unix device name */
+ int maxnumt[SENSOR_MAX_TYPES];
+ int sensors_count;
+};
+
+#ifdef _KERNEL
+
+/* Sensor data */
+struct ksensor {
+ SLIST_ENTRY(ksensor) list; /* device-scope list */
+ char desc[32]; /* sensor description, may be empty */
+ struct timeval tv; /* sensor value last change time */
+ int64_t value; /* current value */
+ enum sensor_type type; /* sensor type */
+ enum sensor_status status; /* sensor status */
+ int numt; /* sensor number of .type type */
+ int flags; /* sensor flags, ie. SENSOR_FINVALID */
+};
+SLIST_HEAD(ksensors_head, ksensor);
+
+/* Sensor device data */
+struct ksensordev {
+ SLIST_ENTRY(ksensordev) list;
+ int num; /* sensordev number */
+ char xname[16]; /* unix device name */
+ int maxnumt[SENSOR_MAX_TYPES];
+ int sensors_count;
+ struct ksensors_head sensors_list;
+};
+
+/* struct ksensordev */
+void sensordev_install(struct ksensordev *);
+void sensordev_deinstall(struct ksensordev *);
+int sensordev_get(int, struct ksensordev **);
+
+/* struct ksensor */
+void sensor_attach(struct ksensordev *, struct ksensor *);
+void sensor_detach(struct ksensordev *, struct ksensor *);
+int sensor_find(int, enum sensor_type, int, struct ksensor **);
+
+/* task scheduling */
+struct sensor_task;
+struct sensor_task *sensor_task_register(void *, void (*)(void *),
+ unsigned int);
+void sensor_task_unregister(struct sensor_task *);
+void sensor_quiesce(void);
+void sensor_restart(void);
+
+#endif /* _KERNEL */
+
+#endif /* !_SYS_SENSORS_H_ */
diff --git a/sys/sys/shm.h b/sys/sys/shm.h
new file mode 100644
index 0000000..d46cbbe
--- /dev/null
+++ b/sys/sys/shm.h
@@ -0,0 +1,151 @@
+/* $OpenBSD: shm.h,v 1.29 2019/11/03 20:16:01 guenther Exp $ */
+/* $NetBSD: shm.h,v 1.20 1996/04/09 20:55:35 cgd Exp $ */
+
+/*
+ * Copyright (c) 1994 Adam Glass
+ * 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. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Adam Glass.
+ * 4. 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.
+ */
+
+/*
+ * As defined+described in "X/Open System Interfaces and Headers"
+ * Issue 4, p. XXX
+ */
+
+#ifndef _SYS_SHM_H_
+#define _SYS_SHM_H_
+
+#ifndef _SYS_IPC_H_
+#include <sys/ipc.h>
+#endif
+
+#if __BSD_VISIBLE
+
+/* shm-specific sysctl variables corresponding to members of struct shminfo */
+#define KERN_SHMINFO_SHMMAX 1 /* int: max shm segment size (bytes) */
+#define KERN_SHMINFO_SHMMIN 2 /* int: min shm segment size (bytes) */
+#define KERN_SHMINFO_SHMMNI 3 /* int: max number of shm identifiers */
+#define KERN_SHMINFO_SHMSEG 4 /* int: max shm segments per process */
+#define KERN_SHMINFO_SHMALL 5 /* int: max amount of shm (pages) */
+#define KERN_SHMINFO_MAXID 6 /* number of valid shared memory ids */
+
+#define CTL_KERN_SHMINFO_NAMES { \
+ { 0, 0 }, \
+ { "shmmax", CTLTYPE_INT }, \
+ { "shmmin", CTLTYPE_INT }, \
+ { "shmmni", CTLTYPE_INT }, \
+ { "shmseg", CTLTYPE_INT }, \
+ { "shmall", CTLTYPE_INT }, \
+}
+
+/*
+ * Old (deprecated) access mode definitions--do not use.
+ * Provided for compatibility with old code only.
+ */
+#define SHM_R IPC_R
+#define SHM_W IPC_W
+
+#endif /* __BSD_VISIBLE */
+
+/*
+ * Shared memory operation flags for shmat(2).
+ */
+#define SHM_RDONLY 010000 /* Attach read-only (else read-write) */
+#define SHM_RND 020000 /* Round attach address to SHMLBA */
+
+/*
+ * Shared memory specific control commands for shmctl().
+ * We accept but ignore these (XXX).
+ */
+#define SHM_LOCK 3 /* Lock segment in memory. */
+#define SHM_UNLOCK 4 /* Unlock a segment locked by SHM_LOCK. */
+
+/*
+ * Segment low boundry address multiple
+ */
+#define SHMLBA (1U << _MAX_PAGE_SHIFT)
+
+typedef short shmatt_t;
+
+struct shmid_ds {
+ struct ipc_perm shm_perm; /* operation permission structure */
+ int shm_segsz; /* size of segment in bytes */
+ pid_t shm_lpid; /* process ID of last shm op */
+ pid_t shm_cpid; /* process ID of creator */
+ shmatt_t shm_nattch; /* number of current attaches */
+ time_t shm_atime; /* time of last shmat() */
+ long __shm_atimensec;
+ time_t shm_dtime; /* time of last shmdt() */
+ long __shm_dtimensec;
+ time_t shm_ctime; /* time of last change by shmctl() */
+ long __shm_ctimensec;
+ void *shm_internal; /* implementation specific data */
+};
+
+#if __BSD_VISIBLE
+/*
+ * System V style catch-all structure for shared memory constants that
+ * might be of interest to user programs. Do we really want/need this?
+ */
+struct shminfo {
+ int shmmax; /* max shared memory segment size (bytes) */
+ int shmmin; /* min shared memory segment size (bytes) */
+ int shmmni; /* max number of shared memory identifiers */
+ int shmseg; /* max shared memory segments per process */
+ int shmall; /* max amount of shared memory (pages) */
+};
+
+struct shm_sysctl_info {
+ struct shminfo shminfo;
+ struct shmid_ds shmids[1];
+};
+#endif /* __BSD_VISIBLE */
+
+#ifdef _KERNEL
+extern struct shminfo shminfo;
+extern struct shmid_ds **shmsegs;
+
+struct proc;
+struct vmspace;
+
+void shminit(void);
+void shmfork(struct vmspace *, struct vmspace *);
+void shmexit(struct vmspace *);
+int sysctl_sysvshm(int *, u_int, void *, size_t *, void *, size_t);
+
+#else /* !_KERNEL */
+
+__BEGIN_DECLS
+void *shmat(int, const void *, int);
+int shmctl(int, int, struct shmid_ds *);
+int shmdt(const void *);
+int shmget(key_t, size_t, int);
+__END_DECLS
+
+#endif /* !_KERNEL */
+
+#endif /* !_SYS_SHM_H_ */
diff --git a/sys/sys/siginfo.h b/sys/sys/siginfo.h
new file mode 100644
index 0000000..dd6b32f
--- /dev/null
+++ b/sys/sys/siginfo.h
@@ -0,0 +1,199 @@
+/* $OpenBSD: siginfo.h,v 1.12 2017/04/07 04:48:44 guenther Exp $ */
+
+/*
+ * Copyright (c) 1997 Theo de Raadt
+ * 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.
+ */
+
+#ifndef _SYS_SIGINFO_H
+#define _SYS_SIGINFO_H
+
+#include <sys/cdefs.h>
+
+union sigval {
+ int sival_int; /* integer value */
+ void *sival_ptr; /* pointer value */
+};
+
+/*
+ * Negative signal codes are reserved for future use for
+ * user generated signals.
+ */
+#define SI_FROMUSER(sip) ((sip)->si_code <= 0)
+#define SI_FROMKERNEL(sip) ((sip)->si_code > 0)
+
+#define SI_NOINFO 32767 /* no signal information */
+#define SI_USER 0 /* user generated signal via kill() */
+#define SI_LWP (-1) /* user generated signal via lwp_kill()*/
+#define SI_QUEUE (-2) /* user generated signal via sigqueue()*/
+#define SI_TIMER (-3) /* from timer expiration */
+
+#if __POSIX_VISIBLE >= 199309 || __XPG_VISIBLE
+/*
+ * The machine dependent signal codes (SIGILL, SIGFPE,
+ * SIGSEGV, and SIGBUS)
+ */
+#define ILL_ILLOPC 1 /* illegal opcode */
+#define ILL_ILLOPN 2 /* illegal operand */
+#define ILL_ILLADR 3 /* illegal addressing mode */
+#define ILL_ILLTRP 4 /* illegal trap */
+#define ILL_PRVOPC 5 /* privileged opcode */
+#define ILL_PRVREG 6 /* privileged register */
+#define ILL_COPROC 7 /* co-processor */
+#define ILL_BADSTK 8 /* bad stack */
+#define NSIGILL 8
+
+#define EMT_TAGOVF 1 /* tag overflow */
+#define NSIGEMT 1
+
+#define FPE_INTDIV 1 /* integer divide by zero */
+#define FPE_INTOVF 2 /* integer overflow */
+#define FPE_FLTDIV 3 /* floating point divide by zero */
+#define FPE_FLTOVF 4 /* floating point overflow */
+#define FPE_FLTUND 5 /* floating point underflow */
+#define FPE_FLTRES 6 /* floating point inexact result */
+#define FPE_FLTINV 7 /* invalid floating point operation */
+#define FPE_FLTSUB 8 /* subscript out of range */
+#define NSIGFPE 8
+
+#define SEGV_MAPERR 1 /* address not mapped to object */
+#define SEGV_ACCERR 2 /* invalid permissions */
+#define NSIGSEGV 2
+
+#define BUS_ADRALN 1 /* invalid address alignment */
+#define BUS_ADRERR 2 /* non-existent physical address */
+#define BUS_OBJERR 3 /* object specific hardware error */
+#define NSIGBUS 3
+
+#endif /* __POSIX_VISIBLE >= 199309 || __XPG_VISIBLE */
+
+/*
+ * SIGTRAP signal codes
+ */
+#define TRAP_BRKPT 1 /* breakpoint trap */
+#define TRAP_TRACE 2 /* trace trap */
+#define NSIGTRAP 2
+
+/*
+ * SIGCHLD signal codes
+ */
+#define CLD_EXITED 1 /* child has exited */
+#define CLD_KILLED 2 /* child was killed */
+#define CLD_DUMPED 3 /* child has coredumped */
+#define CLD_TRAPPED 4 /* traced child has stopped */
+#define CLD_STOPPED 5 /* child has stopped on signal */
+#define CLD_CONTINUED 6 /* stopped child has continued */
+#define NSIGCLD 6
+
+#if 0
+/*
+ * SIGPOLL signal codes - not supported
+ */
+#define POLL_IN 1 /* input available */
+#define POLL_OUT 2 /* output possible */
+#define POLL_MSG 3 /* message available */
+#define POLL_ERR 4 /* I/O error */
+#define POLL_PRI 5 /* high priority input available */
+#define POLL_HUP 6 /* device disconnected */
+#define NSIGPOLL 6
+
+/*
+ * SIGPROF signal codes - not supported
+ */
+#define PROF_SIG 1 /* have to set code non-zero */
+#define NSIGPROF 1
+#endif
+
+#define SI_MAXSZ 128
+#define SI_PAD ((SI_MAXSZ / sizeof (int)) - 3)
+
+#include <sys/time.h>
+
+typedef struct {
+ int si_signo; /* signal from signal.h */
+ int si_code; /* code from above */
+ int si_errno; /* error from errno.h */
+ union {
+ int _pad[SI_PAD]; /* for future growth */
+ struct { /* kill(), SIGCHLD */
+ pid_t _pid; /* process ID */
+ union {
+ struct {
+ uid_t _uid;
+ union sigval _value;
+ } _kill;
+ struct {
+ clock_t _utime;
+ clock_t _stime;
+ int _status;
+ } _cld;
+ } _pdata;
+ } _proc;
+ struct { /* SIGSEGV, SIGBUS, SIGILL and SIGFPE */
+ void *_addr; /* faulting address */
+ int _trapno; /* illegal trap number */
+ } _fault;
+#if 0
+ struct { /* SIGPOLL, SIGXFSZ */
+ /* fd not currently available for SIGPOLL */
+ int _fd; /* file descriptor */
+ long _band;
+ } _file;
+ struct { /* SIGPROF */
+ caddr_t _faddr; /* last fault address */
+ timespec _tstamp; /* real time stamp */
+ short _syscall; /* current syscall */
+ char _nsysarg; /* number of arguments */
+ char _fault; /* last fault type */
+ long _sysarg[8]; /* syscall arguments */
+ long _mstate[17]; /* exactly fills struct*/
+ } _prof;
+#endif
+ } _data;
+} siginfo_t;
+
+#define si_pid _data._proc._pid
+
+#define si_status _data._proc._pdata._cld._status
+#define si_stime _data._proc._pdata._cld._stime
+#define si_utime _data._proc._pdata._cld._utime
+#define si_uid _data._proc._pdata._kill._uid
+#define si_value _data._proc._pdata._kill._value
+#define si_addr _data._fault._addr
+#define si_trapno _data._fault._trapno
+#define si_fd _data._file._fd
+#define si_band _data._file._band
+
+#define si_tstamp _data._prof._tstamp
+#define si_syscall _data._prof._syscall
+#define si_nsysarg _data._prof._nsysarg
+#define si_sysarg _data._prof._sysarg
+#define si_fault _data._prof._fault
+#define si_faddr _data._prof._faddr
+#define si_mstate _data._prof._mstate
+
+#if defined(_KERNEL)
+void initsiginfo(siginfo_t *, int, u_long, int, union sigval);
+#endif
+
+#endif /* _SYS_SIGINFO_H */
diff --git a/sys/sys/sigio.h b/sys/sys/sigio.h
new file mode 100644
index 0000000..a20f983
--- /dev/null
+++ b/sys/sys/sigio.h
@@ -0,0 +1,95 @@
+/* $OpenBSD: sigio.h,v 1.4 2020/01/08 16:27:42 visa Exp $ */
+
+/*-
+ * Copyright (c) 1990, 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.
+ *
+ * @(#)filedesc.h 8.1 (Berkeley) 6/2/93
+ * $FreeBSD: head/sys/sys/sigio.h 326023 2017-11-20 19:43:44Z pfg $
+ */
+
+#ifndef _SYS_SIGIO_H_
+#define _SYS_SIGIO_H_
+
+struct sigio;
+LIST_HEAD(sigiolst, sigio);
+
+/*
+ * sigio registration
+ *
+ * Locking:
+ * S sigio_lock
+ */
+struct sigio_ref {
+ struct sigio *sir_sigio; /* [S] associated sigio struct */
+};
+
+#ifdef _KERNEL
+
+/*
+ * This structure holds the information needed to send a SIGIO or
+ * a SIGURG signal to a process or process group when new data arrives
+ * on a device or socket. The structure is placed on an LIST belonging
+ * to the proc or pgrp so that the entire list may be revoked when the
+ * process exits or the process group disappears.
+ *
+ * Locking:
+ * I immutable after creation
+ * S sigio_lock
+ */
+struct sigio {
+ union {
+ struct process *siu_proc;
+ /* [I] process to receive
+ * SIGIO/SIGURG */
+ struct pgrp *siu_pgrp; /* [I] process group to receive ... */
+ } sio_u;
+ LIST_ENTRY(sigio) sio_pgsigio; /* [S] sigio's for process or group */
+ struct sigio_ref *sio_myref; /* [I] location of the pointer that
+ * holds the reference to
+ * this structure */
+ struct ucred *sio_ucred; /* [I] current credentials */
+ pid_t sio_pgid; /* [I] pgid for signals */
+};
+#define sio_proc sio_u.siu_proc
+#define sio_pgrp sio_u.siu_pgrp
+
+static inline void
+sigio_init(struct sigio_ref *sir)
+{
+ sir->sir_sigio = NULL;
+}
+
+void sigio_copy(struct sigio_ref *, struct sigio_ref *);
+void sigio_free(struct sigio_ref *);
+void sigio_freelist(struct sigiolst *);
+void sigio_getown(struct sigio_ref *, u_long, caddr_t);
+int sigio_setown(struct sigio_ref *, u_long, caddr_t);
+
+#endif /* _KERNEL */
+
+#endif /* _SYS_SIGIO_H_ */
diff --git a/sys/sys/signal.h b/sys/sys/signal.h
new file mode 100644
index 0000000..dcb6810
--- /dev/null
+++ b/sys/sys/signal.h
@@ -0,0 +1,202 @@
+/* $OpenBSD: signal.h,v 1.29 2018/04/18 16:05:20 deraadt Exp $ */
+/* $NetBSD: signal.h,v 1.21 1996/02/09 18:25:32 christos Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 1989, 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)signal.h 8.2 (Berkeley) 1/21/94
+ */
+
+#ifndef _SYS_SIGNAL_H_
+#define _SYS_SIGNAL_H_
+
+#include <machine/signal.h> /* sigcontext; codes for SIGILL, SIGFPE */
+
+#define _NSIG 33 /* counting 0 (mask is 1-32) */
+
+#if __BSD_VISIBLE
+#define NSIG _NSIG
+#endif
+
+#define SIGHUP 1 /* hangup */
+#define SIGINT 2 /* interrupt */
+#define SIGQUIT 3 /* quit */
+#define SIGILL 4 /* illegal instruction (not reset when caught) */
+#define SIGTRAP 5 /* trace trap (not reset when caught) */
+#define SIGABRT 6 /* abort() */
+#if __BSD_VISIBLE
+#define SIGIOT SIGABRT /* compatibility */
+#define SIGEMT 7 /* EMT instruction */
+#endif
+#define SIGFPE 8 /* floating point exception */
+#define SIGKILL 9 /* kill (cannot be caught or ignored) */
+#define SIGBUS 10 /* bus error */
+#define SIGSEGV 11 /* segmentation violation */
+#define SIGSYS 12 /* bad argument to system call */
+#define SIGPIPE 13 /* write on a pipe with no one to read it */
+#define SIGALRM 14 /* alarm clock */
+#define SIGTERM 15 /* software termination signal from kill */
+#define SIGURG 16 /* urgent condition on IO channel */
+#define SIGSTOP 17 /* sendable stop signal not from tty */
+#define SIGTSTP 18 /* stop signal from tty */
+#define SIGCONT 19 /* continue a stopped process */
+#define SIGCHLD 20 /* to parent on child stop or exit */
+#define SIGTTIN 21 /* to readers pgrp upon background tty read */
+#define SIGTTOU 22 /* like TTIN for output if (tp->t_local&LTOSTOP) */
+#if __BSD_VISIBLE
+#define SIGIO 23 /* input/output possible signal */
+#endif
+#define SIGXCPU 24 /* exceeded CPU time limit */
+#define SIGXFSZ 25 /* exceeded file size limit */
+#define SIGVTALRM 26 /* virtual time alarm */
+#define SIGPROF 27 /* profiling time alarm */
+#if __BSD_VISIBLE
+#define SIGWINCH 28 /* window size changes */
+#define SIGINFO 29 /* information request */
+#endif
+#define SIGUSR1 30 /* user defined signal 1 */
+#define SIGUSR2 31 /* user defined signal 2 */
+#if __BSD_VISIBLE
+#define SIGTHR 32 /* thread library AST */
+#endif
+
+/*
+ * Language spec says we must list exactly one parameter, even though we
+ * actually supply three. Ugh!
+ */
+#define SIG_DFL (void (*)(int))0
+#define SIG_IGN (void (*)(int))1
+#define SIG_ERR (void (*)(int))-1
+
+#if __POSIX_VISIBLE || __XPG_VISIBLE
+#ifndef _SIGSET_T_DEFINED_
+#define _SIGSET_T_DEFINED_
+typedef unsigned int sigset_t;
+#endif
+
+#include <sys/siginfo.h>
+
+/*
+ * Signal vector "template" used in sigaction call.
+ */
+struct sigaction {
+ union { /* signal handler */
+ void (*__sa_handler)(int);
+ void (*__sa_sigaction)(int, siginfo_t *, void *);
+ } __sigaction_u;
+ sigset_t sa_mask; /* signal mask to apply */
+ int sa_flags; /* see signal options below */
+};
+
+/* if SA_SIGINFO is set, sa_sigaction is to be used instead of sa_handler. */
+#define sa_handler __sigaction_u.__sa_handler
+#define sa_sigaction __sigaction_u.__sa_sigaction
+
+#if __XPG_VISIBLE >= 500
+#define SA_ONSTACK 0x0001 /* take signal on signal stack */
+#define SA_RESTART 0x0002 /* restart system on signal return */
+#define SA_RESETHAND 0x0004 /* reset to SIG_DFL when taking signal */
+#define SA_NODEFER 0x0010 /* don't mask the signal we're delivering */
+#define SA_NOCLDWAIT 0x0020 /* don't create zombies (assign to pid 1) */
+#endif /* __XPG_VISIBLE >= 500 */
+#define SA_NOCLDSTOP 0x0008 /* do not generate SIGCHLD on child stop */
+#if __POSIX_VISIBLE >= 199309 || __XPG_VISIBLE >= 500
+#define SA_SIGINFO 0x0040 /* generate siginfo_t */
+#endif
+
+/*
+ * Flags for sigprocmask:
+ */
+#define SIG_BLOCK 1 /* block specified signal set */
+#define SIG_UNBLOCK 2 /* unblock specified signal set */
+#define SIG_SETMASK 3 /* set specified signal set */
+#endif /* __POSIX_VISIBLE || __XPG_VISIBLE */
+
+#if __BSD_VISIBLE
+typedef void (*sig_t)(int); /* type of signal function */
+
+/*
+ * 4.3 compatibility:
+ * Signal vector "template" used in sigvec call.
+ */
+struct sigvec {
+ void (*sv_handler)(int); /* signal handler */
+ int sv_mask; /* signal mask to apply */
+ int sv_flags; /* see signal options below */
+};
+#define SV_ONSTACK SA_ONSTACK
+#define SV_INTERRUPT SA_RESTART /* same bit, opposite sense */
+#define SV_RESETHAND SA_RESETHAND
+#define sv_onstack sv_flags /* isn't compatibility wonderful! */
+
+/*
+ * Macro for converting signal number to a mask suitable for
+ * sigblock().
+ */
+#define sigmask(m) (1U << ((m)-1))
+
+#define BADSIG SIG_ERR
+
+#endif /* __BSD_VISIBLE */
+
+#if __BSD_VISIBLE || __XPG_VISIBLE >= 420
+/*
+ * Structure used in sigaltstack call.
+ */
+typedef struct sigaltstack {
+ void *ss_sp; /* signal stack base */
+ size_t ss_size; /* signal stack length */
+ int ss_flags; /* SS_DISABLE and/or SS_ONSTACK */
+} stack_t;
+#define SS_ONSTACK 0x0001 /* take signals on alternate stack */
+#define SS_DISABLE 0x0004 /* disable taking signals on alternate stack */
+#define MINSIGSTKSZ (3U << _MAX_PAGE_SHIFT) /* minimum allowable stack */
+#if _MAX_PAGE_SHIFT < 14 /* recommended stack size */
+#define SIGSTKSZ (MINSIGSTKSZ + (1U << _MAX_PAGE_SHIFT) * 4)
+#else
+#define SIGSTKSZ (MINSIGSTKSZ + (1U << _MAX_PAGE_SHIFT) * 2)
+#endif
+
+typedef struct sigcontext ucontext_t;
+#endif /* __BSD_VISIBLE || __XPG_VISIBLE >= 420 */
+
+#ifndef _KERNEL
+/*
+ * For historical reasons; programs expect signal's return value to be
+ * defined by <sys/signal.h>.
+ */
+__BEGIN_DECLS
+void (*signal(int, void (*)(int)))(int);
+__END_DECLS
+#endif /* !_KERNEL */
+#endif /* !_SYS_SIGNAL_H_ */
diff --git a/sys/sys/signalvar.h b/sys/sys/signalvar.h
new file mode 100644
index 0000000..7ee361f
--- /dev/null
+++ b/sys/sys/signalvar.h
@@ -0,0 +1,144 @@
+/* $OpenBSD: signalvar.h,v 1.40 2020/03/13 09:25:21 mpi Exp $ */
+/* $NetBSD: signalvar.h,v 1.17 1996/04/22 01:23:31 christos Exp $ */
+
+/*
+ * Copyright (c) 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.
+ * 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.
+ *
+ * @(#)signalvar.h 8.3 (Berkeley) 1/4/94
+ */
+
+#ifndef _SYS_SIGNALVAR_H_ /* tmp for user.h */
+#define _SYS_SIGNALVAR_H_
+
+/*
+ * Kernel signal definitions and data structures,
+ * not exported to user programs.
+ */
+
+/*
+ * Process signal actions and state, needed only within the process
+ * (not necessarily resident).
+ */
+struct sigacts {
+ sig_t ps_sigact[NSIG]; /* disposition of signals */
+ sigset_t ps_catchmask[NSIG]; /* signals to be blocked */
+ sigset_t ps_sigonstack; /* signals to take on sigstack */
+ sigset_t ps_sigintr; /* signals that interrupt syscalls */
+ sigset_t ps_sigreset; /* signals that reset when caught */
+ sigset_t ps_siginfo; /* signals that provide siginfo */
+ sigset_t ps_sigignore; /* signals being ignored */
+ sigset_t ps_sigcatch; /* signals being caught by user */
+ int ps_sigflags; /* signal flags, below */
+};
+
+/* signal flags */
+#define SAS_NOCLDSTOP 0x01 /* No SIGCHLD when children stop. */
+#define SAS_NOCLDWAIT 0x02 /* No zombies if child dies */
+
+/* additional signal action values, used only temporarily/internally */
+#define SIG_CATCH (void (*)(int))2
+#define SIG_HOLD (void (*)(int))3
+
+/*
+ * Check if process p has an unmasked signal pending.
+ * Return mask of pending signals.
+ */
+#define SIGPENDING(p) \
+ (((p)->p_siglist | (p)->p_p->ps_siglist) & ~(p)->p_sigmask)
+
+/*
+ * Determine signal that should be delivered to process p, the current
+ * process, 0 if none. If there is a pending stop signal with default
+ * action, the process stops in issignal().
+ */
+#define CURSIG(p) \
+ ((((p)->p_siglist | (p)->p_p->ps_siglist) == 0 || \
+ (((p)->p_p->ps_flags & PS_TRACED) == 0 && \
+ SIGPENDING(p) == 0)) ? \
+ 0 : issignal(p))
+
+/*
+ * Clear a pending signal from a process.
+ */
+#define CLRSIG(p, sig) do { \
+ int _mask = sigmask(sig); \
+ atomic_clearbits_int(&(p)->p_siglist, _mask); \
+ atomic_clearbits_int(&(p)->p_p->ps_siglist, _mask); \
+} while (0)
+
+/*
+ * Signal properties and actions.
+ * The array below categorizes the signals and their default actions
+ * according to the following properties:
+ */
+#define SA_KILL 0x01 /* terminates process by default */
+#define SA_CORE 0x02 /* ditto and coredumps */
+#define SA_STOP 0x04 /* suspend process */
+#define SA_TTYSTOP 0x08 /* ditto, from tty */
+#define SA_IGNORE 0x10 /* ignore by default */
+#define SA_CONT 0x20 /* continue if suspended */
+#define SA_CANTMASK 0x40 /* non-maskable, catchable */
+
+#define sigcantmask (sigmask(SIGKILL) | sigmask(SIGSTOP))
+
+#ifdef _KERNEL
+enum signal_type { SPROCESS, STHREAD, SPROPAGATED };
+
+struct sigio_ref;
+
+/*
+ * Machine-independent functions:
+ */
+int coredump(struct proc *p);
+void execsigs(struct proc *p);
+int issignal(struct proc *p);
+void pgsigio(struct sigio_ref *sir, int sig, int checkctty);
+void pgsignal(struct pgrp *pgrp, int sig, int checkctty);
+void psignal(struct proc *p, int sig);
+void ptsignal(struct proc *p, int sig, enum signal_type type);
+#define prsignal(pr,sig) ptsignal((pr)->ps_mainproc, (sig), SPROCESS)
+void siginit(struct process *);
+void trapsignal(struct proc *p, int sig, u_long code, int type,
+ union sigval val);
+void sigexit(struct proc *, int);
+int sigonstack(size_t);
+void setsigvec(struct proc *, int, struct sigaction *);
+int killpg1(struct proc *, int, int, int);
+
+void signal_init(void);
+
+struct sigacts *sigactsinit(struct process *);
+void sigstkinit(struct sigaltstack *);
+void sigactsfree(struct process *);
+
+/*
+ * Machine-dependent functions:
+ */
+void sendsig(sig_t _catcher, int _sig, sigset_t _mask, const siginfo_t *_si);
+#endif /* _KERNEL */
+#endif /* !_SYS_SIGNALVAR_H_ */
diff --git a/sys/sys/smr.h b/sys/sys/smr.h
new file mode 100644
index 0000000..1ca42e0
--- /dev/null
+++ b/sys/sys/smr.h
@@ -0,0 +1,440 @@
+/* $OpenBSD: smr.h,v 1.6 2020/04/12 07:20:33 visa Exp $ */
+
+/*
+ * Copyright (c) 2019 Visa Hankala
+ *
+ * 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.
+ */
+
+#ifndef _SYS_SMR_H_
+#define _SYS_SMR_H_
+
+#include <sys/queue.h>
+
+struct smr_entry {
+ SIMPLEQ_ENTRY(smr_entry) smr_list;
+ void (*smr_func)(void *);
+ void *smr_arg;
+};
+
+SIMPLEQ_HEAD(smr_entry_list, smr_entry);
+
+#ifdef _KERNEL
+
+#include <sys/atomic.h>
+
+void smr_startup(void);
+void smr_startup_thread(void);
+void smr_idle(void);
+void smr_read_enter(void);
+void smr_read_leave(void);
+
+void smr_call_impl(struct smr_entry *, void (*)(void *), void *, int);
+void smr_barrier_impl(int);
+
+#define smr_call(entry, func, arg) smr_call_impl(entry, func, arg, 0)
+#define smr_barrier() smr_barrier_impl(0)
+#define smr_flush() smr_barrier_impl(1)
+
+static inline void
+smr_init(struct smr_entry *smr)
+{
+ smr->smr_func = NULL;
+ smr->smr_arg = NULL;
+}
+
+#ifdef DIAGNOSTIC
+#define SMR_ASSERT_CRITICAL() do { \
+ if (panicstr == NULL && !db_active) \
+ KASSERT(curcpu()->ci_schedstate.spc_smrdepth > 0); \
+} while (0)
+#define SMR_ASSERT_NONCRITICAL() do { \
+ if (panicstr == NULL && !db_active) \
+ KASSERT(curcpu()->ci_schedstate.spc_smrdepth == 0); \
+} while (0)
+#else
+#define SMR_ASSERT_CRITICAL() do {} while (0)
+#define SMR_ASSERT_NONCRITICAL() do {} while (0)
+#endif
+
+#define SMR_PTR_GET(pptr) READ_ONCE(*pptr)
+
+#define SMR_PTR_GET_LOCKED(pptr) (*(pptr))
+
+#define SMR_PTR_SET_LOCKED(pptr, val) do { \
+ membar_producer(); \
+ WRITE_ONCE(*pptr, val); \
+} while (0)
+
+/*
+ * List implementations for use with safe memory reclamation.
+ */
+
+/*
+ * Copyright (c) 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.
+ * 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.
+ *
+ * @(#)queue.h 8.5 (Berkeley) 8/20/94
+ */
+
+#include <sys/_null.h>
+
+/*
+ * This file defines three types of data structures: singly-linked lists,
+ * lists, and tail queues.
+ *
+ *
+ * A singly-linked list is headed by a single forward pointer. The elements
+ * are singly linked for minimum space and pointer manipulation overhead at
+ * the expense of O(n) removal for arbitrary elements. New elements can be
+ * added to the list after an existing element or at the head of the list.
+ * Elements being removed from the head of the list should use the explicit
+ * macro for this purpose for optimum efficiency. A singly-linked list may
+ * only be traversed in the forward direction. Singly-linked lists are ideal
+ * for applications with large datasets and few or no removals or for
+ * implementing a LIFO queue.
+ *
+ * A list is headed by a single forward pointer (or an array of forward
+ * pointers for a hash table header). The elements are doubly linked
+ * so that an arbitrary element can be removed without a need to
+ * traverse the list. New elements can be added to the list before
+ * or after an existing element or at the head of the list. A list
+ * may only be traversed in the forward direction.
+ *
+ * A tail queue is headed by a pair of pointers, one to the head of the
+ * list and the other to the tail of the list. The elements are doubly
+ * linked so that an arbitrary element can be removed without a need to
+ * traverse the list. New elements can be added to the list before or
+ * after an existing element, at the head of the list, or at the end of
+ * the list. A tail queue may only be traversed in the forward direction
+ * by lock-free readers.
+ */
+
+/*
+ * Singly-linked List definitions.
+ */
+#define SMR_SLIST_HEAD(name, type) \
+struct name { \
+ struct type *smr_slh_first; /* first element, SMR-protected */\
+}
+
+#define SMR_SLIST_HEAD_INITIALIZER(head) \
+ { .smr_slh_first = NULL }
+
+#define SMR_SLIST_ENTRY(type) \
+struct { \
+ struct type *smr_sle_next; /* next element, SMR-protected */\
+}
+
+/*
+ * Singly-linked List access methods.
+ */
+#define SMR_SLIST_END(head) NULL
+
+#define SMR_SLIST_FIRST(head) \
+ SMR_PTR_GET(&(head)->smr_slh_first)
+#define SMR_SLIST_NEXT(elm, field) \
+ SMR_PTR_GET(&(elm)->field.smr_sle_next)
+
+#define SMR_SLIST_FIRST_LOCKED(head) \
+ SMR_PTR_GET_LOCKED(&(head)->smr_slh_first)
+#define SMR_SLIST_EMPTY_LOCKED(head) \
+ (SMR_SLIST_FIRST_LOCKED(head) == SMR_SLIST_END(head))
+#define SMR_SLIST_NEXT_LOCKED(elm, field) \
+ SMR_PTR_GET_LOCKED(&(elm)->field.smr_sle_next)
+
+#define SMR_SLIST_FOREACH(var, head, field) \
+ for ((var) = SMR_SLIST_FIRST(head); \
+ (var) != SMR_SLIST_END(head); \
+ (var) = SMR_SLIST_NEXT(var, field))
+
+#define SMR_SLIST_FOREACH_LOCKED(var, head, field) \
+ for ((var) = SMR_SLIST_FIRST_LOCKED(head); \
+ (var) != SMR_SLIST_END(head); \
+ (var) = SMR_SLIST_NEXT_LOCKED(var, field))
+
+#define SMR_SLIST_FOREACH_SAFE_LOCKED(var, head, field, tvar) \
+ for ((var) = SMR_SLIST_FIRST_LOCKED(head); \
+ (var) && ((tvar) = SMR_SLIST_NEXT_LOCKED(var, field), 1); \
+ (var) = (tvar))
+
+/*
+ * Singly-linked List functions.
+ */
+#define SMR_SLIST_INIT(head) do { \
+ (head)->smr_slh_first = SMR_SLIST_END(head); \
+} while (0)
+
+#define SMR_SLIST_INSERT_AFTER_LOCKED(slistelm, elm, field) do { \
+ (elm)->field.smr_sle_next = (slistelm)->field.smr_sle_next; \
+ membar_producer(); \
+ (slistelm)->field.smr_sle_next = (elm); \
+} while (0)
+
+#define SMR_SLIST_INSERT_HEAD_LOCKED(head, elm, field) do { \
+ (elm)->field.smr_sle_next = (head)->smr_slh_first; \
+ membar_producer(); \
+ (head)->smr_slh_first = (elm); \
+} while (0)
+
+#define SMR_SLIST_REMOVE_AFTER_LOCKED(elm, field) do { \
+ (elm)->field.smr_sle_next = \
+ (elm)->field.smr_sle_next->field.smr_sle_next; \
+} while (0)
+
+#define SMR_SLIST_REMOVE_HEAD_LOCKED(head, field) do { \
+ (head)->smr_slh_first = (head)->smr_slh_first->field.smr_sle_next;\
+} while (0)
+
+#define SMR_SLIST_REMOVE_LOCKED(head, elm, type, field) do { \
+ if ((head)->smr_slh_first == (elm)) { \
+ SMR_SLIST_REMOVE_HEAD_LOCKED((head), field); \
+ } else { \
+ struct type *curelm = (head)->smr_slh_first; \
+ \
+ while (curelm->field.smr_sle_next != (elm)) \
+ curelm = curelm->field.smr_sle_next; \
+ curelm->field.smr_sle_next = \
+ curelm->field.smr_sle_next->field.smr_sle_next; \
+ } \
+ /* (elm)->field.smr_sle_next must be left intact to allow \
+ * any concurrent readers to proceed iteration. */ \
+} while (0)
+
+/*
+ * List definitions.
+ */
+#define SMR_LIST_HEAD(name, type) \
+struct name { \
+ struct type *smr_lh_first; /* first element, SMR-protected */\
+}
+
+#define SMR_LIST_HEAD_INITIALIZER(head) \
+ { .smr_lh_first = NULL }
+
+#define SMR_LIST_ENTRY(type) \
+struct { \
+ struct type *smr_le_next; /* next element, SMR-protected */\
+ struct type **smr_le_prev; /* address of previous next element */\
+}
+
+/*
+ * List access methods.
+ */
+#define SMR_LIST_END(head) NULL
+
+#define SMR_LIST_FIRST(head) \
+ SMR_PTR_GET(&(head)->smr_lh_first)
+#define SMR_LIST_NEXT(elm, field) \
+ SMR_PTR_GET(&(elm)->field.smr_le_next)
+
+#define SMR_LIST_FIRST_LOCKED(head) ((head)->smr_lh_first)
+#define SMR_LIST_NEXT_LOCKED(elm, field) ((elm)->field.smr_le_next)
+#define SMR_LIST_EMPTY_LOCKED(head) \
+ (SMR_LIST_FIRST_LOCKED(head) == SMR_LIST_END(head))
+
+#define SMR_LIST_FOREACH(var, head, field) \
+ for((var) = SMR_LIST_FIRST(head); \
+ (var)!= SMR_LIST_END(head); \
+ (var) = SMR_LIST_NEXT(var, field))
+
+#define SMR_LIST_FOREACH_LOCKED(var, head, field) \
+ for((var) = SMR_LIST_FIRST_LOCKED(head); \
+ (var)!= SMR_LIST_END(head); \
+ (var) = SMR_LIST_NEXT_LOCKED(var, field))
+
+#define SMR_LIST_FOREACH_SAFE_LOCKED(var, head, field, tvar) \
+ for ((var) = SMR_LIST_FIRST_LOCKED(head); \
+ (var) && ((tvar) = SMR_LIST_NEXT_LOCKED(var, field), 1); \
+ (var) = (tvar))
+
+/*
+ * List functions.
+ */
+#define SMR_LIST_INIT(head) do { \
+ (head)->smr_lh_first = LIST_END(head); \
+} while (0)
+
+#define SMR_LIST_INSERT_AFTER_LOCKED(listelm, elm, field) do { \
+ (elm)->field.smr_le_next = (listelm)->field.smr_le_next; \
+ if ((listelm)->field.smr_le_next != NULL) \
+ (listelm)->field.smr_le_next->field.smr_le_prev = \
+ &(elm)->field.smr_le_next; \
+ (elm)->field.smr_le_prev = &(listelm)->field.smr_le_next; \
+ membar_producer(); \
+ (listelm)->field.smr_le_next = (elm); \
+} while (0)
+
+#define SMR_LIST_INSERT_BEFORE_LOCKED(listelm, elm, field) do { \
+ (elm)->field.smr_le_prev = (listelm)->field.smr_le_prev; \
+ (elm)->field.smr_le_next = (listelm); \
+ membar_producer(); \
+ *(listelm)->field.smr_le_prev = (elm); \
+ (listelm)->field.smr_le_prev = &(elm)->field.smr_le_next; \
+} while (0)
+
+#define SMR_LIST_INSERT_HEAD_LOCKED(head, elm, field) do { \
+ (elm)->field.smr_le_next = (head)->smr_lh_first; \
+ (elm)->field.smr_le_prev = &(head)->smr_lh_first; \
+ if ((head)->smr_lh_first != NULL) \
+ (head)->smr_lh_first->field.smr_le_prev = \
+ &(elm)->field.smr_le_next; \
+ membar_producer(); \
+ (head)->smr_lh_first = (elm); \
+} while (0)
+
+#define SMR_LIST_REMOVE_LOCKED(elm, field) do { \
+ if ((elm)->field.smr_le_next != NULL) \
+ (elm)->field.smr_le_next->field.smr_le_prev = \
+ (elm)->field.smr_le_prev; \
+ *(elm)->field.smr_le_prev = (elm)->field.smr_le_next; \
+ /* (elm)->field.smr_le_next must be left intact to allow \
+ * any concurrent readers to proceed iteration. */ \
+} while (0)
+
+/*
+ * Tail queue definitions.
+ */
+#define SMR_TAILQ_HEAD(name, type) \
+struct name { \
+ struct type *smr_tqh_first; /* first element, SMR-protected */\
+ struct type **smr_tqh_last; /* last element, SMR-protected */\
+}
+
+#define SMR_TAILQ_HEAD_INITIALIZER(head) \
+ { .smr_tqh_first = NULL, .smr_tqh_last = &(head).smr_tqh_first }
+
+#define SMR_TAILQ_ENTRY(type) \
+struct { \
+ struct type *smr_tqe_next; /* next element, SMR-protected */\
+ struct type **smr_tqe_prev; /* address of previous next element */\
+}
+
+/*
+ * Tail queue access methods.
+ */
+#define SMR_TAILQ_END(head) NULL
+
+#define SMR_TAILQ_FIRST(head) \
+ SMR_PTR_GET(&(head)->smr_tqh_first)
+#define SMR_TAILQ_NEXT(elm, field) \
+ SMR_PTR_GET(&(elm)->field.smr_tqe_next)
+
+#define SMR_TAILQ_FIRST_LOCKED(head) ((head)->smr_tqh_first)
+#define SMR_TAILQ_NEXT_LOCKED(elm, field) ((elm)->field.smr_tqe_next)
+#define SMR_TAILQ_LAST_LOCKED(head, headname) \
+ (*(((struct headname *)((head)->smr_tqh_last))->smr_tqh_last))
+#define SMR_TAILQ_EMPTY_LOCKED(head) \
+ (SMR_TAILQ_FIRST_LOCKED(head) == SMR_TAILQ_END(head))
+
+#define SMR_TAILQ_FOREACH(var, head, field) \
+ for((var) = SMR_TAILQ_FIRST(head); \
+ (var)!= SMR_TAILQ_END(head); \
+ (var) = SMR_TAILQ_NEXT(var, field))
+
+#define SMR_TAILQ_FOREACH_LOCKED(var, head, field) \
+ for((var) = SMR_TAILQ_FIRST_LOCKED(head); \
+ (var)!= SMR_TAILQ_END(head); \
+ (var) = SMR_TAILQ_NEXT_LOCKED(var, field))
+
+#define SMR_TAILQ_FOREACH_SAFE_LOCKED(var, head, field, tvar) \
+ for ((var) = SMR_TAILQ_FIRST_LOCKED(head); \
+ (var) && ((tvar) = SMR_TAILQ_NEXT_LOCKED(var, field), 1); \
+ (var) = (tvar))
+
+/*
+ * Tail queue functions.
+ */
+#define SMR_TAILQ_INIT(head) do { \
+ (head)->smr_tqh_first = TAILQ_END(head); \
+ (head)->smr_tqh_last = &(head)->smr_tqh_first; \
+} while (0)
+
+#define SMR_TAILQ_INSERT_AFTER_LOCKED(head, listelm, elm, field) do { \
+ (elm)->field.smr_tqe_next = (listelm)->field.smr_tqe_next; \
+ if ((listelm)->field.smr_tqe_next != NULL) \
+ (listelm)->field.smr_tqe_next->field.smr_tqe_prev = \
+ &(elm)->field.smr_tqe_next; \
+ else \
+ (head)->smr_tqh_last = &(elm)->field.smr_tqe_next; \
+ (elm)->field.smr_tqe_prev = &(listelm)->field.smr_tqe_next; \
+ membar_producer(); \
+ (listelm)->field.smr_tqe_next = (elm); \
+} while (0)
+
+#define SMR_TAILQ_INSERT_BEFORE_LOCKED(listelm, elm, field) do { \
+ (elm)->field.smr_tqe_prev = (listelm)->field.smr_tqe_prev; \
+ (elm)->field.smr_tqe_next = (listelm); \
+ membar_producer(); \
+ *(listelm)->field.smr_tqe_prev = (elm); \
+ (listelm)->field.smr_tqe_prev = &(elm)->field.smr_tqe_next; \
+} while (0)
+
+#define SMR_TAILQ_INSERT_HEAD_LOCKED(head, elm, field) do { \
+ (elm)->field.smr_tqe_next = (head)->smr_tqh_first; \
+ (elm)->field.smr_tqe_prev = &(head)->smr_tqh_first; \
+ if ((head)->smr_tqh_first != NULL) \
+ (head)->smr_tqh_first->field.smr_tqe_prev = \
+ &(elm)->field.smr_tqe_next; \
+ else \
+ (head)->smr_tqh_last = &(elm)->field.smr_tqe_next; \
+ membar_producer(); \
+ (head)->smr_tqh_first = (elm); \
+} while (0)
+
+#define SMR_TAILQ_INSERT_TAIL_LOCKED(head, elm, field) do { \
+ (elm)->field.smr_tqe_next = NULL; \
+ (elm)->field.smr_tqe_prev = (head)->smr_tqh_last; \
+ membar_producer(); \
+ *(head)->smr_tqh_last = (elm); \
+ (head)->smr_tqh_last = &(elm)->field.smr_tqe_next; \
+} while (0)
+
+#define SMR_TAILQ_REMOVE_LOCKED(head, elm, field) do { \
+ if ((elm)->field.smr_tqe_next != NULL) \
+ (elm)->field.smr_tqe_next->field.smr_tqe_prev = \
+ (elm)->field.smr_tqe_prev; \
+ else \
+ (head)->smr_tqh_last = (elm)->field.smr_tqe_prev; \
+ *(elm)->field.smr_tqe_prev = (elm)->field.smr_tqe_next; \
+ /* (elm)->field.smr_tqe_next must be left intact to allow \
+ * any concurrent readers to proceed iteration. */ \
+} while (0)
+
+#endif /* _KERNEL */
+
+#endif /* !_SYS_SMR_ */
diff --git a/sys/sys/socket.h b/sys/sys/socket.h
new file mode 100644
index 0000000..927fd26
--- /dev/null
+++ b/sys/sys/socket.h
@@ -0,0 +1,572 @@
+/* $OpenBSD: socket.h,v 1.98 2019/07/22 15:34:07 robert Exp $ */
+/* $NetBSD: socket.h,v 1.14 1996/02/09 18:25:36 christos Exp $ */
+
+/*
+ * Copyright (c) 1982, 1985, 1986, 1988, 1993, 1994
+ * 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.
+ *
+ * @(#)socket.h 8.4 (Berkeley) 2/21/94
+ */
+
+#ifndef _SYS_SOCKET_H_
+#define _SYS_SOCKET_H_
+
+/* get the definitions for struct iovec, size_t, ssize_t, and <sys/cdefs.h> */
+#include <sys/uio.h>
+
+#if __BSD_VISIBLE
+#include <sys/types.h> /* for off_t, uid_t, and gid_t */
+#endif
+
+#ifndef _SOCKLEN_T_DEFINED_
+#define _SOCKLEN_T_DEFINED_
+typedef __socklen_t socklen_t; /* length type for network syscalls */
+#endif
+
+#ifndef _SA_FAMILY_T_DEFINED_
+#define _SA_FAMILY_T_DEFINED_
+typedef __sa_family_t sa_family_t; /* sockaddr address family type */
+#endif
+
+
+/*
+ * Definitions related to sockets: types, address families, options.
+ */
+
+/*
+ * Types
+ */
+#define SOCK_STREAM 1 /* stream socket */
+#define SOCK_DGRAM 2 /* datagram socket */
+#define SOCK_RAW 3 /* raw-protocol interface */
+#define SOCK_RDM 4 /* reliably-delivered message */
+#define SOCK_SEQPACKET 5 /* sequenced packet stream */
+#ifdef _KERNEL
+#define SOCK_TYPE_MASK 0x000F /* mask that covers the above */
+#endif
+
+/*
+ * Socket creation flags
+ */
+#if __BSD_VISIBLE
+#define SOCK_CLOEXEC 0x8000 /* set FD_CLOEXEC */
+#define SOCK_NONBLOCK 0x4000 /* set O_NONBLOCK */
+#ifdef _KERNEL
+#define SOCK_NONBLOCK_INHERIT 0x2000 /* inherit O_NONBLOCK from listener */
+#endif
+#define SOCK_DNS 0x1000 /* set SS_DNS */
+#endif /* __BSD_VISIBLE */
+
+/*
+ * Option flags per-socket.
+ */
+#define SO_DEBUG 0x0001 /* turn on debugging info recording */
+#define SO_ACCEPTCONN 0x0002 /* socket has had listen() */
+#define SO_REUSEADDR 0x0004 /* allow local address reuse */
+#define SO_KEEPALIVE 0x0008 /* keep connections alive */
+#define SO_DONTROUTE 0x0010 /* just use interface addresses */
+#define SO_BROADCAST 0x0020 /* permit sending of broadcast msgs */
+#define SO_USELOOPBACK 0x0040 /* bypass hardware when possible */
+#define SO_LINGER 0x0080 /* linger on close if data present */
+#define SO_OOBINLINE 0x0100 /* leave received OOB data in line */
+#define SO_REUSEPORT 0x0200 /* allow local address & port reuse */
+#define SO_TIMESTAMP 0x0800 /* timestamp received dgram traffic */
+#define SO_BINDANY 0x1000 /* allow bind to any address */
+#define SO_ZEROIZE 0x2000 /* zero out all mbufs sent over socket */
+
+/*
+ * Additional options, not kept in so_options.
+ */
+#define SO_SNDBUF 0x1001 /* send buffer size */
+#define SO_RCVBUF 0x1002 /* receive buffer size */
+#define SO_SNDLOWAT 0x1003 /* send low-water mark */
+#define SO_RCVLOWAT 0x1004 /* receive low-water mark */
+#define SO_SNDTIMEO 0x1005 /* send timeout */
+#define SO_RCVTIMEO 0x1006 /* receive timeout */
+#define SO_ERROR 0x1007 /* get error status and clear */
+#define SO_TYPE 0x1008 /* get socket type */
+#define SO_NETPROC 0x1020 /* multiplex; network processing */
+#define SO_RTABLE 0x1021 /* routing table to be used */
+#define SO_PEERCRED 0x1022 /* get connect-time credentials */
+#define SO_SPLICE 0x1023 /* splice data to other socket */
+#define SO_DOMAIN 0x1024 /* get socket domain */
+#define SO_PROTOCOL 0x1025 /* get socket protocol */
+
+/*
+ * Structure used for manipulating linger option.
+ */
+struct linger {
+ int l_onoff; /* option on/off */
+ int l_linger; /* linger time */
+};
+
+#if __BSD_VISIBLE
+
+#ifndef _TIMEVAL_DECLARED
+#define _TIMEVAL_DECLARED
+struct timeval {
+ time_t tv_sec; /* seconds */
+ suseconds_t tv_usec; /* and microseconds */
+};
+#endif
+
+/*
+ * Structure used for manipulating splice option.
+ */
+struct splice {
+ int sp_fd; /* drain socket file descriptor */
+ off_t sp_max; /* if set, maximum bytes to splice */
+ struct timeval sp_idle; /* idle timeout */
+};
+
+/*
+ * Maximum number of alternate routing tables
+ */
+#define RT_TABLEID_MAX 255
+#define RT_TABLEID_BITS 8
+#define RT_TABLEID_MASK 0xff
+
+#endif /* __BSD_VISIBLE */
+
+/*
+ * Level number for (get/set)sockopt() to apply to socket itself.
+ */
+#define SOL_SOCKET 0xffff /* options for socket level */
+
+/*
+ * Address families.
+ */
+#define AF_UNSPEC 0 /* unspecified */
+#define AF_UNIX 1 /* local to host */
+#define AF_LOCAL AF_UNIX /* draft POSIX compatibility */
+#define AF_INET 2 /* internetwork: UDP, TCP, etc. */
+#define AF_IMPLINK 3 /* arpanet imp addresses */
+#define AF_PUP 4 /* pup protocols: e.g. BSP */
+#define AF_CHAOS 5 /* mit CHAOS protocols */
+#define AF_NS 6 /* XEROX NS protocols */
+#define AF_ISO 7 /* ISO protocols */
+#define AF_OSI AF_ISO
+#define AF_ECMA 8 /* european computer manufacturers */
+#define AF_DATAKIT 9 /* datakit protocols */
+#define AF_CCITT 10 /* CCITT protocols, X.25 etc */
+#define AF_SNA 11 /* IBM SNA */
+#define AF_DECnet 12 /* DECnet */
+#define AF_DLI 13 /* DEC Direct data link interface */
+#define AF_LAT 14 /* LAT */
+#define AF_HYLINK 15 /* NSC Hyperchannel */
+#define AF_APPLETALK 16 /* Apple Talk */
+#define AF_ROUTE 17 /* Internal Routing Protocol */
+#define AF_LINK 18 /* Link layer interface */
+#define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */
+#define AF_COIP 20 /* connection-oriented IP, aka ST II */
+#define AF_CNT 21 /* Computer Network Technology */
+#define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */
+#define AF_IPX 23 /* Novell Internet Protocol */
+#define AF_INET6 24 /* IPv6 */
+#define pseudo_AF_PIP 25 /* Help Identify PIP packets */
+#define AF_ISDN 26 /* Integrated Services Digital Network*/
+#define AF_E164 AF_ISDN /* CCITT E.164 recommendation */
+#define AF_NATM 27 /* native ATM access */
+#define AF_ENCAP 28
+#define AF_SIP 29 /* Simple Internet Protocol */
+#define AF_KEY 30
+#define pseudo_AF_HDRCMPLT 31 /* Used by BPF to not rewrite headers
+ in interface output routine */
+#define AF_BLUETOOTH 32 /* Bluetooth */
+#define AF_MPLS 33 /* MPLS */
+#define pseudo_AF_PFLOW 34 /* pflow */
+#define pseudo_AF_PIPEX 35 /* PIPEX */
+#define AF_MAX 36
+
+/*
+ * Structure used by kernel to store most
+ * addresses.
+ */
+struct sockaddr {
+ __uint8_t sa_len; /* total length */
+ sa_family_t sa_family; /* address family */
+ char sa_data[14]; /* actually longer; address value */
+};
+
+/*
+ * Sockaddr type which can hold any sockaddr type available
+ * in the system.
+ *
+ * Note: __ss_{len,family} is defined in RFC2553. During RFC2553 discussion
+ * the field name went back and forth between ss_len and __ss_len,
+ * and RFC2553 specifies it to be __ss_len. openbsd picked ss_len.
+ * For maximum portability, userland programmer would need to
+ * (1) make the code never touch ss_len portion (cast it into sockaddr and
+ * touch sa_len), or (2) add "-Dss_len=__ss_len" into CFLAGS to unify all
+ * occurrences (including header file) to __ss_len.
+ */
+struct sockaddr_storage {
+ __uint8_t ss_len; /* total length */
+ sa_family_t ss_family; /* address family */
+ unsigned char __ss_pad1[6]; /* align to quad */
+ __uint64_t __ss_pad2; /* force alignment for stupid compilers */
+ unsigned char __ss_pad3[240]; /* pad to a total of 256 bytes */
+};
+
+#ifdef _KERNEL
+/*
+ * Structure used by kernel to pass protocol
+ * information in raw sockets.
+ */
+struct sockproto {
+ unsigned short sp_family; /* address family */
+ unsigned short sp_protocol; /* protocol */
+};
+#endif /* _KERNEL */
+
+/*
+ * Protocol families, same as address families for now.
+ */
+#define PF_UNSPEC AF_UNSPEC
+#define PF_LOCAL AF_LOCAL
+#define PF_UNIX AF_UNIX
+#define PF_INET AF_INET
+#define PF_IMPLINK AF_IMPLINK
+#define PF_PUP AF_PUP
+#define PF_CHAOS AF_CHAOS
+#define PF_NS AF_NS
+#define PF_ISO AF_ISO
+#define PF_OSI AF_ISO
+#define PF_ECMA AF_ECMA
+#define PF_DATAKIT AF_DATAKIT
+#define PF_CCITT AF_CCITT
+#define PF_SNA AF_SNA
+#define PF_DECnet AF_DECnet
+#define PF_DLI AF_DLI
+#define PF_LAT AF_LAT
+#define PF_HYLINK AF_HYLINK
+#define PF_APPLETALK AF_APPLETALK
+#define PF_ROUTE AF_ROUTE
+#define PF_LINK AF_LINK
+#define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
+#define PF_COIP AF_COIP
+#define PF_CNT AF_CNT
+#define PF_IPX AF_IPX /* same format as AF_NS */
+#define PF_INET6 AF_INET6
+#define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */
+#define PF_PIP pseudo_AF_PIP
+#define PF_ISDN AF_ISDN
+#define PF_NATM AF_NATM
+#define PF_ENCAP AF_ENCAP
+#define PF_SIP AF_SIP
+#define PF_KEY AF_KEY
+#define PF_BPF pseudo_AF_HDRCMPLT
+#define PF_BLUETOOTH AF_BLUETOOTH
+#define PF_MPLS AF_MPLS
+#define PF_PFLOW pseudo_AF_PFLOW
+#define PF_PIPEX pseudo_AF_PIPEX
+#define PF_MAX AF_MAX
+
+/*
+ * These are the valid values for the "how" field used by shutdown(2).
+ */
+#define SHUT_RD 0
+#define SHUT_WR 1
+#define SHUT_RDWR 2
+
+#if __BSD_VISIBLE
+#define SA_LEN(x) ((x)->sa_len)
+
+/* Read using getsockopt() with SOL_SOCKET, SO_PEERCRED */
+struct sockpeercred {
+ uid_t uid; /* effective user id */
+ gid_t gid; /* effective group id */
+ pid_t pid;
+};
+
+/*
+ * Definitions for network related sysctl, CTL_NET.
+ *
+ * Second level is protocol family.
+ * Third level is protocol number.
+ *
+ * Further levels are defined by the individual families below.
+ */
+#define NET_MAXID AF_MAX
+
+#define CTL_NET_NAMES { \
+ { 0, 0 }, \
+ { "unix", CTLTYPE_NODE }, \
+ { "inet", CTLTYPE_NODE }, \
+ { "implink", CTLTYPE_NODE }, \
+ { "pup", CTLTYPE_NODE }, \
+ { "chaos", CTLTYPE_NODE }, \
+ { "xerox_ns", CTLTYPE_NODE }, \
+ { "iso", CTLTYPE_NODE }, \
+ { "emca", CTLTYPE_NODE }, \
+ { "datakit", CTLTYPE_NODE }, \
+ { "ccitt", CTLTYPE_NODE }, \
+ { "ibm_sna", CTLTYPE_NODE }, \
+ { "decnet", CTLTYPE_NODE }, \
+ { "dec_dli", CTLTYPE_NODE }, \
+ { "lat", CTLTYPE_NODE }, \
+ { "hylink", CTLTYPE_NODE }, \
+ { "appletalk", CTLTYPE_NODE }, \
+ { "route", CTLTYPE_NODE }, \
+ { "link", CTLTYPE_NODE }, \
+ { "xtp", CTLTYPE_NODE }, \
+ { "coip", CTLTYPE_NODE }, \
+ { "cnt", CTLTYPE_NODE }, \
+ { "rtip", CTLTYPE_NODE }, \
+ { "ipx", CTLTYPE_NODE }, \
+ { "inet6", CTLTYPE_NODE }, \
+ { "pip", CTLTYPE_NODE }, \
+ { "isdn", CTLTYPE_NODE }, \
+ { "natm", CTLTYPE_NODE }, \
+ { "encap", CTLTYPE_NODE }, \
+ { "sip", CTLTYPE_NODE }, \
+ { "key", CTLTYPE_NODE }, \
+ { "bpf", CTLTYPE_NODE }, \
+ { "bluetooth", CTLTYPE_NODE }, \
+ { "mpls", CTLTYPE_NODE }, \
+ { "pflow", CTLTYPE_NODE }, \
+ { "pipex", CTLTYPE_NODE }, \
+}
+
+/*
+ * PF_ROUTE - Routing table
+ *
+ * Four additional levels are defined:
+ * Fourth: address family, 0 is wildcard
+ * Fifth: type of info, defined below
+ * Sixth: flag(s) to mask with for NET_RT_FLAGS
+ * Seventh: routing table to use (facultative, defaults to 0)
+ * NET_RT_TABLE has the table id as sixth element.
+ */
+#define NET_RT_DUMP 1 /* dump; may limit to a.f. */
+#define NET_RT_FLAGS 2 /* by flags, e.g. RESOLVING */
+#define NET_RT_IFLIST 3 /* survey interface list */
+#define NET_RT_STATS 4 /* routing table statistics */
+#define NET_RT_TABLE 5
+#define NET_RT_IFNAMES 6
+#define NET_RT_MAXID 7
+
+#define CTL_NET_RT_NAMES { \
+ { 0, 0 }, \
+ { "dump", CTLTYPE_STRUCT }, \
+ { "flags", CTLTYPE_STRUCT }, \
+ { "iflist", CTLTYPE_STRUCT }, \
+ { "stats", CTLTYPE_STRUCT }, \
+ { "table", CTLTYPE_STRUCT }, \
+ { "ifnames", CTLTYPE_STRUCT }, \
+}
+
+/*
+ * PF_LINK - link layer or device tunables
+ */
+#define NET_LINK_IFRXQ 1 /* net.link.ifrxq */
+#define NET_LINK_MAXID 2
+
+#define CTL_NET_LINK_NAMES { \
+ { 0, 0 }, \
+ { "ifrxq", CTLTYPE_NODE }, \
+}
+
+#define NET_LINK_IFRXQ_PRESSURE_RETURN \
+ 1 /* net.link.ifrxq.pressure_return */
+#define NET_LINK_IFRXQ_PRESSURE_DROP \
+ 2 /* net.link.ifrxq.pressure_drop */
+#define NET_LINK_IFRXQ_MAXID 3
+
+#define CTL_NET_LINK_IFRXQ_NAMES { \
+ { 0, 0 }, \
+ { "pressure_return", CTLTYPE_INT }, \
+ { "pressure_drop", CTLTYPE_INT }, \
+}
+
+/*
+ * PF_KEY - Key Management
+ */
+#define NET_KEY_SADB_DUMP 1 /* return SADB */
+#define NET_KEY_SPD_DUMP 2 /* return SPD */
+#define NET_KEY_MAXID 3
+
+#define CTL_NET_KEY_NAMES { \
+ { 0, 0 }, \
+ { "sadb_dump", CTLTYPE_STRUCT }, \
+ { "spd_dump", CTLTYPE_STRUCT }, \
+}
+
+/*
+ * PF_BPF not really a family, but connected under CTL_NET
+ */
+#define NET_BPF_BUFSIZE 1 /* default buffer size */
+#define NET_BPF_MAXBUFSIZE 2 /* maximum buffer size */
+#define NET_BPF_MAXID 3
+
+#define CTL_NET_BPF_NAMES { \
+ { 0, 0 }, \
+ { "bufsize", CTLTYPE_INT }, \
+ { "maxbufsize", CTLTYPE_INT }, \
+}
+
+/*
+ * PF_PFLOW not really a family, but connected under CTL_NET
+ */
+#define NET_PFLOW_STATS 1 /* statistics */
+#define NET_PFLOW_MAXID 2
+
+#define CTL_NET_PFLOW_NAMES { \
+ { 0, 0 }, \
+ { "stats", CTLTYPE_STRUCT }, \
+}
+#endif /* __BSD_VISIBLE */
+
+/*
+ * Maximum queue length specifiable by listen(2).
+ */
+#define SOMAXCONN 128
+
+/*
+ * Message header for recvmsg and sendmsg calls.
+ * Used value-result for recvmsg, value only for sendmsg.
+ */
+struct msghdr {
+ void *msg_name; /* optional address */
+ socklen_t msg_namelen; /* size of address */
+ struct iovec *msg_iov; /* scatter/gather array */
+ unsigned int msg_iovlen; /* # elements in msg_iov */
+ void *msg_control; /* ancillary data, see below */
+ socklen_t msg_controllen; /* ancillary data buffer len */
+ int msg_flags; /* flags on received message */
+};
+
+#define MSG_OOB 0x1 /* process out-of-band data */
+#define MSG_PEEK 0x2 /* peek at incoming message */
+#define MSG_DONTROUTE 0x4 /* send without using routing tables */
+#define MSG_EOR 0x8 /* data completes record */
+#define MSG_TRUNC 0x10 /* data discarded before delivery */
+#define MSG_CTRUNC 0x20 /* control data lost before delivery */
+#define MSG_WAITALL 0x40 /* wait for full request or error */
+#define MSG_DONTWAIT 0x80 /* this message should be nonblocking */
+#define MSG_BCAST 0x100 /* this message rec'd as broadcast */
+#define MSG_MCAST 0x200 /* this message rec'd as multicast */
+#define MSG_NOSIGNAL 0x400 /* do not send SIGPIPE */
+#define MSG_CMSG_CLOEXEC 0x800 /* set FD_CLOEXEC on received fds */
+
+/*
+ * Header for ancillary data objects in msg_control buffer.
+ * Used for additional information with/about a datagram
+ * not expressible by flags. The format is a sequence
+ * of message elements headed by cmsghdr structures.
+ */
+struct cmsghdr {
+ socklen_t cmsg_len; /* data byte count, including hdr */
+ int cmsg_level; /* originating protocol */
+ int cmsg_type; /* protocol-specific type */
+/* followed by u_char cmsg_data[]; */
+};
+
+/* given pointer to struct cmsghdr, return pointer to data */
+#define CMSG_DATA(cmsg) \
+ ((unsigned char *)(cmsg) + _ALIGN(sizeof(struct cmsghdr)))
+
+/* given pointer to struct cmsghdr, return pointer to next cmsghdr */
+#define CMSG_NXTHDR(mhdr, cmsg) \
+ (((char *)(cmsg) + _ALIGN((cmsg)->cmsg_len) + \
+ _ALIGN(sizeof(struct cmsghdr)) > \
+ ((char *)(mhdr)->msg_control) + (mhdr)->msg_controllen) ? \
+ (struct cmsghdr *)NULL : \
+ (struct cmsghdr *)((char *)(cmsg) + _ALIGN((cmsg)->cmsg_len)))
+
+/*
+ * RFC 2292 requires to check msg_controllen, in case that the kernel returns
+ * an empty list for some reasons.
+ */
+#define CMSG_FIRSTHDR(mhdr) \
+ ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
+ (struct cmsghdr *)(mhdr)->msg_control : \
+ (struct cmsghdr *)NULL)
+
+/* Round len up to next alignment boundary */
+#ifdef _KERNEL
+#define CMSG_ALIGN(n) _ALIGN(n)
+#endif
+
+/* Length of the contents of a control message of length len */
+#define CMSG_LEN(len) (_ALIGN(sizeof(struct cmsghdr)) + (len))
+
+/* Length of the space taken up by a padded control message of length len */
+#define CMSG_SPACE(len) (_ALIGN(sizeof(struct cmsghdr)) + _ALIGN(len))
+
+/* "Socket"-level control message types: */
+#define SCM_RIGHTS 0x01 /* access rights (array of int) */
+#define SCM_TIMESTAMP 0x04 /* timestamp (struct timeval) */
+
+#ifndef _KERNEL
+
+__BEGIN_DECLS
+int accept(int, struct sockaddr *, socklen_t *);
+int bind(int, const struct sockaddr *, socklen_t);
+int connect(int, const struct sockaddr *, socklen_t);
+int getpeername(int, struct sockaddr *, socklen_t *);
+int getsockname(int, struct sockaddr *, socklen_t *);
+int getsockopt(int, int, int, void *, socklen_t *);
+int listen(int, int);
+ssize_t recv(int, void *, size_t, int);
+ssize_t recvfrom(int, void *, size_t, int, struct sockaddr *, socklen_t *);
+ssize_t recvmsg(int, struct msghdr *, int);
+ssize_t send(int, const void *, size_t, int);
+ssize_t sendto(int, const void *,
+ size_t, int, const struct sockaddr *, socklen_t);
+ssize_t sendmsg(int, const struct msghdr *, int);
+int setsockopt(int, int, int, const void *, socklen_t);
+int shutdown(int, int);
+int sockatmark(int);
+int socket(int, int, int);
+int socketpair(int, int, int, int *);
+
+#if __BSD_VISIBLE
+int accept4(int, struct sockaddr *__restrict, socklen_t *__restrict, int);
+#endif
+
+#if __BSD_VISIBLE
+int getpeereid(int, uid_t *, gid_t *);
+int getrtable(void);
+int setrtable(int);
+#endif /* __BSD_VISIBLE */
+
+__END_DECLS
+
+#else
+
+void pfctlinput(int, struct sockaddr *);
+
+static inline struct sockaddr *
+sstosa(struct sockaddr_storage *ss)
+{
+ return ((struct sockaddr *)(ss));
+}
+
+#endif /* !_KERNEL */
+
+#endif /* !_SYS_SOCKET_H_ */
diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h
new file mode 100644
index 0000000..abcf20e
--- /dev/null
+++ b/sys/sys/socketvar.h
@@ -0,0 +1,365 @@
+/* $OpenBSD: socketvar.h,v 1.91 2020/01/15 13:17:35 mpi Exp $ */
+/* $NetBSD: socketvar.h,v 1.18 1996/02/09 18:25:38 christos Exp $ */
+
+/*-
+ * Copyright (c) 1982, 1986, 1990, 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.
+ *
+ * @(#)socketvar.h 8.1 (Berkeley) 6/2/93
+ */
+
+#include <sys/selinfo.h> /* for struct selinfo */
+#include <sys/queue.h>
+#include <sys/sigio.h> /* for struct sigio_ref */
+#include <sys/task.h>
+#include <sys/timeout.h>
+
+#ifndef _SOCKLEN_T_DEFINED_
+#define _SOCKLEN_T_DEFINED_
+typedef __socklen_t socklen_t; /* length type for network syscalls */
+#endif
+
+TAILQ_HEAD(soqhead, socket);
+
+/*
+ * Kernel structure per socket.
+ * Contains send and receive buffer queues,
+ * handle on protocol and pointer to protocol
+ * private data and error information.
+ */
+struct socket {
+ const struct protosw *so_proto; /* protocol handle */
+ void *so_pcb; /* protocol control block */
+ u_int so_state; /* internal state flags SS_*, below */
+ short so_type; /* generic type, see socket.h */
+ short so_options; /* from socket call, see socket.h */
+ short so_linger; /* time to linger while closing */
+/*
+ * Variables for connection queueing.
+ * Socket where accepts occur is so_head in all subsidiary sockets.
+ * If so_head is 0, socket is not related to an accept.
+ * For head socket so_q0 queues partially completed connections,
+ * while so_q is a queue of connections ready to be accepted.
+ * If a connection is aborted and it has so_head set, then
+ * it has to be pulled out of either so_q0 or so_q.
+ * We allow connections to queue up based on current queue lengths
+ * and limit on number of queued connections for this socket.
+ */
+ struct socket *so_head; /* back pointer to accept socket */
+ struct soqhead *so_onq; /* queue (q or q0) that we're on */
+ struct soqhead so_q0; /* queue of partial connections */
+ struct soqhead so_q; /* queue of incoming connections */
+ struct sigio_ref so_sigio; /* async I/O registration */
+ TAILQ_ENTRY(socket) so_qe; /* our queue entry (q or q0) */
+ short so_q0len; /* partials on so_q0 */
+ short so_qlen; /* number of connections on so_q */
+ short so_qlimit; /* max number queued connections */
+ short so_timeo; /* connection timeout */
+ u_long so_oobmark; /* chars to oob mark */
+ u_int so_error; /* error affecting connection */
+/*
+ * Variables for socket splicing, allocated only when needed.
+ */
+ struct sosplice {
+ struct socket *ssp_socket; /* send data to drain socket */
+ struct socket *ssp_soback; /* back ref to source socket */
+ off_t ssp_len; /* number of bytes spliced */
+ off_t ssp_max; /* maximum number of bytes */
+ struct timeval ssp_idletv; /* idle timeout */
+ struct timeout ssp_idleto;
+ struct task ssp_task; /* task for somove */
+ } *so_sp;
+/*
+ * Variables for socket buffering.
+ */
+ struct sockbuf {
+/* The following fields are all zeroed on flush. */
+#define sb_startzero sb_cc
+ u_long sb_cc; /* actual chars in buffer */
+ u_long sb_datacc; /* data only chars in buffer */
+ u_long sb_hiwat; /* max actual char count */
+ u_long sb_wat; /* default watermark */
+ u_long sb_mbcnt; /* chars of mbufs used */
+ u_long sb_mbmax; /* max chars of mbufs to use */
+ long sb_lowat; /* low water mark */
+ struct mbuf *sb_mb; /* the mbuf chain */
+ struct mbuf *sb_mbtail; /* the last mbuf in the chain */
+ struct mbuf *sb_lastrecord;/* first mbuf of last record in
+ socket buffer */
+ short sb_flags; /* flags, see below */
+/* End area that is zeroed on flush. */
+#define sb_endzero sb_flags
+ int sb_flagsintr; /* flags, changed atomically */
+ uint64_t sb_timeo_nsecs;/* timeout for read/write */
+ struct selinfo sb_sel; /* process selecting read/write */
+ } so_rcv, so_snd;
+#define SB_MAX (2*1024*1024) /* default for max chars in sockbuf */
+#define SB_LOCK 0x01 /* lock on data queue */
+#define SB_WANT 0x02 /* someone is waiting to lock */
+#define SB_WAIT 0x04 /* someone is waiting for data/space */
+#define SB_SEL 0x08 /* someone is selecting */
+#define SB_ASYNC 0x10 /* ASYNC I/O, need signals */
+#define SB_SPLICE 0x20 /* buffer is splice source or drain */
+#define SB_NOINTR 0x40 /* operations not interruptible */
+#define SB_KNOTE 0x80 /* kernel note attached */
+
+ void (*so_upcall)(struct socket *so, caddr_t arg, int waitf);
+ caddr_t so_upcallarg; /* Arg for above */
+ uid_t so_euid, so_ruid; /* who opened the socket */
+ gid_t so_egid, so_rgid;
+ pid_t so_cpid; /* pid of process that opened socket */
+};
+
+/*
+ * Socket state bits.
+ */
+#define SS_NOFDREF 0x001 /* no file table ref any more */
+#define SS_ISCONNECTED 0x002 /* socket connected to a peer */
+#define SS_ISCONNECTING 0x004 /* in process of connecting to peer */
+#define SS_ISDISCONNECTING 0x008 /* in process of disconnecting */
+#define SS_CANTSENDMORE 0x010 /* can't send more data to peer */
+#define SS_CANTRCVMORE 0x020 /* can't receive more data from peer */
+#define SS_RCVATMARK 0x040 /* at mark on input */
+#define SS_ISDISCONNECTED 0x800 /* socket disconnected from peer */
+
+#define SS_PRIV 0x080 /* privileged for broadcast, raw... */
+#define SS_ASYNC 0x200 /* async i/o notify */
+#define SS_CONNECTOUT 0x1000 /* connect, not accept, at this end */
+#define SS_ISSENDING 0x2000 /* hint for lower layer */
+#define SS_DNS 0x4000 /* created using SOCK_DNS socket(2) */
+
+#ifdef _KERNEL
+
+#include <lib/libkern/libkern.h>
+
+/*
+ * Values for sounlock()/sofree().
+ */
+#define SL_NOUNLOCK 0x00
+#define SL_LOCKED 0x42
+
+void soassertlocked(struct socket *);
+
+/*
+ * Macros for sockets and socket buffering.
+ */
+
+#define isspliced(so) ((so)->so_sp && (so)->so_sp->ssp_socket)
+#define issplicedback(so) ((so)->so_sp && (so)->so_sp->ssp_soback)
+
+/*
+ * Do we need to notify the other side when I/O is possible?
+ */
+static inline int
+sb_notify(struct socket *so, struct sockbuf *sb)
+{
+ int flags = (sb->sb_flags | sb->sb_flagsintr);
+
+ KASSERT(sb == &so->so_rcv || sb == &so->so_snd);
+ soassertlocked(so);
+ return ((flags & (SB_WAIT|SB_SEL|SB_ASYNC|SB_SPLICE|SB_KNOTE)) != 0);
+}
+
+/*
+ * How much space is there in a socket buffer (so->so_snd or so->so_rcv)?
+ * This is problematical if the fields are unsigned, as the space might
+ * still be negative (cc > hiwat or mbcnt > mbmax). Should detect
+ * overflow and return 0.
+ */
+static inline long
+sbspace(struct socket *so, struct sockbuf *sb)
+{
+ KASSERT(sb == &so->so_rcv || sb == &so->so_snd);
+ soassertlocked(so);
+ return lmin(sb->sb_hiwat - sb->sb_cc, sb->sb_mbmax - sb->sb_mbcnt);
+}
+
+/* do we have to send all at once on a socket? */
+#define sosendallatonce(so) \
+ ((so)->so_proto->pr_flags & PR_ATOMIC)
+
+/* are we sending on this socket? */
+#define soissending(so) \
+ ((so)->so_state & SS_ISSENDING)
+
+/* can we read something from so? */
+static inline int
+soreadable(struct socket *so)
+{
+ soassertlocked(so);
+ if (isspliced(so))
+ return 0;
+ return (so->so_state & SS_CANTRCVMORE) || so->so_qlen || so->so_error ||
+ so->so_rcv.sb_cc >= so->so_rcv.sb_lowat;
+}
+
+/* can we write something to so? */
+#define sowriteable(so) \
+ ((sbspace((so), &(so)->so_snd) >= (so)->so_snd.sb_lowat && \
+ (((so)->so_state & SS_ISCONNECTED) || \
+ ((so)->so_proto->pr_flags & PR_CONNREQUIRED)==0)) || \
+ ((so)->so_state & SS_CANTSENDMORE) || (so)->so_error)
+
+/* adjust counters in sb reflecting allocation of m */
+#define sballoc(sb, m) do { \
+ (sb)->sb_cc += (m)->m_len; \
+ if ((m)->m_type != MT_CONTROL && (m)->m_type != MT_SONAME) \
+ (sb)->sb_datacc += (m)->m_len; \
+ (sb)->sb_mbcnt += MSIZE; \
+ if ((m)->m_flags & M_EXT) \
+ (sb)->sb_mbcnt += (m)->m_ext.ext_size; \
+} while (/* CONSTCOND */ 0)
+
+/* adjust counters in sb reflecting freeing of m */
+#define sbfree(sb, m) do { \
+ (sb)->sb_cc -= (m)->m_len; \
+ if ((m)->m_type != MT_CONTROL && (m)->m_type != MT_SONAME) \
+ (sb)->sb_datacc -= (m)->m_len; \
+ (sb)->sb_mbcnt -= MSIZE; \
+ if ((m)->m_flags & M_EXT) \
+ (sb)->sb_mbcnt -= (m)->m_ext.ext_size; \
+} while (/* CONSTCOND */ 0)
+
+/*
+ * Set lock on sockbuf sb; sleep if lock is already held.
+ * Unless SB_NOINTR is set on sockbuf, sleep is interruptible.
+ * Returns error without lock if sleep is interrupted.
+ */
+int sblock(struct socket *, struct sockbuf *, int);
+
+/* release lock on sockbuf sb */
+void sbunlock(struct socket *, struct sockbuf *);
+
+#define SB_EMPTY_FIXUP(sb) do { \
+ if ((sb)->sb_mb == NULL) { \
+ (sb)->sb_mbtail = NULL; \
+ (sb)->sb_lastrecord = NULL; \
+ } \
+} while (/*CONSTCOND*/0)
+
+extern u_long sb_max;
+
+extern struct pool socket_pool;
+
+struct mbuf;
+struct sockaddr;
+struct proc;
+struct msghdr;
+struct stat;
+struct knote;
+
+/*
+ * File operations on sockets.
+ */
+int soo_read(struct file *, struct uio *, int);
+int soo_write(struct file *, struct uio *, int);
+int soo_ioctl(struct file *, u_long, caddr_t, struct proc *);
+int soo_poll(struct file *, int events, struct proc *);
+int soo_kqfilter(struct file *, struct knote *);
+int soo_close(struct file *, struct proc *);
+int soo_stat(struct file *, struct stat *, struct proc *);
+void sbappend(struct socket *, struct sockbuf *, struct mbuf *);
+void sbappendstream(struct socket *, struct sockbuf *, struct mbuf *);
+int sbappendaddr(struct socket *, struct sockbuf *,
+ const struct sockaddr *, struct mbuf *, struct mbuf *);
+int sbappendcontrol(struct socket *, struct sockbuf *, struct mbuf *,
+ struct mbuf *);
+void sbappendrecord(struct socket *, struct sockbuf *, struct mbuf *);
+void sbcompress(struct sockbuf *sb, struct mbuf *m, struct mbuf *n);
+struct mbuf *
+ sbcreatecontrol(const void *, size_t, int type, int level);
+void sbdrop(struct socket *, struct sockbuf *, int);
+void sbdroprecord(struct sockbuf *sb);
+void sbflush(struct socket *, struct sockbuf *);
+void sbinsertoob(struct sockbuf *sb, struct mbuf *m0);
+void sbrelease(struct socket *, struct sockbuf *);
+int sbcheckreserve(u_long cnt, u_long defcnt);
+int sbchecklowmem(void);
+int sbreserve(struct socket *, struct sockbuf *, u_long);
+int sbwait(struct socket *, struct sockbuf *sb);
+int sb_lock(struct sockbuf *sb);
+void soinit(void);
+int soabort(struct socket *so);
+int soaccept(struct socket *so, struct mbuf *nam);
+int sobind(struct socket *so, struct mbuf *nam, struct proc *p);
+void socantrcvmore(struct socket *so);
+void socantsendmore(struct socket *so);
+int soclose(struct socket *, int);
+int soconnect(struct socket *so, struct mbuf *nam);
+int soconnect2(struct socket *so1, struct socket *so2);
+int socreate(int dom, struct socket **aso, int type, int proto);
+int sodisconnect(struct socket *so);
+void sofree(struct socket *so, int);
+int sogetopt(struct socket *so, int level, int optname, struct mbuf *m);
+void sohasoutofband(struct socket *so);
+void soisconnected(struct socket *so);
+void soisconnecting(struct socket *so);
+void soisdisconnected(struct socket *so);
+void soisdisconnecting(struct socket *so);
+int solisten(struct socket *so, int backlog);
+struct socket *sonewconn(struct socket *head, int connstatus);
+void soqinsque(struct socket *head, struct socket *so, int q);
+int soqremque(struct socket *so, int q);
+int soreceive(struct socket *so, struct mbuf **paddr, struct uio *uio,
+ struct mbuf **mp0, struct mbuf **controlp, int *flagsp,
+ socklen_t controllen);
+int soreserve(struct socket *so, u_long sndcc, u_long rcvcc);
+void sorflush(struct socket *so);
+int sosend(struct socket *so, struct mbuf *addr, struct uio *uio,
+ struct mbuf *top, struct mbuf *control, int flags);
+int sosetopt(struct socket *so, int level, int optname, struct mbuf *m);
+int soshutdown(struct socket *so, int how);
+void sowakeup(struct socket *so, struct sockbuf *sb);
+void sorwakeup(struct socket *);
+void sowwakeup(struct socket *);
+int sockargs(struct mbuf **, const void *, size_t, int);
+
+int sosleep_nsec(struct socket *, void *, int, const char *, uint64_t);
+int solock(struct socket *);
+void sounlock(struct socket *, int);
+
+int sendit(struct proc *, int, struct msghdr *, int, register_t *);
+int recvit(struct proc *, int, struct msghdr *, caddr_t,
+ register_t *);
+int doaccept(struct proc *, int, struct sockaddr *, socklen_t *, int,
+ register_t *);
+
+#ifdef SOCKBUF_DEBUG
+void sblastrecordchk(struct sockbuf *, const char *);
+#define SBLASTRECORDCHK(sb, where) sblastrecordchk((sb), (where))
+
+void sblastmbufchk(struct sockbuf *, const char *);
+#define SBLASTMBUFCHK(sb, where) sblastmbufchk((sb), (where))
+void sbcheck(struct sockbuf *sb);
+#define SBCHECK(sb) sbcheck(sb)
+#else
+#define SBLASTRECORDCHK(sb, where) /* nothing */
+#define SBLASTMBUFCHK(sb, where) /* nothing */
+#define SBCHECK(sb) /* nothing */
+#endif /* SOCKBUF_DEBUG */
+
+#endif /* _KERNEL */
diff --git a/sys/sys/sockio.h b/sys/sys/sockio.h
new file mode 100644
index 0000000..1198dd8
--- /dev/null
+++ b/sys/sys/sockio.h
@@ -0,0 +1,230 @@
+/* $OpenBSD: sockio.h,v 1.83 2019/11/13 11:54:01 tobhe Exp $ */
+/* $NetBSD: sockio.h,v 1.5 1995/08/23 00:40:47 thorpej Exp $ */
+
+/*-
+ * Copyright (c) 1982, 1986, 1990, 1993, 1994
+ * 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.
+ *
+ * @(#)sockio.h 8.1 (Berkeley) 3/28/94
+ */
+
+#ifndef _SYS_SOCKIO_H_
+#define _SYS_SOCKIO_H_
+
+#include <sys/ioccom.h>
+
+/* Socket ioctl's. */
+#define SIOCATMARK _IOR('s', 7, int) /* at oob mark? */
+#define SIOCSPGRP _IOW('s', 8, int) /* set process group */
+#define SIOCGPGRP _IOR('s', 9, int) /* get process group */
+
+#define SIOCSIFADDR _IOW('i', 12, struct ifreq) /* set ifnet address */
+#define SIOCGIFADDR _IOWR('i', 33, struct ifreq) /* get ifnet address */
+#define SIOCSIFDSTADDR _IOW('i', 14, struct ifreq) /* set p-p address */
+#define SIOCGIFDSTADDR _IOWR('i', 34, struct ifreq) /* get p-p address */
+#define SIOCSIFFLAGS _IOW('i', 16, struct ifreq) /* set ifnet flags */
+#define SIOCGIFFLAGS _IOWR('i', 17, struct ifreq) /* get ifnet flags */
+#define SIOCGIFBRDADDR _IOWR('i', 35, struct ifreq) /* get broadcast addr */
+#define SIOCSIFBRDADDR _IOW('i', 19, struct ifreq) /* set broadcast addr */
+#define SIOCGIFCONF _IOWR('i', 36, struct ifconf) /* get ifnet list */
+#define SIOCGIFNETMASK _IOWR('i', 37, struct ifreq) /* get net addr mask */
+#define SIOCSIFNETMASK _IOW('i', 22, struct ifreq) /* set net addr mask */
+#define SIOCGIFMETRIC _IOWR('i', 23, struct ifreq) /* get IF metric */
+#define SIOCSIFMETRIC _IOW('i', 24, struct ifreq) /* set IF metric */
+#define SIOCDIFADDR _IOW('i', 25, struct ifreq) /* delete IF addr */
+#define SIOCAIFADDR _IOW('i', 26, struct ifaliasreq)/* add/chg IF alias */
+#define SIOCGIFDATA _IOWR('i', 27, struct ifreq) /* get if_data */
+#define SIOCSIFLLADDR _IOW('i', 31, struct ifreq) /* set link level addr */
+
+#define SIOCADDMULTI _IOW('i', 49, struct ifreq) /* add m'cast addr */
+#define SIOCDELMULTI _IOW('i', 50, struct ifreq) /* del m'cast addr */
+#define SIOCGETVIFCNT _IOWR('u', 51, struct sioc_vif_req)/* vif pkt cnt */
+#define SIOCGETSGCNT _IOWR('u', 52, struct sioc_sg_req) /* sg pkt cnt */
+
+/* 53 and 54 used to be SIOC[SG]IFMEDIA with a 32 bit media word */
+#define SIOCSIFMEDIA _IOWR('i', 55, struct ifreq) /* set net media */
+#define SIOCGIFMEDIA _IOWR('i', 56, struct ifmediareq) /* get net media */
+#define SIOCGIFSFFPAGE _IOWR('i', 57, struct if_sffpage) /* get SFF page */
+
+#define SIOCDIFPHYADDR _IOW('i', 73, struct ifreq) /* delete gif addrs */
+#define SIOCSLIFPHYADDR _IOW('i', 74, struct if_laddrreq) /* set gif addrs */
+#define SIOCGLIFPHYADDR _IOWR('i', 75, struct if_laddrreq) /* get gif addrs */
+
+#define SIOCBRDGADD _IOW('i', 60, struct ifbreq) /* add bridge ifs */
+#define SIOCBRDGDEL _IOW('i', 61, struct ifbreq) /* del bridge ifs */
+#define SIOCBRDGGIFFLGS _IOWR('i', 62, struct ifbreq) /* get brdg if flags */
+#define SIOCBRDGSIFFLGS _IOW('i', 63, struct ifbreq) /* set brdg if flags */
+#define SIOCBRDGSCACHE _IOW('i', 64, struct ifbrparam)/* set cache size */
+#define SIOCBRDGGCACHE _IOWR('i', 65, struct ifbrparam)/* get cache size */
+#define SIOCBRDGADDS _IOW('i', 65, struct ifbreq) /* add span port */
+#define SIOCBRDGIFS _IOWR('i', 66, struct ifbreq) /* get member ifs */
+#define SIOCBRDGDELS _IOW('i', 66, struct ifbreq) /* del span port */
+#define SIOCBRDGRTS _IOWR('i', 67, struct ifbaconf) /* get addresses */
+#define SIOCBRDGSADDR _IOWR('i', 68, struct ifbareq) /* set addr flags */
+#define SIOCBRDGSTO _IOW('i', 69, struct ifbrparam)/* cache timeout */
+#define SIOCBRDGGTO _IOWR('i', 70, struct ifbrparam)/* cache timeout */
+#define SIOCBRDGDADDR _IOW('i', 71, struct ifbareq) /* delete addr */
+#define SIOCBRDGFLUSH _IOW('i', 72, struct ifbreq) /* flush addr cache */
+#define SIOCBRDGADDL _IOW('i', 73, struct ifbreq) /* add local port */
+#define SIOCBRDGSIFPROT _IOW('i', 74, struct ifbreq) /* set protected grp */
+
+#define SIOCBRDGARL _IOW('i', 77, struct ifbrlreq) /* add bridge rule */
+#define SIOCBRDGFRL _IOW('i', 78, struct ifbrlreq) /* flush brdg rules */
+#define SIOCBRDGGRL _IOWR('i', 79, struct ifbrlconf)/* get bridge rules */
+#define SIOCBRDGGPRI _IOWR('i', 80, struct ifbrparam)/* get priority */
+#define SIOCBRDGSPRI _IOW('i', 80, struct ifbrparam)/* set priority */
+#define SIOCBRDGGHT _IOWR('i', 81, struct ifbrparam)/* get hello time */
+#define SIOCBRDGSHT _IOW('i', 81, struct ifbrparam)/* set hello time */
+#define SIOCBRDGGFD _IOWR('i', 82, struct ifbrparam)/* get forward delay */
+#define SIOCBRDGSFD _IOW('i', 82, struct ifbrparam)/* set forward delay */
+#define SIOCBRDGGMA _IOWR('i', 83, struct ifbrparam)/* get max age */
+#define SIOCBRDGSMA _IOW('i', 83, struct ifbrparam)/* set max age */
+#define SIOCBRDGSIFPRIO _IOW('i', 84, struct ifbreq) /* set if priority */
+#define SIOCBRDGSIFCOST _IOW('i', 85, struct ifbreq) /* set if cost */
+
+#define SIOCBRDGGPARAM _IOWR('i', 88, struct ifbropreq)/* get brdg STP parms */
+#define SIOCBRDGSTXHC _IOW('i', 89, struct ifbrparam)/* set tx hold count */
+#define SIOCBRDGSPROTO _IOW('i', 90, struct ifbrparam)/* set protocol */
+#define SIOCBRDGS
+
+#define SIOCSWGDPID _IOWR('i', 91, struct ifbrparam)/* get datapath id */
+#define SIOCSWSDPID _IOW('i', 92, struct ifbrparam)/* set datapath id */
+#define SIOCSWGMAXGROUP _IOWR('i', 93, struct ifbrparam)/* get max groups */
+#define SIOCSWSPORTNO _IOWR('i', 95, struct ifbreq) /* set port number */
+#define SIOCSWGMAXFLOW _IOWR('i', 96, struct ifbrparam)/* get max flow per table */
+
+#define SIOCSIFMTU _IOW('i', 127, struct ifreq) /* set ifnet mtu */
+#define SIOCGIFMTU _IOWR('i', 126, struct ifreq) /* get ifnet mtu */
+
+#define SIOCIFCREATE _IOW('i', 122, struct ifreq) /* create clone if */
+#define SIOCIFDESTROY _IOW('i', 121, struct ifreq) /* destroy clone if */
+#define SIOCIFGCLONERS _IOWR('i', 120, struct if_clonereq) /* get cloners */
+
+#define SIOCAIFGROUP _IOW('i', 135, struct ifgroupreq) /* add an ifgroup */
+#define SIOCGIFGROUP _IOWR('i', 136, struct ifgroupreq) /* get ifgroups */
+#define SIOCDIFGROUP _IOW('i', 137, struct ifgroupreq) /* delete ifgroup */
+#define SIOCGIFGMEMB _IOWR('i', 138, struct ifgroupreq) /* get members */
+#define SIOCGIFGATTR _IOWR('i', 139, struct ifgroupreq) /* get ifgroup attribs */
+#define SIOCSIFGATTR _IOW('i', 140, struct ifgroupreq) /* set ifgroup attribs */
+#define SIOCGIFGLIST _IOWR('i', 141, struct ifgroupreq) /* get ifgroup list */
+
+#define SIOCSIFDESCR _IOW('i', 128, struct ifreq) /* set ifnet descr */
+#define SIOCGIFDESCR _IOWR('i', 129, struct ifreq) /* get ifnet descr */
+
+#define SIOCSIFRTLABEL _IOW('i', 130, struct ifreq) /* set ifnet rtlabel */
+#define SIOCGIFRTLABEL _IOWR('i', 131, struct ifreq) /* set ifnet rtlabel */
+
+#define SIOCSETVLAN _IOW('i', 143, struct ifreq) /* set vlan parent if */
+#define SIOCGETVLAN _IOWR('i', 144, struct ifreq) /* get vlan parent if */
+
+#define SIOCSSPPPPARAMS _IOW('i', 147, struct ifreq) /* set pppoe params */
+#define SIOCGSPPPPARAMS _IOWR('i', 148, struct ifreq) /* get pppoe params */
+
+#define SIOCDELLABEL _IOW('i', 151, struct ifreq) /* del MPLS label */
+#define SIOCGPWE3 _IOWR('i', 152, struct ifreq) /* get MPLS PWE3 cap */
+#define SIOCSETLABEL _IOW('i', 153, struct ifreq) /* set MPLS label */
+#define SIOCGETLABEL _IOW('i', 154, struct ifreq) /* get MPLS label */
+
+#define SIOCSIFPRIORITY _IOW('i', 155, struct ifreq) /* set if priority */
+#define SIOCGIFPRIORITY _IOWR('i', 156, struct ifreq) /* get if priority */
+
+#define SIOCSIFXFLAGS _IOW('i', 157, struct ifreq) /* set ifnet xflags */
+#define SIOCGIFXFLAGS _IOWR('i', 158, struct ifreq) /* get ifnet xflags */
+
+#define SIOCSIFRDOMAIN _IOW('i', 159, struct ifreq) /* set ifnet VRF id */
+#define SIOCGIFRDOMAIN _IOWR('i', 160, struct ifreq) /* get ifnet VRF id */
+
+#define SIOCSLIFPHYRTABLE _IOW('i', 161, struct ifreq) /* set tunnel VRF id */
+#define SIOCGLIFPHYRTABLE _IOWR('i', 162, struct ifreq) /* get tunnel VRF id */
+
+#define SIOCSETKALIVE _IOW('i', 163, struct ifkalivereq)
+#define SIOCGETKALIVE _IOWR('i', 164, struct ifkalivereq)
+
+#define SIOCGIFHARDMTU _IOWR('i', 165, struct ifreq) /* get ifnet hardmtu */
+
+#define SIOCSVNETID _IOW('i', 166, struct ifreq) /* set virt net id */
+#define SIOCGVNETID _IOWR('i', 167, struct ifreq) /* get virt net id */
+
+#define SIOCSLIFPHYTTL _IOW('i', 168, struct ifreq) /* set tunnel ttl */
+#define SIOCGLIFPHYTTL _IOWR('i', 169, struct ifreq) /* get tunnel ttl */
+
+#define SIOCGIFRXR _IOW('i', 170, struct ifreq)
+#define SIOCIFAFATTACH _IOW('i', 171, struct if_afreq) /* attach given af */
+#define SIOCIFAFDETACH _IOW('i', 172, struct if_afreq) /* detach given af */
+
+#define SIOCSETMPWCFG _IOW('i', 173, struct ifreq) /* set mpw config */
+#define SIOCGETMPWCFG _IOWR('i', 174, struct ifreq) /* get mpw config */
+
+#define SIOCDVNETID _IOW('i', 175, struct ifreq) /* del virt net id */
+
+#define SIOCSIFPAIR _IOW('i', 176, struct ifreq) /* set paired if */
+#define SIOCGIFPAIR _IOWR('i', 177, struct ifreq) /* get paired if */
+
+#define SIOCSIFPARENT _IOW('i', 178, struct if_parent) /* set parent if */
+#define SIOCGIFPARENT _IOWR('i', 179, struct if_parent) /* get parent if */
+#define SIOCDIFPARENT _IOW('i', 180, struct ifreq) /* del parent if */
+
+#define SIOCSIFLLPRIO _IOW('i', 181, struct ifreq) /* set ifnet llprio */
+#define SIOCGIFLLPRIO _IOWR('i', 182, struct ifreq) /* get ifnet llprio */
+
+#define SIOCGUMBINFO _IOWR('i', 190, struct ifreq) /* get MBIM info */
+#define SIOCSUMBPARAM _IOW('i', 191, struct ifreq) /* set MBIM param */
+#define SIOCGUMBPARAM _IOWR('i', 192, struct ifreq) /* get MBIM param */
+
+#define SIOCSLIFPHYDF _IOW('i', 193, struct ifreq) /* set tunnel df/nodf */
+#define SIOCGLIFPHYDF _IOWR('i', 194, struct ifreq) /* set tunnel df/nodf */
+
+#define SIOCSVNETFLOWID _IOW('i', 195, struct ifreq) /* set vnet flowid */
+#define SIOCGVNETFLOWID _IOWR('i', 196, struct ifreq) /* get vnet flowid */
+
+#define SIOCSTXHPRIO _IOW('i', 197, struct ifreq) /* set tx hdr prio */
+#define SIOCGTXHPRIO _IOWR('i', 198, struct ifreq) /* get tx hdr prio */
+
+#define SIOCSLIFPHYECN _IOW('i', 199, struct ifreq) /* set ecn copying */
+#define SIOCGLIFPHYECN _IOWR('i', 200, struct ifreq) /* get ecn copying */
+
+#define SIOCSRXHPRIO _IOW('i', 219, struct ifreq) /* set rx hdr prio */
+#define SIOCGRXHPRIO _IOWR('i', 219, struct ifreq) /* get rx hdr prio */
+
+#define SIOCSPWE3CTRLWORD _IOW('i', 220, struct ifreq)
+#define SIOCGPWE3CTRLWORD _IOWR('i', 220, struct ifreq)
+#define SIOCSPWE3FAT _IOW('i', 221, struct ifreq)
+#define SIOCGPWE3FAT _IOWR('i', 221, struct ifreq)
+#define SIOCSPWE3NEIGHBOR _IOW('i', 222, struct if_laddrreq)
+#define SIOCGPWE3NEIGHBOR _IOWR('i', 222, struct if_laddrreq)
+#define SIOCDPWE3NEIGHBOR _IOW('i', 222, struct ifreq)
+
+#define SIOCSVH _IOWR('i', 245, struct ifreq) /* set carp param */
+#define SIOCGVH _IOWR('i', 246, struct ifreq) /* get carp param */
+
+#define SIOCSETPFSYNC _IOW('i', 247, struct ifreq)
+#define SIOCGETPFSYNC _IOWR('i', 248, struct ifreq)
+
+#define SIOCSETPFLOW _IOW('i', 253, struct ifreq)
+#define SIOCGETPFLOW _IOWR('i', 254, struct ifreq)
+
+#endif /* !_SYS_SOCKIO_H_ */
diff --git a/sys/sys/specdev.h b/sys/sys/specdev.h
new file mode 100644
index 0000000..2570b20
--- /dev/null
+++ b/sys/sys/specdev.h
@@ -0,0 +1,113 @@
+/* $OpenBSD: specdev.h,v 1.39 2019/12/27 22:17:01 bluhm Exp $ */
+/* $NetBSD: specdev.h,v 1.12 1996/02/13 13:13:01 mycroft Exp $ */
+
+/*
+ * Copyright (c) 1990, 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.
+ *
+ * @(#)specdev.h 8.3 (Berkeley) 8/10/94
+ */
+
+SLIST_HEAD(vnodechain, vnode);
+
+/*
+ * This structure defines the information maintained about
+ * special devices. It is allocated in checkalias and freed
+ * in vgone.
+ */
+struct specinfo {
+ struct vnodechain *si_hashchain;
+ SLIST_ENTRY(vnode) si_specnext;
+ struct mount *si_mountpoint;
+ dev_t si_rdev;
+ struct lockf_state *si_lockf;
+ daddr_t si_lastr;
+ union {
+ struct vnode *ci_parent; /* pointer back to parent device */
+ u_int8_t *ci_bitmap; /* bitmap of devices cloned off us */
+ } si_ci;
+};
+
+struct cloneinfo {
+ struct vnode *ci_vp; /* cloned vnode */
+ void *ci_data; /* original vnode's v_data */
+};
+
+/*
+ * Exported shorthand
+ */
+#define v_rdev v_specinfo->si_rdev
+#define v_hashchain v_specinfo->si_hashchain
+#define v_specnext v_specinfo->si_specnext
+#define v_specmountpoint v_specinfo->si_mountpoint
+#define v_speclockf v_specinfo->si_lockf
+#define v_specparent v_specinfo->si_ci.ci_parent
+#define v_specbitmap v_specinfo->si_ci.ci_bitmap
+
+/*
+ * We use the upper 16 bits of the minor to record the clone instance.
+ * This gives us 8 bits for encoding the real minor number.
+ */
+#define CLONE_SHIFT 8
+#define CLONE_MAPSZ 128
+
+/*
+ * Special device management
+ */
+#define SPECHSZ 64
+#if ((SPECHSZ&(SPECHSZ-1)) == 0)
+#define SPECHASH(rdev) (((rdev>>5)+(rdev))&(SPECHSZ-1))
+#else
+#define SPECHASH(rdev) (((unsigned)((rdev>>5)+(rdev)))%SPECHSZ)
+#endif
+
+#ifdef _KERNEL
+
+extern struct vnodechain speclisth[SPECHSZ];
+
+/*
+ * Prototypes for special file operations on vnodes.
+ */
+int spec_badop(void *);
+int spec_getattr(void *);
+int spec_setattr(void *);
+int spec_access(void *);
+int spec_open(void *);
+int spec_close(void *);
+int spec_read(void *);
+int spec_write(void *);
+int spec_ioctl(void *);
+int spec_poll(void *);
+int spec_kqfilter(void *);
+int spec_fsync(void *);
+int spec_inactive(void *);
+int spec_strategy(void *);
+int spec_print(void *);
+int spec_pathconf(void *);
+int spec_advlock(void *);
+
+#endif /* _KERNEL */
diff --git a/sys/sys/srp.h b/sys/sys/srp.h
new file mode 100644
index 0000000..a22e940
--- /dev/null
+++ b/sys/sys/srp.h
@@ -0,0 +1,190 @@
+/* $OpenBSD: srp.h,v 1.14 2019/03/31 14:03:40 mpi Exp $ */
+
+/*
+ * Copyright (c) 2014 Jonathan Matthew <jmatthew@openbsd.org>
+ *
+ * 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.
+ */
+
+#ifndef _SYS_SRP_H_
+#define _SYS_SRP_H_
+
+#include <sys/refcnt.h>
+
+#ifndef __upunused
+#ifdef MULTIPROCESSOR
+#define __upunused
+#else
+#define __upunused __attribute__((__unused__))
+#endif
+#endif /* __upunused */
+
+struct srp {
+ void *ref;
+};
+
+#define SRP_INITIALIZER() { NULL }
+
+struct srp_hazard {
+ struct srp *sh_p;
+ void *sh_v;
+};
+
+struct srp_ref {
+ struct srp_hazard *hz;
+} __upunused;
+
+#define SRP_HAZARD_NUM 16
+
+struct srp_gc {
+ void (*srp_gc_dtor)(void *, void *);
+ void *srp_gc_cookie;
+ struct refcnt srp_gc_refcnt;
+};
+
+#define SRP_GC_INITIALIZER(_d, _c) { (_d), (_c), REFCNT_INITIALIZER() }
+
+/*
+ * singly linked list built by following srps
+ */
+
+struct srpl_rc {
+ void (*srpl_ref)(void *, void *);
+ struct srp_gc srpl_gc;
+};
+#define srpl_cookie srpl_gc.srp_gc_cookie
+
+#define SRPL_RC_INITIALIZER(_r, _u, _c) { _r, SRP_GC_INITIALIZER(_u, _c) }
+
+struct srpl {
+ struct srp sl_head;
+};
+
+#define SRPL_HEAD(name, type) struct srpl
+
+#define SRPL_ENTRY(type) \
+struct { \
+ struct srp se_next; \
+}
+
+#ifdef _KERNEL
+
+void srp_startup(void);
+void srp_gc_init(struct srp_gc *, void (*)(void *, void *), void *);
+void *srp_swap_locked(struct srp *, void *);
+void srp_update_locked(struct srp_gc *, struct srp *, void *);
+void *srp_get_locked(struct srp *);
+void srp_gc_finalize(struct srp_gc *);
+
+void srp_init(struct srp *);
+
+#ifdef MULTIPROCESSOR
+void *srp_swap(struct srp *, void *);
+void srp_update(struct srp_gc *, struct srp *, void *);
+void srp_finalize(void *, const char *);
+void *srp_enter(struct srp_ref *, struct srp *);
+void *srp_follow(struct srp_ref *, struct srp *);
+void srp_leave(struct srp_ref *);
+#else /* MULTIPROCESSOR */
+#define srp_swap(_srp, _v) srp_swap_locked((_srp), (_v))
+#define srp_update(_gc, _srp, _v) srp_update_locked((_gc), (_srp), (_v))
+#define srp_finalize(_v, _wchan) ((void)0)
+#define srp_enter(_sr, _srp) ((_srp)->ref)
+#define srp_follow(_sr, _srp) ((_srp)->ref)
+#define srp_leave(_sr) do { } while (0)
+#endif /* MULTIPROCESSOR */
+
+
+void srpl_rc_init(struct srpl_rc *, void (*)(void *, void *),
+ void (*)(void *, void *), void *);
+
+#define SRPL_INIT(_sl) srp_init(&(_sl)->sl_head)
+
+#define SRPL_FIRST(_sr, _sl) srp_enter((_sr), &(_sl)->sl_head)
+#define SRPL_NEXT(_sr, _e, _ENTRY) srp_enter((_sr), &(_e)->_ENTRY.se_next)
+#define SRPL_FOLLOW(_sr, _e, _ENTRY) srp_follow((_sr), &(_e)->_ENTRY.se_next)
+
+#define SRPL_FOREACH(_c, _sr, _sl, _ENTRY) \
+ for ((_c) = SRPL_FIRST(_sr, _sl); \
+ (_c) != NULL; \
+ (_c) = SRPL_FOLLOW(_sr, _c, _ENTRY))
+
+#define SRPL_LEAVE(_sr) srp_leave((_sr))
+
+#define SRPL_FIRST_LOCKED(_sl) srp_get_locked(&(_sl)->sl_head)
+#define SRPL_EMPTY_LOCKED(_sl) (SRPL_FIRST_LOCKED(_sl) == NULL)
+
+#define SRPL_NEXT_LOCKED(_e, _ENTRY) \
+ srp_get_locked(&(_e)->_ENTRY.se_next)
+
+#define SRPL_FOREACH_LOCKED(_c, _sl, _ENTRY) \
+ for ((_c) = SRPL_FIRST_LOCKED(_sl); \
+ (_c) != NULL; \
+ (_c) = SRPL_NEXT_LOCKED((_c), _ENTRY))
+
+#define SRPL_FOREACH_SAFE_LOCKED(_c, _sl, _ENTRY, _tc) \
+ for ((_c) = SRPL_FIRST_LOCKED(_sl); \
+ (_c) && ((_tc) = SRPL_NEXT_LOCKED(_c, _ENTRY), 1); \
+ (_c) = (_tc))
+
+#define SRPL_INSERT_HEAD_LOCKED(_rc, _sl, _e, _ENTRY) do { \
+ void *head; \
+ \
+ srp_init(&(_e)->_ENTRY.se_next); \
+ \
+ head = SRPL_FIRST_LOCKED(_sl); \
+ if (head != NULL) { \
+ (_rc)->srpl_ref(&(_rc)->srpl_cookie, head); \
+ srp_update_locked(&(_rc)->srpl_gc, \
+ &(_e)->_ENTRY.se_next, head); \
+ } \
+ \
+ (_rc)->srpl_ref(&(_rc)->srpl_cookie, _e); \
+ srp_update_locked(&(_rc)->srpl_gc, &(_sl)->sl_head, (_e)); \
+} while (0)
+
+#define SRPL_INSERT_AFTER_LOCKED(_rc, _se, _e, _ENTRY) do { \
+ void *next; \
+ \
+ srp_init(&(_e)->_ENTRY.se_next); \
+ \
+ next = SRPL_NEXT_LOCKED(_se, _ENTRY); \
+ if (next != NULL) { \
+ (_rc)->srpl_ref(&(_rc)->srpl_cookie, next); \
+ srp_update_locked(&(_rc)->srpl_gc, \
+ &(_e)->_ENTRY.se_next, next); \
+ } \
+ \
+ (_rc)->srpl_ref(&(_rc)->srpl_cookie, _e); \
+ srp_update_locked(&(_rc)->srpl_gc, \
+ &(_se)->_ENTRY.se_next, (_e)); \
+} while (0)
+
+#define SRPL_REMOVE_LOCKED(_rc, _sl, _e, _type, _ENTRY) do { \
+ struct srp *ref; \
+ struct _type *c, *n; \
+ \
+ ref = &(_sl)->sl_head; \
+ while ((c = srp_get_locked(ref)) != (_e)) \
+ ref = &c->_ENTRY.se_next; \
+ \
+ n = SRPL_NEXT_LOCKED(c, _ENTRY); \
+ if (n != NULL) \
+ (_rc)->srpl_ref(&(_rc)->srpl_cookie, n); \
+ srp_update_locked(&(_rc)->srpl_gc, ref, n); \
+ srp_update_locked(&(_rc)->srpl_gc, &c->_ENTRY.se_next, NULL); \
+} while (0)
+
+#endif /* _KERNEL */
+
+#endif /* _SYS_SRP_H_ */
diff --git a/sys/sys/stacktrace.h b/sys/sys/stacktrace.h
new file mode 100644
index 0000000..5d78b75
--- /dev/null
+++ b/sys/sys/stacktrace.h
@@ -0,0 +1,40 @@
+/* $OpenBSD: stacktrace.h,v 1.3 2020/04/18 04:45:20 visa Exp $ */
+
+/*
+ * Copyright (c) 2017 Visa Hankala
+ *
+ * Permission to use, copy, modify, and/or 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.
+ */
+
+#ifndef _SYS_STACKTRACE_H_
+#define _SYS_STACKTRACE_H_
+
+#define STACKTRACE_MAX 19
+
+struct stacktrace {
+ unsigned int st_count;
+ unsigned long st_pc[STACKTRACE_MAX];
+};
+
+#ifdef _KERNEL
+void stacktrace_print(struct stacktrace *, int (*)(const char *, ...));
+void stacktrace_save_at(struct stacktrace *, unsigned int);
+
+static inline void
+stacktrace_save(struct stacktrace *st)
+{
+ stacktrace_save_at(st, 0);
+}
+#endif
+
+#endif /* _SYS_STACKTRACE_H_ */
diff --git a/sys/sys/stat.h b/sys/sys/stat.h
new file mode 100644
index 0000000..564548f
--- /dev/null
+++ b/sys/sys/stat.h
@@ -0,0 +1,222 @@
+/* $OpenBSD: stat.h,v 1.28 2015/04/04 18:06:08 jca Exp $ */
+/* $NetBSD: stat.h,v 1.20 1996/05/16 22:17:49 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1982, 1986, 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)stat.h 8.9 (Berkeley) 8/17/94
+ */
+
+#ifndef _SYS_STAT_H_
+#define _SYS_STAT_H_
+
+#include <sys/time.h>
+
+struct stat {
+ mode_t st_mode; /* inode protection mode */
+ dev_t st_dev; /* inode's device */
+ ino_t st_ino; /* inode's number */
+ nlink_t st_nlink; /* number of hard links */
+ uid_t st_uid; /* user ID of the file's owner */
+ gid_t st_gid; /* group ID of the file's group */
+ dev_t st_rdev; /* device type */
+#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE
+ struct timespec st_atim; /* time of last access */
+ struct timespec st_mtim; /* time of last data modification */
+ struct timespec st_ctim; /* time of last file status change */
+#else
+ time_t st_atime; /* time of last access */
+ long st_atimensec; /* nsec of last access */
+ time_t st_mtime; /* time of last data modification */
+ long st_mtimensec; /* nsec of last data modification */
+ time_t st_ctime; /* time of last file status change */
+ long st_ctimensec; /* nsec of last file status change */
+#endif /* __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE */
+ off_t st_size; /* file size, in bytes */
+ blkcnt_t st_blocks; /* blocks allocated for file */
+ blksize_t st_blksize; /* optimal blocksize for I/O */
+ u_int32_t st_flags; /* user defined flags for file */
+ u_int32_t st_gen; /* file generation number */
+#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE
+ struct timespec __st_birthtim; /* time of file creation */
+#else
+ time_t __st_birthtime; /* time of file creation */
+ long __st_birthtimensec; /* nsec of file creation */
+#endif /* __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE */
+};
+#if __POSIX_VISIBLE >= 200809 || __BSD_VISIBLE
+#define st_atime st_atim.tv_sec
+#define st_mtime st_mtim.tv_sec
+#define st_ctime st_ctim.tv_sec
+#define __st_birthtime __st_birthtim.tv_sec
+#endif
+#if __BSD_VISIBLE
+#define st_atimespec st_atim
+#define st_atimensec st_atim.tv_nsec
+#define st_mtimespec st_mtim
+#define st_mtimensec st_mtim.tv_nsec
+#define st_ctimespec st_ctim
+#define st_ctimensec st_ctim.tv_nsec
+#define __st_birthtimespec __st_birthtim
+#define __st_birthtimensec __st_birthtim.tv_nsec
+#endif
+
+#define S_ISUID 0004000 /* set user id on execution */
+#define S_ISGID 0002000 /* set group id on execution */
+#if __BSD_VISIBLE
+#define S_ISTXT 0001000 /* sticky bit */
+#endif
+
+#define S_IRWXU 0000700 /* RWX mask for owner */
+#define S_IRUSR 0000400 /* R for owner */
+#define S_IWUSR 0000200 /* W for owner */
+#define S_IXUSR 0000100 /* X for owner */
+
+#if __BSD_VISIBLE
+#define S_IREAD S_IRUSR
+#define S_IWRITE S_IWUSR
+#define S_IEXEC S_IXUSR
+#endif
+
+#define S_IRWXG 0000070 /* RWX mask for group */
+#define S_IRGRP 0000040 /* R for group */
+#define S_IWGRP 0000020 /* W for group */
+#define S_IXGRP 0000010 /* X for group */
+
+#define S_IRWXO 0000007 /* RWX mask for other */
+#define S_IROTH 0000004 /* R for other */
+#define S_IWOTH 0000002 /* W for other */
+#define S_IXOTH 0000001 /* X for other */
+
+#if __XPG_VISIBLE || __BSD_VISIBLE
+#define S_IFMT 0170000 /* type of file mask */
+#define S_IFIFO 0010000 /* named pipe (fifo) */
+#define S_IFCHR 0020000 /* character special */
+#define S_IFDIR 0040000 /* directory */
+#define S_IFBLK 0060000 /* block special */
+#define S_IFREG 0100000 /* regular */
+#define S_IFLNK 0120000 /* symbolic link */
+#define S_IFSOCK 0140000 /* socket */
+#define S_ISVTX 0001000 /* save swapped text even after use */
+#endif
+
+#define S_ISDIR(m) ((m & 0170000) == 0040000) /* directory */
+#define S_ISCHR(m) ((m & 0170000) == 0020000) /* char special */
+#define S_ISBLK(m) ((m & 0170000) == 0060000) /* block special */
+#define S_ISREG(m) ((m & 0170000) == 0100000) /* regular file */
+#define S_ISFIFO(m) ((m & 0170000) == 0010000) /* fifo */
+#if __POSIX_VISIBLE >= 200112 || __BSD_VISIBLE
+#define S_ISLNK(m) ((m & 0170000) == 0120000) /* symbolic link */
+#define S_ISSOCK(m) ((m & 0170000) == 0140000) /* socket */
+#endif
+
+#if __POSIX_VISIBLE >= 200809
+/* manadated to be present, but permitted to always return zero */
+#define S_TYPEISMQ(m) 0
+#define S_TYPEISSEM(m) 0
+#define S_TYPEISSHM(m) 0
+#endif
+
+#if __BSD_VISIBLE
+#define ACCESSPERMS (S_IRWXU|S_IRWXG|S_IRWXO) /* 00777 */
+ /* 07777 */
+#define ALLPERMS (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO)
+ /* 00666 */
+#define DEFFILEMODE (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)
+
+#define S_BLKSIZE 512 /* block size used in the stat struct */
+
+/*
+ * Definitions of flags stored in file flags word.
+ *
+ * Super-user and owner changeable flags.
+ */
+#define UF_SETTABLE 0x0000ffff /* mask of owner changeable flags */
+#define UF_NODUMP 0x00000001 /* do not dump file */
+#define UF_IMMUTABLE 0x00000002 /* file may not be changed */
+#define UF_APPEND 0x00000004 /* writes to file may only append */
+#define UF_OPAQUE 0x00000008 /* directory is opaque wrt. union */
+/*
+ * Super-user changeable flags.
+ */
+#define SF_SETTABLE 0xffff0000 /* mask of superuser changeable flags */
+#define SF_ARCHIVED 0x00010000 /* file is archived */
+#define SF_IMMUTABLE 0x00020000 /* file may not be changed */
+#define SF_APPEND 0x00040000 /* writes to file may only append */
+
+#ifdef _KERNEL
+/*
+ * Shorthand abbreviations of above.
+ */
+#define OPAQUE (UF_OPAQUE)
+#define APPEND (UF_APPEND | SF_APPEND)
+#define IMMUTABLE (UF_IMMUTABLE | SF_IMMUTABLE)
+#endif /* _KERNEL */
+#endif /* __BSD_VISIBLE */
+
+#if __POSIX_VISIBLE >= 200809
+#define UTIME_NOW -2L
+#define UTIME_OMIT -1L
+#endif /* __POSIX_VISIBLE */
+
+#ifndef _KERNEL
+__BEGIN_DECLS
+int chmod(const char *, mode_t);
+int fstat(int, struct stat *);
+int mknod(const char *, mode_t, dev_t);
+int mkdir(const char *, mode_t);
+int mkfifo(const char *, mode_t);
+int stat(const char *, struct stat *);
+mode_t umask(mode_t);
+#if __POSIX_VISIBLE >= 200112L || __XPG_VISIBLE >= 420 || __BSD_VISIBLE
+int fchmod(int, mode_t);
+int lstat(const char *, struct stat *);
+#endif
+#if __POSIX_VISIBLE >= 200809
+int fchmodat(int, const char *, mode_t, int);
+int fstatat(int, const char *, struct stat *, int);
+int mkdirat(int, const char *, mode_t);
+int mkfifoat(int, const char *, mode_t);
+int mknodat(int, const char *, mode_t, dev_t);
+int utimensat(int, const char *, const struct timespec [2], int);
+int futimens(int, const struct timespec [2]);
+#endif
+#if __BSD_VISIBLE
+int chflags(const char *, unsigned int);
+int chflagsat(int, const char *, unsigned int, int);
+int fchflags(int, unsigned int);
+int isfdtype(int, int);
+#endif
+__END_DECLS
+#endif
+#endif /* !_SYS_STAT_H_ */
diff --git a/sys/sys/statvfs.h b/sys/sys/statvfs.h
new file mode 100644
index 0000000..7c6492b
--- /dev/null
+++ b/sys/sys/statvfs.h
@@ -0,0 +1,48 @@
+/* $OpenBSD: statvfs.h,v 1.3 2013/03/24 17:45:50 deraadt Exp $ */
+
+/*
+ * Copyright (c) 2008 Otto Moerbeek <otto@drijf.net>
+ *
+ * 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.
+ */
+
+#ifndef _SYS_STATVFS_H_
+#define _SYS_STATVFS_H_
+
+#include <sys/types.h>
+
+struct statvfs {
+ unsigned long f_bsize; /* file system block size */
+ unsigned long f_frsize; /* fundamental file system block size */
+ fsblkcnt_t f_blocks; /* number of blocks (unit f_frsize) */
+ fsblkcnt_t f_bfree; /* free blocks in file system */
+ fsblkcnt_t f_bavail; /* free blocks for non-root */
+ fsfilcnt_t f_files; /* total file inodes */
+ fsfilcnt_t f_ffree; /* free file inodes */
+ fsfilcnt_t f_favail; /* free file inodes for to non-root */
+ unsigned long f_fsid; /* file system id */
+ unsigned long f_flag; /* bit mask of f_flag values */
+ unsigned long f_namemax; /* maximum filename length */
+};
+
+#define ST_RDONLY 0x0001UL /* read-only filesystem */
+#define ST_NOSUID 0x0002UL /* nosuid flag set */
+
+#ifndef _KERNEL
+__BEGIN_DECLS
+int fstatvfs(int, struct statvfs *);
+int statvfs(const char *, struct statvfs *);
+__END_DECLS
+#endif /* !_KERNEL */
+
+#endif /* !_SYS_STATVFS_H_ */
diff --git a/sys/sys/stdarg.h b/sys/sys/stdarg.h
new file mode 100644
index 0000000..7b9b403
--- /dev/null
+++ b/sys/sys/stdarg.h
@@ -0,0 +1,51 @@
+/* $OpenBSD: stdarg.h,v 1.9 2019/12/12 15:55:36 visa Exp $ */
+/*
+ * Copyright (c) 2003, 2004 Marc espie <espie@openbsd.org>
+ *
+ * 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.
+ */
+
+#ifndef _STDARG_H_
+#define _STDARG_H_
+
+#include <sys/cdefs.h>
+
+#if (defined(__GNUC__) && __GNUC__ >= 3) || defined(__PCC__)
+
+/* Define __gnuc_va_list. */
+
+#ifndef __GNUC_VA_LIST
+#define __GNUC_VA_LIST
+typedef __builtin_va_list __gnuc_va_list;
+#endif
+
+/* Note that the type used in va_arg is supposed to match the
+ actual type **after default promotions**.
+ Thus, va_arg (..., short) is not valid. */
+
+#define va_start(ap, last) __builtin_va_start((ap), last)
+#define va_end(ap) __builtin_va_end((ap))
+#define va_arg(ap, type) __builtin_va_arg((ap), type)
+#define __va_copy(dst, src) __builtin_va_copy((dst),(src))
+
+typedef __gnuc_va_list va_list;
+
+#else
+#error "unsupported compiler"
+#endif
+
+#if __ISO_C_VISIBLE >= 1999
+#define va_copy(dst, src) __va_copy((dst), (src))
+#endif
+
+#endif /* not _STDARG_H_ */
diff --git a/sys/sys/stdint.h b/sys/sys/stdint.h
new file mode 100644
index 0000000..5d3fd94
--- /dev/null
+++ b/sys/sys/stdint.h
@@ -0,0 +1,231 @@
+/* $OpenBSD: stdint.h,v 1.11 2019/01/25 00:19:26 millert Exp $ */
+
+/*
+ * Copyright (c) 1997, 2005 Todd C. Miller <millert@openbsd.org>
+ *
+ * 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.
+ */
+
+#ifndef _SYS_STDINT_H_
+#define _SYS_STDINT_H_
+
+#include <sys/cdefs.h>
+#include <machine/_types.h>
+
+#ifndef __BIT_TYPES_DEFINED__
+#define __BIT_TYPES_DEFINED__
+#endif
+
+/* 7.18.1.1 Exact-width integer types (also in sys/types.h) */
+#ifndef _INT8_T_DEFINED_
+#define _INT8_T_DEFINED_
+typedef __int8_t int8_t;
+#endif
+
+#ifndef _UINT8_T_DEFINED_
+#define _UINT8_T_DEFINED_
+typedef __uint8_t uint8_t;
+#endif
+
+#ifndef _INT16_T_DEFINED_
+#define _INT16_T_DEFINED_
+typedef __int16_t int16_t;
+#endif
+
+#ifndef _UINT16_T_DEFINED_
+#define _UINT16_T_DEFINED_
+typedef __uint16_t uint16_t;
+#endif
+
+#ifndef _INT32_T_DEFINED_
+#define _INT32_T_DEFINED_
+typedef __int32_t int32_t;
+#endif
+
+#ifndef _UINT32_T_DEFINED_
+#define _UINT32_T_DEFINED_
+typedef __uint32_t uint32_t;
+#endif
+
+#ifndef _INT64_T_DEFINED_
+#define _INT64_T_DEFINED_
+typedef __int64_t int64_t;
+#endif
+
+#ifndef _UINT64_T_DEFINED_
+#define _UINT64_T_DEFINED_
+typedef __uint64_t uint64_t;
+#endif
+
+/* 7.18.1.2 Minimum-width integer types */
+typedef __int_least8_t int_least8_t;
+typedef __uint_least8_t uint_least8_t;
+typedef __int_least16_t int_least16_t;
+typedef __uint_least16_t uint_least16_t;
+typedef __int_least32_t int_least32_t;
+typedef __uint_least32_t uint_least32_t;
+typedef __int_least64_t int_least64_t;
+typedef __uint_least64_t uint_least64_t;
+
+/* 7.18.1.3 Fastest minimum-width integer types */
+typedef __int_fast8_t int_fast8_t;
+typedef __uint_fast8_t uint_fast8_t;
+typedef __int_fast16_t int_fast16_t;
+typedef __uint_fast16_t uint_fast16_t;
+typedef __int_fast32_t int_fast32_t;
+typedef __uint_fast32_t uint_fast32_t;
+typedef __int_fast64_t int_fast64_t;
+typedef __uint_fast64_t uint_fast64_t;
+
+/* 7.18.1.4 Integer types capable of holding object pointers */
+#ifndef _INTPTR_T_DEFINED_
+#define _INTPTR_T_DEFINED_
+typedef __intptr_t intptr_t;
+#endif
+
+typedef __uintptr_t uintptr_t;
+
+/* 7.18.1.5 Greatest-width integer types */
+typedef __intmax_t intmax_t;
+typedef __uintmax_t uintmax_t;
+
+/*
+ * 7.18.2 Limits of specified-width integer types.
+ *
+ * The following object-like macros specify the minimum and maximum limits
+ * of integer types corresponding to the typedef names defined above.
+ */
+
+/* 7.18.2.1 Limits of exact-width integer types */
+#define INT8_MIN (-0x7f - 1)
+#define INT16_MIN (-0x7fff - 1)
+#define INT32_MIN (-0x7fffffff - 1)
+#define INT64_MIN (-0x7fffffffffffffffLL - 1)
+
+#define INT8_MAX 0x7f
+#define INT16_MAX 0x7fff
+#define INT32_MAX 0x7fffffff
+#define INT64_MAX 0x7fffffffffffffffLL
+
+#define UINT8_MAX 0xff
+#define UINT16_MAX 0xffff
+#define UINT32_MAX 0xffffffffU
+#define UINT64_MAX 0xffffffffffffffffULL
+
+/* 7.18.2.2 Limits of minimum-width integer types */
+#define INT_LEAST8_MIN INT8_MIN
+#define INT_LEAST16_MIN INT16_MIN
+#define INT_LEAST32_MIN INT32_MIN
+#define INT_LEAST64_MIN INT64_MIN
+
+#define INT_LEAST8_MAX INT8_MAX
+#define INT_LEAST16_MAX INT16_MAX
+#define INT_LEAST32_MAX INT32_MAX
+#define INT_LEAST64_MAX INT64_MAX
+
+#define UINT_LEAST8_MAX UINT8_MAX
+#define UINT_LEAST16_MAX UINT16_MAX
+#define UINT_LEAST32_MAX UINT32_MAX
+#define UINT_LEAST64_MAX UINT64_MAX
+
+/* 7.18.2.3 Limits of fastest minimum-width integer types */
+#define INT_FAST8_MIN __INT_FAST8_MIN
+#define INT_FAST16_MIN __INT_FAST16_MIN
+#define INT_FAST32_MIN __INT_FAST32_MIN
+#define INT_FAST64_MIN __INT_FAST64_MIN
+
+#define INT_FAST8_MAX __INT_FAST8_MAX
+#define INT_FAST16_MAX __INT_FAST16_MAX
+#define INT_FAST32_MAX __INT_FAST32_MAX
+#define INT_FAST64_MAX __INT_FAST64_MAX
+
+#define UINT_FAST8_MAX __UINT_FAST8_MAX
+#define UINT_FAST16_MAX __UINT_FAST16_MAX
+#define UINT_FAST32_MAX __UINT_FAST32_MAX
+#define UINT_FAST64_MAX __UINT_FAST64_MAX
+
+/* 7.18.2.4 Limits of integer types capable of holding object pointers */
+#ifdef __LP64__
+#define INTPTR_MIN (-0x7fffffffffffffffL - 1)
+#define INTPTR_MAX 0x7fffffffffffffffL
+#define UINTPTR_MAX 0xffffffffffffffffUL
+#else
+#define INTPTR_MIN (-0x7fffffffL - 1)
+#define INTPTR_MAX 0x7fffffffL
+#define UINTPTR_MAX 0xffffffffUL
+#endif
+
+/* 7.18.2.5 Limits of greatest-width integer types */
+#define INTMAX_MIN INT64_MIN
+#define INTMAX_MAX INT64_MAX
+#define UINTMAX_MAX UINT64_MAX
+
+/*
+ * 7.18.3 Limits of other integer types.
+ *
+ * The following object-like macros specify the minimum and maximum limits
+ * of integer types corresponding to types specified in other standard
+ * header files.
+ */
+
+/* Limits of ptrdiff_t */
+#define PTRDIFF_MIN INTPTR_MIN
+#define PTRDIFF_MAX INTPTR_MAX
+
+/* Limits of sig_atomic_t */
+#define SIG_ATOMIC_MIN INT32_MIN
+#define SIG_ATOMIC_MAX INT32_MAX
+
+/* Limit of size_t */
+#ifndef SIZE_MAX
+#define SIZE_MAX UINTPTR_MAX
+#endif
+
+/* Limits of wchar_t */
+#ifndef WCHAR_MIN
+#define WCHAR_MIN INT32_MIN
+#endif
+#ifndef WCHAR_MAX
+#define WCHAR_MAX INT32_MAX
+#endif
+
+/* Limits of wint_t */
+#define WINT_MIN INT32_MIN
+#define WINT_MAX INT32_MAX
+
+/*
+ * 7.18.4 Macros for integer constants.
+ *
+ * The following function-like macros expand to integer constants
+ * suitable for initializing objects that have integer types corresponding
+ * to types defined in <stdint.h>. The argument in any instance of
+ * these macros shall be a decimal, octal, or hexadecimal constant with
+ * a value that does not exceed the limits for the corresponding type.
+ */
+
+/* 7.18.4.1 Macros for minimum-width integer constants. */
+#define INT8_C(_c) (_c)
+#define INT16_C(_c) (_c)
+#define INT32_C(_c) (_c)
+#define INT64_C(_c) __CONCAT(_c, LL)
+
+#define UINT8_C(_c) (_c)
+#define UINT16_C(_c) (_c)
+#define UINT32_C(_c) __CONCAT(_c, U)
+#define UINT64_C(_c) __CONCAT(_c, ULL)
+
+/* 7.18.4.2 Macros for greatest-width integer constants. */
+#define INTMAX_C(_c) __CONCAT(_c, LL)
+#define UINTMAX_C(_c) __CONCAT(_c, ULL)
+
+#endif /* _SYS_STDINT_H_ */
diff --git a/sys/sys/swap.h b/sys/sys/swap.h
new file mode 100644
index 0000000..ad7b442
--- /dev/null
+++ b/sys/sys/swap.h
@@ -0,0 +1,62 @@
+/* $OpenBSD: swap.h,v 1.7 2013/09/30 12:02:30 millert Exp $ */
+/* $NetBSD: swap.h,v 1.2 1998/09/13 14:46:24 christos Exp $ */
+
+/*
+ * Copyright (c) 1995, 1996, 1998 Matthew R. Green, Tobias Weingartner
+ * 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.
+ */
+
+#ifndef _SYS_SWAP_H_
+#define _SYS_SWAP_H_
+
+#include <sys/syslimits.h>
+
+/* These structures are used to return swap information for userland */
+struct swapent {
+ dev_t se_dev; /* device id */
+ int se_flags; /* flags */
+ int se_nblks; /* total blocks */
+ int se_inuse; /* blocks in use */
+ int se_priority; /* priority of this device */
+ char se_path[PATH_MAX]; /* path name */
+};
+
+#ifdef _KERNEL
+#define NETDEV (dev_t)(-2) /* network device (for nfs swap) */
+#endif /* _KERNEL */
+
+#define SWAP_ON 1 /* begin swapping on device */
+#define SWAP_OFF 2 /* (stop swapping on device) */
+#define SWAP_NSWAP 3 /* how many swap devices ? */
+#define SWAP_STATS 4 /* get device info */
+#define SWAP_CTL 5 /* change priority on device */
+#define SWAP_DUMPDEV 7 /* use this device as dump device */
+
+#define SWF_INUSE 0x00000001 /* in use: we have swapped here */
+#define SWF_ENABLE 0x00000002 /* enabled: we can swap here */
+#define SWF_BUSY 0x00000004 /* busy: I/O happening here */
+#define SWF_FAKE 0x00000008 /* fake: still being built */
+
+#endif /* _SYS_SWAP_H_ */
diff --git a/sys/sys/syscall.h b/sys/sys/syscall.h
new file mode 100644
index 0000000..3500f7f
--- /dev/null
+++ b/sys/sys/syscall.h
@@ -0,0 +1,708 @@
+/* $OpenBSD: syscall.h,v 1.215 2020/03/18 19:35:00 anton Exp $ */
+
+/*
+ * System call numbers.
+ *
+ * DO NOT EDIT-- this file is automatically generated.
+ * created from; OpenBSD: syscalls.master,v 1.207 2020/03/18 19:33:36 anton Exp
+ */
+
+/* syscall: "syscall" ret: "int" args: "int" "..." */
+#define SYS_syscall 0
+
+/* syscall: "exit" ret: "void" args: "int" */
+#define SYS_exit 1
+
+/* syscall: "fork" ret: "int" args: */
+#define SYS_fork 2
+
+/* syscall: "read" ret: "ssize_t" args: "int" "void *" "size_t" */
+#define SYS_read 3
+
+/* syscall: "write" ret: "ssize_t" args: "int" "const void *" "size_t" */
+#define SYS_write 4
+
+/* syscall: "open" ret: "int" args: "const char *" "int" "..." */
+#define SYS_open 5
+
+/* syscall: "close" ret: "int" args: "int" */
+#define SYS_close 6
+
+/* syscall: "getentropy" ret: "int" args: "void *" "size_t" */
+#define SYS_getentropy 7
+
+/* syscall: "__tfork" ret: "int" args: "const struct __tfork *" "size_t" */
+#define SYS___tfork 8
+
+/* syscall: "link" ret: "int" args: "const char *" "const char *" */
+#define SYS_link 9
+
+/* syscall: "unlink" ret: "int" args: "const char *" */
+#define SYS_unlink 10
+
+/* syscall: "wait4" ret: "pid_t" args: "pid_t" "int *" "int" "struct rusage *" */
+#define SYS_wait4 11
+
+/* syscall: "chdir" ret: "int" args: "const char *" */
+#define SYS_chdir 12
+
+/* syscall: "fchdir" ret: "int" args: "int" */
+#define SYS_fchdir 13
+
+/* syscall: "mknod" ret: "int" args: "const char *" "mode_t" "dev_t" */
+#define SYS_mknod 14
+
+/* syscall: "chmod" ret: "int" args: "const char *" "mode_t" */
+#define SYS_chmod 15
+
+/* syscall: "chown" ret: "int" args: "const char *" "uid_t" "gid_t" */
+#define SYS_chown 16
+
+/* syscall: "break" ret: "int" args: "char *" */
+#define SYS_break 17
+
+/* syscall: "getdtablecount" ret: "int" args: */
+#define SYS_getdtablecount 18
+
+/* syscall: "getrusage" ret: "int" args: "int" "struct rusage *" */
+#define SYS_getrusage 19
+
+/* syscall: "getpid" ret: "pid_t" args: */
+#define SYS_getpid 20
+
+/* syscall: "mount" ret: "int" args: "const char *" "const char *" "int" "void *" */
+#define SYS_mount 21
+
+/* syscall: "unmount" ret: "int" args: "const char *" "int" */
+#define SYS_unmount 22
+
+/* syscall: "setuid" ret: "int" args: "uid_t" */
+#define SYS_setuid 23
+
+/* syscall: "getuid" ret: "uid_t" args: */
+#define SYS_getuid 24
+
+/* syscall: "geteuid" ret: "uid_t" args: */
+#define SYS_geteuid 25
+
+/* syscall: "ptrace" ret: "int" args: "int" "pid_t" "caddr_t" "int" */
+#define SYS_ptrace 26
+
+/* syscall: "recvmsg" ret: "ssize_t" args: "int" "struct msghdr *" "int" */
+#define SYS_recvmsg 27
+
+/* syscall: "sendmsg" ret: "ssize_t" args: "int" "const struct msghdr *" "int" */
+#define SYS_sendmsg 28
+
+/* syscall: "recvfrom" ret: "ssize_t" args: "int" "void *" "size_t" "int" "struct sockaddr *" "socklen_t *" */
+#define SYS_recvfrom 29
+
+/* syscall: "accept" ret: "int" args: "int" "struct sockaddr *" "socklen_t *" */
+#define SYS_accept 30
+
+/* syscall: "getpeername" ret: "int" args: "int" "struct sockaddr *" "socklen_t *" */
+#define SYS_getpeername 31
+
+/* syscall: "getsockname" ret: "int" args: "int" "struct sockaddr *" "socklen_t *" */
+#define SYS_getsockname 32
+
+/* syscall: "access" ret: "int" args: "const char *" "int" */
+#define SYS_access 33
+
+/* syscall: "chflags" ret: "int" args: "const char *" "u_int" */
+#define SYS_chflags 34
+
+/* syscall: "fchflags" ret: "int" args: "int" "u_int" */
+#define SYS_fchflags 35
+
+/* syscall: "sync" ret: "void" args: */
+#define SYS_sync 36
+
+/* syscall: "msyscall" ret: "int" args: "void *" "size_t" */
+#define SYS_msyscall 37
+
+/* syscall: "stat" ret: "int" args: "const char *" "struct stat *" */
+#define SYS_stat 38
+
+/* syscall: "getppid" ret: "pid_t" args: */
+#define SYS_getppid 39
+
+/* syscall: "lstat" ret: "int" args: "const char *" "struct stat *" */
+#define SYS_lstat 40
+
+/* syscall: "dup" ret: "int" args: "int" */
+#define SYS_dup 41
+
+/* syscall: "fstatat" ret: "int" args: "int" "const char *" "struct stat *" "int" */
+#define SYS_fstatat 42
+
+/* syscall: "getegid" ret: "gid_t" args: */
+#define SYS_getegid 43
+
+/* syscall: "profil" ret: "int" args: "caddr_t" "size_t" "u_long" "u_int" */
+#define SYS_profil 44
+
+/* syscall: "ktrace" ret: "int" args: "const char *" "int" "int" "pid_t" */
+#define SYS_ktrace 45
+
+/* syscall: "sigaction" ret: "int" args: "int" "const struct sigaction *" "struct sigaction *" */
+#define SYS_sigaction 46
+
+/* syscall: "getgid" ret: "gid_t" args: */
+#define SYS_getgid 47
+
+/* syscall: "sigprocmask" ret: "int" args: "int" "sigset_t" */
+#define SYS_sigprocmask 48
+
+ /* 49 is obsolete ogetlogin */
+/* syscall: "setlogin" ret: "int" args: "const char *" */
+#define SYS_setlogin 50
+
+/* syscall: "acct" ret: "int" args: "const char *" */
+#define SYS_acct 51
+
+/* syscall: "sigpending" ret: "int" args: */
+#define SYS_sigpending 52
+
+/* syscall: "fstat" ret: "int" args: "int" "struct stat *" */
+#define SYS_fstat 53
+
+/* syscall: "ioctl" ret: "int" args: "int" "u_long" "..." */
+#define SYS_ioctl 54
+
+/* syscall: "reboot" ret: "int" args: "int" */
+#define SYS_reboot 55
+
+/* syscall: "revoke" ret: "int" args: "const char *" */
+#define SYS_revoke 56
+
+/* syscall: "symlink" ret: "int" args: "const char *" "const char *" */
+#define SYS_symlink 57
+
+/* syscall: "readlink" ret: "ssize_t" args: "const char *" "char *" "size_t" */
+#define SYS_readlink 58
+
+/* syscall: "execve" ret: "int" args: "const char *" "char *const *" "char *const *" */
+#define SYS_execve 59
+
+/* syscall: "umask" ret: "mode_t" args: "mode_t" */
+#define SYS_umask 60
+
+/* syscall: "chroot" ret: "int" args: "const char *" */
+#define SYS_chroot 61
+
+/* syscall: "getfsstat" ret: "int" args: "struct statfs *" "size_t" "int" */
+#define SYS_getfsstat 62
+
+/* syscall: "statfs" ret: "int" args: "const char *" "struct statfs *" */
+#define SYS_statfs 63
+
+/* syscall: "fstatfs" ret: "int" args: "int" "struct statfs *" */
+#define SYS_fstatfs 64
+
+/* syscall: "fhstatfs" ret: "int" args: "const fhandle_t *" "struct statfs *" */
+#define SYS_fhstatfs 65
+
+/* syscall: "vfork" ret: "int" args: */
+#define SYS_vfork 66
+
+/* syscall: "gettimeofday" ret: "int" args: "struct timeval *" "struct timezone *" */
+#define SYS_gettimeofday 67
+
+/* syscall: "settimeofday" ret: "int" args: "const struct timeval *" "const struct timezone *" */
+#define SYS_settimeofday 68
+
+/* syscall: "setitimer" ret: "int" args: "int" "const struct itimerval *" "struct itimerval *" */
+#define SYS_setitimer 69
+
+/* syscall: "getitimer" ret: "int" args: "int" "struct itimerval *" */
+#define SYS_getitimer 70
+
+/* syscall: "select" ret: "int" args: "int" "fd_set *" "fd_set *" "fd_set *" "struct timeval *" */
+#define SYS_select 71
+
+/* syscall: "kevent" ret: "int" args: "int" "const struct kevent *" "int" "struct kevent *" "int" "const struct timespec *" */
+#define SYS_kevent 72
+
+/* syscall: "munmap" ret: "int" args: "void *" "size_t" */
+#define SYS_munmap 73
+
+/* syscall: "mprotect" ret: "int" args: "void *" "size_t" "int" */
+#define SYS_mprotect 74
+
+/* syscall: "madvise" ret: "int" args: "void *" "size_t" "int" */
+#define SYS_madvise 75
+
+/* syscall: "utimes" ret: "int" args: "const char *" "const struct timeval *" */
+#define SYS_utimes 76
+
+/* syscall: "futimes" ret: "int" args: "int" "const struct timeval *" */
+#define SYS_futimes 77
+
+/* syscall: "getgroups" ret: "int" args: "int" "gid_t *" */
+#define SYS_getgroups 79
+
+/* syscall: "setgroups" ret: "int" args: "int" "const gid_t *" */
+#define SYS_setgroups 80
+
+/* syscall: "getpgrp" ret: "int" args: */
+#define SYS_getpgrp 81
+
+/* syscall: "setpgid" ret: "int" args: "pid_t" "pid_t" */
+#define SYS_setpgid 82
+
+/* syscall: "futex" ret: "int" args: "uint32_t *" "int" "int" "const struct timespec *" "uint32_t *" */
+#define SYS_futex 83
+
+/* syscall: "utimensat" ret: "int" args: "int" "const char *" "const struct timespec *" "int" */
+#define SYS_utimensat 84
+
+/* syscall: "futimens" ret: "int" args: "int" "const struct timespec *" */
+#define SYS_futimens 85
+
+/* syscall: "kbind" ret: "int" args: "const struct __kbind *" "size_t" "int64_t" */
+#define SYS_kbind 86
+
+/* syscall: "clock_gettime" ret: "int" args: "clockid_t" "struct timespec *" */
+#define SYS_clock_gettime 87
+
+/* syscall: "clock_settime" ret: "int" args: "clockid_t" "const struct timespec *" */
+#define SYS_clock_settime 88
+
+/* syscall: "clock_getres" ret: "int" args: "clockid_t" "struct timespec *" */
+#define SYS_clock_getres 89
+
+/* syscall: "dup2" ret: "int" args: "int" "int" */
+#define SYS_dup2 90
+
+/* syscall: "nanosleep" ret: "int" args: "const struct timespec *" "struct timespec *" */
+#define SYS_nanosleep 91
+
+/* syscall: "fcntl" ret: "int" args: "int" "int" "..." */
+#define SYS_fcntl 92
+
+/* syscall: "accept4" ret: "int" args: "int" "struct sockaddr *" "socklen_t *" "int" */
+#define SYS_accept4 93
+
+/* syscall: "__thrsleep" ret: "int" args: "const volatile void *" "clockid_t" "const struct timespec *" "void *" "const int *" */
+#define SYS___thrsleep 94
+
+/* syscall: "fsync" ret: "int" args: "int" */
+#define SYS_fsync 95
+
+/* syscall: "setpriority" ret: "int" args: "int" "id_t" "int" */
+#define SYS_setpriority 96
+
+/* syscall: "socket" ret: "int" args: "int" "int" "int" */
+#define SYS_socket 97
+
+/* syscall: "connect" ret: "int" args: "int" "const struct sockaddr *" "socklen_t" */
+#define SYS_connect 98
+
+/* syscall: "getdents" ret: "int" args: "int" "void *" "size_t" */
+#define SYS_getdents 99
+
+/* syscall: "getpriority" ret: "int" args: "int" "id_t" */
+#define SYS_getpriority 100
+
+/* syscall: "pipe2" ret: "int" args: "int *" "int" */
+#define SYS_pipe2 101
+
+/* syscall: "dup3" ret: "int" args: "int" "int" "int" */
+#define SYS_dup3 102
+
+/* syscall: "sigreturn" ret: "int" args: "struct sigcontext *" */
+#define SYS_sigreturn 103
+
+/* syscall: "bind" ret: "int" args: "int" "const struct sockaddr *" "socklen_t" */
+#define SYS_bind 104
+
+/* syscall: "setsockopt" ret: "int" args: "int" "int" "int" "const void *" "socklen_t" */
+#define SYS_setsockopt 105
+
+/* syscall: "listen" ret: "int" args: "int" "int" */
+#define SYS_listen 106
+
+/* syscall: "chflagsat" ret: "int" args: "int" "const char *" "u_int" "int" */
+#define SYS_chflagsat 107
+
+/* syscall: "pledge" ret: "int" args: "const char *" "const char *" */
+#define SYS_pledge 108
+
+/* syscall: "ppoll" ret: "int" args: "struct pollfd *" "u_int" "const struct timespec *" "const sigset_t *" */
+#define SYS_ppoll 109
+
+/* syscall: "pselect" ret: "int" args: "int" "fd_set *" "fd_set *" "fd_set *" "const struct timespec *" "const sigset_t *" */
+#define SYS_pselect 110
+
+/* syscall: "sigsuspend" ret: "int" args: "int" */
+#define SYS_sigsuspend 111
+
+/* syscall: "sendsyslog" ret: "int" args: "const char *" "size_t" "int" */
+#define SYS_sendsyslog 112
+
+/* syscall: "unveil" ret: "int" args: "const char *" "const char *" */
+#define SYS_unveil 114
+
+/* syscall: "__realpath" ret: "int" args: "const char *" "char *" */
+#define SYS___realpath 115
+
+ /* 116 is obsolete t32_gettimeofday */
+ /* 117 is obsolete t32_getrusage */
+/* syscall: "getsockopt" ret: "int" args: "int" "int" "int" "void *" "socklen_t *" */
+#define SYS_getsockopt 118
+
+/* syscall: "thrkill" ret: "int" args: "pid_t" "int" "void *" */
+#define SYS_thrkill 119
+
+/* syscall: "readv" ret: "ssize_t" args: "int" "const struct iovec *" "int" */
+#define SYS_readv 120
+
+/* syscall: "writev" ret: "ssize_t" args: "int" "const struct iovec *" "int" */
+#define SYS_writev 121
+
+/* syscall: "kill" ret: "int" args: "int" "int" */
+#define SYS_kill 122
+
+/* syscall: "fchown" ret: "int" args: "int" "uid_t" "gid_t" */
+#define SYS_fchown 123
+
+/* syscall: "fchmod" ret: "int" args: "int" "mode_t" */
+#define SYS_fchmod 124
+
+ /* 125 is obsolete orecvfrom */
+/* syscall: "setreuid" ret: "int" args: "uid_t" "uid_t" */
+#define SYS_setreuid 126
+
+/* syscall: "setregid" ret: "int" args: "gid_t" "gid_t" */
+#define SYS_setregid 127
+
+/* syscall: "rename" ret: "int" args: "const char *" "const char *" */
+#define SYS_rename 128
+
+ /* 129 is obsolete otruncate */
+ /* 130 is obsolete oftruncate */
+/* syscall: "flock" ret: "int" args: "int" "int" */
+#define SYS_flock 131
+
+/* syscall: "mkfifo" ret: "int" args: "const char *" "mode_t" */
+#define SYS_mkfifo 132
+
+/* syscall: "sendto" ret: "ssize_t" args: "int" "const void *" "size_t" "int" "const struct sockaddr *" "socklen_t" */
+#define SYS_sendto 133
+
+/* syscall: "shutdown" ret: "int" args: "int" "int" */
+#define SYS_shutdown 134
+
+/* syscall: "socketpair" ret: "int" args: "int" "int" "int" "int *" */
+#define SYS_socketpair 135
+
+/* syscall: "mkdir" ret: "int" args: "const char *" "mode_t" */
+#define SYS_mkdir 136
+
+/* syscall: "rmdir" ret: "int" args: "const char *" */
+#define SYS_rmdir 137
+
+ /* 138 is obsolete t32_utimes */
+ /* 139 is obsolete 4.2 sigreturn */
+/* syscall: "adjtime" ret: "int" args: "const struct timeval *" "struct timeval *" */
+#define SYS_adjtime 140
+
+/* syscall: "getlogin_r" ret: "int" args: "char *" "u_int" */
+#define SYS_getlogin_r 141
+
+ /* 142 is obsolete ogethostid */
+ /* 143 is obsolete osethostid */
+ /* 144 is obsolete ogetrlimit */
+ /* 145 is obsolete osetrlimit */
+ /* 146 is obsolete okillpg */
+/* syscall: "setsid" ret: "int" args: */
+#define SYS_setsid 147
+
+/* syscall: "quotactl" ret: "int" args: "const char *" "int" "int" "char *" */
+#define SYS_quotactl 148
+
+ /* 149 is obsolete oquota */
+ /* 150 is obsolete ogetsockname */
+/* syscall: "nfssvc" ret: "int" args: "int" "void *" */
+#define SYS_nfssvc 155
+
+ /* 156 is obsolete ogetdirentries */
+ /* 157 is obsolete statfs25 */
+ /* 158 is obsolete fstatfs25 */
+/* syscall: "getfh" ret: "int" args: "const char *" "fhandle_t *" */
+#define SYS_getfh 161
+
+ /* 162 is obsolete ogetdomainname */
+ /* 163 is obsolete osetdomainname */
+/* syscall: "__tmpfd" ret: "int" args: "int" */
+#define SYS___tmpfd 164
+
+/* syscall: "sysarch" ret: "int" args: "int" "void *" */
+#define SYS_sysarch 165
+
+ /* 169 is obsolete semsys10 */
+ /* 170 is obsolete msgsys10 */
+ /* 171 is obsolete shmsys10 */
+/* syscall: "pread" ret: "ssize_t" args: "int" "void *" "size_t" "int" "off_t" */
+#define SYS_pread 173
+
+/* syscall: "pwrite" ret: "ssize_t" args: "int" "const void *" "size_t" "int" "off_t" */
+#define SYS_pwrite 174
+
+/* syscall: "setgid" ret: "int" args: "gid_t" */
+#define SYS_setgid 181
+
+/* syscall: "setegid" ret: "int" args: "gid_t" */
+#define SYS_setegid 182
+
+/* syscall: "seteuid" ret: "int" args: "uid_t" */
+#define SYS_seteuid 183
+
+ /* 184 is obsolete lfs_bmapv */
+ /* 185 is obsolete lfs_markv */
+ /* 186 is obsolete lfs_segclean */
+ /* 187 is obsolete lfs_segwait */
+ /* 188 is obsolete stat35 */
+ /* 189 is obsolete fstat35 */
+ /* 190 is obsolete lstat35 */
+/* syscall: "pathconf" ret: "long" args: "const char *" "int" */
+#define SYS_pathconf 191
+
+/* syscall: "fpathconf" ret: "long" args: "int" "int" */
+#define SYS_fpathconf 192
+
+/* syscall: "swapctl" ret: "int" args: "int" "const void *" "int" */
+#define SYS_swapctl 193
+
+/* syscall: "getrlimit" ret: "int" args: "int" "struct rlimit *" */
+#define SYS_getrlimit 194
+
+/* syscall: "setrlimit" ret: "int" args: "int" "const struct rlimit *" */
+#define SYS_setrlimit 195
+
+ /* 196 is obsolete ogetdirentries48 */
+/* syscall: "mmap" ret: "void *" args: "void *" "size_t" "int" "int" "int" "long" "off_t" */
+#define SYS_mmap 197
+
+/* syscall: "__syscall" ret: "quad_t" args: "quad_t" "..." */
+#define SYS___syscall 198
+
+/* syscall: "lseek" ret: "off_t" args: "int" "int" "off_t" "int" */
+#define SYS_lseek 199
+
+/* syscall: "truncate" ret: "int" args: "const char *" "int" "off_t" */
+#define SYS_truncate 200
+
+/* syscall: "ftruncate" ret: "int" args: "int" "int" "off_t" */
+#define SYS_ftruncate 201
+
+/* syscall: "sysctl" ret: "int" args: "const int *" "u_int" "void *" "size_t *" "void *" "size_t" */
+#define SYS_sysctl 202
+
+/* syscall: "mlock" ret: "int" args: "const void *" "size_t" */
+#define SYS_mlock 203
+
+/* syscall: "munlock" ret: "int" args: "const void *" "size_t" */
+#define SYS_munlock 204
+
+ /* 206 is obsolete t32_futimes */
+/* syscall: "getpgid" ret: "pid_t" args: "pid_t" */
+#define SYS_getpgid 207
+
+ /* 208 is obsolete nnpfspioctl */
+/* syscall: "utrace" ret: "int" args: "const char *" "const void *" "size_t" */
+#define SYS_utrace 209
+
+/* syscall: "semget" ret: "int" args: "key_t" "int" "int" */
+#define SYS_semget 221
+
+ /* 222 is obsolete semop35 */
+ /* 223 is obsolete semconfig35 */
+/* syscall: "msgget" ret: "int" args: "key_t" "int" */
+#define SYS_msgget 225
+
+/* syscall: "msgsnd" ret: "int" args: "int" "const void *" "size_t" "int" */
+#define SYS_msgsnd 226
+
+/* syscall: "msgrcv" ret: "int" args: "int" "void *" "size_t" "long" "int" */
+#define SYS_msgrcv 227
+
+/* syscall: "shmat" ret: "void *" args: "int" "const void *" "int" */
+#define SYS_shmat 228
+
+/* syscall: "shmdt" ret: "int" args: "const void *" */
+#define SYS_shmdt 230
+
+ /* 231 is obsolete shmget35 */
+ /* 232 is obsolete t32_clock_gettime */
+ /* 233 is obsolete t32_clock_settime */
+ /* 234 is obsolete t32_clock_getres */
+ /* 240 is obsolete t32_nanosleep */
+/* syscall: "minherit" ret: "int" args: "void *" "size_t" "int" */
+#define SYS_minherit 250
+
+ /* 251 is obsolete rfork */
+/* syscall: "poll" ret: "int" args: "struct pollfd *" "u_int" "int" */
+#define SYS_poll 252
+
+/* syscall: "issetugid" ret: "int" args: */
+#define SYS_issetugid 253
+
+/* syscall: "lchown" ret: "int" args: "const char *" "uid_t" "gid_t" */
+#define SYS_lchown 254
+
+/* syscall: "getsid" ret: "pid_t" args: "pid_t" */
+#define SYS_getsid 255
+
+/* syscall: "msync" ret: "int" args: "void *" "size_t" "int" */
+#define SYS_msync 256
+
+ /* 257 is obsolete semctl35 */
+ /* 258 is obsolete shmctl35 */
+ /* 259 is obsolete msgctl35 */
+/* syscall: "pipe" ret: "int" args: "int *" */
+#define SYS_pipe 263
+
+/* syscall: "fhopen" ret: "int" args: "const fhandle_t *" "int" */
+#define SYS_fhopen 264
+
+/* syscall: "preadv" ret: "ssize_t" args: "int" "const struct iovec *" "int" "int" "off_t" */
+#define SYS_preadv 267
+
+/* syscall: "pwritev" ret: "ssize_t" args: "int" "const struct iovec *" "int" "int" "off_t" */
+#define SYS_pwritev 268
+
+/* syscall: "kqueue" ret: "int" args: */
+#define SYS_kqueue 269
+
+ /* 270 is obsolete t32_kevent */
+/* syscall: "mlockall" ret: "int" args: "int" */
+#define SYS_mlockall 271
+
+/* syscall: "munlockall" ret: "int" args: */
+#define SYS_munlockall 272
+
+/* syscall: "getresuid" ret: "int" args: "uid_t *" "uid_t *" "uid_t *" */
+#define SYS_getresuid 281
+
+/* syscall: "setresuid" ret: "int" args: "uid_t" "uid_t" "uid_t" */
+#define SYS_setresuid 282
+
+/* syscall: "getresgid" ret: "int" args: "gid_t *" "gid_t *" "gid_t *" */
+#define SYS_getresgid 283
+
+/* syscall: "setresgid" ret: "int" args: "gid_t" "gid_t" "gid_t" */
+#define SYS_setresgid 284
+
+ /* 285 is obsolete sys_omquery */
+/* syscall: "mquery" ret: "void *" args: "void *" "size_t" "int" "int" "int" "long" "off_t" */
+#define SYS_mquery 286
+
+/* syscall: "closefrom" ret: "int" args: "int" */
+#define SYS_closefrom 287
+
+/* syscall: "sigaltstack" ret: "int" args: "const struct sigaltstack *" "struct sigaltstack *" */
+#define SYS_sigaltstack 288
+
+/* syscall: "shmget" ret: "int" args: "key_t" "size_t" "int" */
+#define SYS_shmget 289
+
+/* syscall: "semop" ret: "int" args: "int" "struct sembuf *" "size_t" */
+#define SYS_semop 290
+
+ /* 291 is obsolete t32_stat */
+ /* 292 is obsolete t32_fstat */
+ /* 293 is obsolete t32_lstat */
+/* syscall: "fhstat" ret: "int" args: "const fhandle_t *" "struct stat *" */
+#define SYS_fhstat 294
+
+/* syscall: "__semctl" ret: "int" args: "int" "int" "int" "union semun *" */
+#define SYS___semctl 295
+
+/* syscall: "shmctl" ret: "int" args: "int" "int" "struct shmid_ds *" */
+#define SYS_shmctl 296
+
+/* syscall: "msgctl" ret: "int" args: "int" "int" "struct msqid_ds *" */
+#define SYS_msgctl 297
+
+/* syscall: "sched_yield" ret: "int" args: */
+#define SYS_sched_yield 298
+
+/* syscall: "getthrid" ret: "pid_t" args: */
+#define SYS_getthrid 299
+
+ /* 300 is obsolete t32___thrsleep */
+/* syscall: "__thrwakeup" ret: "int" args: "const volatile void *" "int" */
+#define SYS___thrwakeup 301
+
+/* syscall: "__threxit" ret: "void" args: "pid_t *" */
+#define SYS___threxit 302
+
+/* syscall: "__thrsigdivert" ret: "int" args: "sigset_t" "siginfo_t *" "const struct timespec *" */
+#define SYS___thrsigdivert 303
+
+/* syscall: "__getcwd" ret: "int" args: "char *" "size_t" */
+#define SYS___getcwd 304
+
+/* syscall: "adjfreq" ret: "int" args: "const int64_t *" "int64_t *" */
+#define SYS_adjfreq 305
+
+ /* 306 is obsolete getfsstat53 */
+ /* 307 is obsolete statfs53 */
+ /* 308 is obsolete fstatfs53 */
+ /* 309 is obsolete fhstatfs53 */
+/* syscall: "setrtable" ret: "int" args: "int" */
+#define SYS_setrtable 310
+
+/* syscall: "getrtable" ret: "int" args: */
+#define SYS_getrtable 311
+
+ /* 312 is obsolete t32_getdirentries */
+/* syscall: "faccessat" ret: "int" args: "int" "const char *" "int" "int" */
+#define SYS_faccessat 313
+
+/* syscall: "fchmodat" ret: "int" args: "int" "const char *" "mode_t" "int" */
+#define SYS_fchmodat 314
+
+/* syscall: "fchownat" ret: "int" args: "int" "const char *" "uid_t" "gid_t" "int" */
+#define SYS_fchownat 315
+
+ /* 316 is obsolete t32_fstatat */
+/* syscall: "linkat" ret: "int" args: "int" "const char *" "int" "const char *" "int" */
+#define SYS_linkat 317
+
+/* syscall: "mkdirat" ret: "int" args: "int" "const char *" "mode_t" */
+#define SYS_mkdirat 318
+
+/* syscall: "mkfifoat" ret: "int" args: "int" "const char *" "mode_t" */
+#define SYS_mkfifoat 319
+
+/* syscall: "mknodat" ret: "int" args: "int" "const char *" "mode_t" "dev_t" */
+#define SYS_mknodat 320
+
+/* syscall: "openat" ret: "int" args: "int" "const char *" "int" "..." */
+#define SYS_openat 321
+
+/* syscall: "readlinkat" ret: "ssize_t" args: "int" "const char *" "char *" "size_t" */
+#define SYS_readlinkat 322
+
+/* syscall: "renameat" ret: "int" args: "int" "const char *" "int" "const char *" */
+#define SYS_renameat 323
+
+/* syscall: "symlinkat" ret: "int" args: "const char *" "int" "const char *" */
+#define SYS_symlinkat 324
+
+/* syscall: "unlinkat" ret: "int" args: "int" "const char *" "int" */
+#define SYS_unlinkat 325
+
+ /* 326 is obsolete t32_utimensat */
+ /* 327 is obsolete t32_futimens */
+ /* 328 is obsolete __tfork51 */
+/* syscall: "__set_tcb" ret: "void" args: "void *" */
+#define SYS___set_tcb 329
+
+/* syscall: "__get_tcb" ret: "void *" args: */
+#define SYS___get_tcb 330
+
+#define SYS_MAXSYSCALL 331
diff --git a/sys/sys/syscall_mi.h b/sys/sys/syscall_mi.h
new file mode 100644
index 0000000..76f34e0
--- /dev/null
+++ b/sys/sys/syscall_mi.h
@@ -0,0 +1,191 @@
+/* $OpenBSD: syscall_mi.h,v 1.25 2020/01/21 16:16:23 mpi Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 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.
+ * 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.
+ *
+ * @(#)kern_xxx.c 8.2 (Berkeley) 11/14/93
+ */
+
+#include <sys/param.h>
+#include <sys/pledge.h>
+#include <sys/tracepoint.h>
+#include <uvm/uvm_extern.h>
+
+#ifdef KTRACE
+#include <sys/ktrace.h>
+#endif
+
+#include "dt.h"
+#if NDT > 0
+#include <dev/dt/dtvar.h>
+#endif
+
+
+/*
+ * The MD setup for a system call has been done; here's the MI part.
+ */
+static inline int
+mi_syscall(struct proc *p, register_t code, const struct sysent *callp,
+ register_t *argp, register_t retval[2])
+{
+ uint64_t tval;
+ int lock = !(callp->sy_flags & SY_NOLOCK);
+ int error, pledged;
+
+ /* refresh the thread's cache of the process's creds */
+ refreshcreds(p);
+
+#ifdef SYSCALL_DEBUG
+ KERNEL_LOCK();
+ scdebug_call(p, code, argp);
+ KERNEL_UNLOCK();
+#endif
+ TRACEPOINT(raw_syscalls, sys_enter, code, NULL);
+#if NDT > 0
+ DT_ENTER(syscall, code, callp->sy_argsize, argp);
+#endif
+#ifdef KTRACE
+ if (KTRPOINT(p, KTR_SYSCALL)) {
+ KERNEL_LOCK();
+ ktrsyscall(p, code, callp->sy_argsize, argp);
+ KERNEL_UNLOCK();
+ }
+#endif
+
+ /* SP must be within MAP_STACK space */
+ if (!uvm_map_inentry(p, &p->p_spinentry, PROC_STACK(p),
+ "[%s]%d/%d sp=%lx inside %lx-%lx: not MAP_STACK\n",
+ uvm_map_inentry_sp, p->p_vmspace->vm_map.sserial))
+ return (EPERM);
+
+ /* PC must be in un-writeable permitted text (sigtramp, libc, ld.so) */
+ if (!uvm_map_inentry(p, &p->p_pcinentry, PROC_PC(p),
+ "[%s]%d/%d pc=%lx inside %lx-%lx: bogus syscall\n",
+ uvm_map_inentry_pc, p->p_vmspace->vm_map.wserial))
+ return (EPERM);
+
+ if (lock)
+ KERNEL_LOCK();
+ pledged = (p->p_p->ps_flags & PS_PLEDGE);
+ if (pledged && (error = pledge_syscall(p, code, &tval))) {
+ if (!lock)
+ KERNEL_LOCK();
+ error = pledge_fail(p, error, tval);
+ KERNEL_UNLOCK();
+ return (error);
+ }
+ error = (*callp->sy_call)(p, argp, retval);
+ if (lock)
+ KERNEL_UNLOCK();
+
+ return (error);
+}
+
+/*
+ * Finish MI stuff on return, after the registers have been set
+ */
+static inline void
+mi_syscall_return(struct proc *p, register_t code, int error,
+ const register_t retval[2])
+{
+#ifdef SYSCALL_DEBUG
+ KERNEL_LOCK();
+ scdebug_ret(p, code, error, retval);
+ KERNEL_UNLOCK();
+#endif
+#if NDT > 0
+ DT_LEAVE(syscall, code, error, retval[0], retval[1]);
+#endif
+ TRACEPOINT(raw_syscalls, sys_exit, code, NULL);
+
+ userret(p);
+
+#ifdef KTRACE
+ if (KTRPOINT(p, KTR_SYSRET)) {
+ KERNEL_LOCK();
+ ktrsysret(p, code, error, retval);
+ KERNEL_UNLOCK();
+ }
+#endif
+}
+
+/*
+ * Finish MI stuff for a new process/thread to return
+ */
+static inline void
+mi_child_return(struct proc *p)
+{
+#if defined(SYSCALL_DEBUG) || defined(KTRACE) || NDT > 0
+ int code = (p->p_flag & P_THREAD) ? SYS___tfork :
+ (p->p_p->ps_flags & PS_PPWAIT) ? SYS_vfork : SYS_fork;
+ const register_t child_retval[2] = { 0, 1 };
+#endif
+
+ TRACEPOINT(sched, on__cpu, NULL);
+
+#ifdef SYSCALL_DEBUG
+ KERNEL_LOCK();
+ scdebug_ret(p, code, 0, child_retval);
+ KERNEL_UNLOCK();
+#endif
+#if NDT > 0
+ DT_LEAVE(syscall, code, 0, child_retval[0], child_retval[1]);
+#endif
+ TRACEPOINT(raw_syscalls, sys_exit, code, NULL);
+
+ userret(p);
+
+#ifdef KTRACE
+ if (KTRPOINT(p, KTR_SYSRET)) {
+ KERNEL_LOCK();
+ ktrsysret(p, code, 0, child_retval);
+ KERNEL_UNLOCK();
+ }
+#endif
+}
+
+/*
+ * Do the specific processing necessary for an AST
+ */
+static inline void
+mi_ast(struct proc *p, int resched)
+{
+ if (p->p_flag & P_OWEUPC) {
+ KERNEL_LOCK();
+ ADDUPROF(p);
+ KERNEL_UNLOCK();
+ }
+ if (resched)
+ preempt();
+
+ /*
+ * XXX could move call to userret() here, but
+ * hppa calls ast() in syscall return and sh calls
+ * it after userret()
+ */
+}
diff --git a/sys/sys/syscallargs.h b/sys/sys/syscallargs.h
new file mode 100644
index 0000000..2209606
--- /dev/null
+++ b/sys/sys/syscallargs.h
@@ -0,0 +1,1362 @@
+/* $OpenBSD: syscallargs.h,v 1.218 2020/03/18 19:35:00 anton Exp $ */
+
+/*
+ * System call argument lists.
+ *
+ * DO NOT EDIT-- this file is automatically generated.
+ * created from; OpenBSD: syscalls.master,v 1.207 2020/03/18 19:33:36 anton Exp
+ */
+
+#ifdef syscallarg
+#undef syscallarg
+#endif
+
+#define syscallarg(x) \
+ union { \
+ register_t pad; \
+ struct { x datum; } le; \
+ struct { \
+ int8_t pad[ (sizeof (register_t) < sizeof (x)) \
+ ? 0 \
+ : sizeof (register_t) - sizeof (x)]; \
+ x datum; \
+ } be; \
+ }
+
+struct sys_exit_args {
+ syscallarg(int) rval;
+};
+
+struct sys_read_args {
+ syscallarg(int) fd;
+ syscallarg(void *) buf;
+ syscallarg(size_t) nbyte;
+};
+
+struct sys_write_args {
+ syscallarg(int) fd;
+ syscallarg(const void *) buf;
+ syscallarg(size_t) nbyte;
+};
+
+struct sys_open_args {
+ syscallarg(const char *) path;
+ syscallarg(int) flags;
+ syscallarg(mode_t) mode;
+};
+
+struct sys_close_args {
+ syscallarg(int) fd;
+};
+
+struct sys_getentropy_args {
+ syscallarg(void *) buf;
+ syscallarg(size_t) nbyte;
+};
+
+struct sys___tfork_args {
+ syscallarg(const struct __tfork *) param;
+ syscallarg(size_t) psize;
+};
+
+struct sys_link_args {
+ syscallarg(const char *) path;
+ syscallarg(const char *) link;
+};
+
+struct sys_unlink_args {
+ syscallarg(const char *) path;
+};
+
+struct sys_wait4_args {
+ syscallarg(pid_t) pid;
+ syscallarg(int *) status;
+ syscallarg(int) options;
+ syscallarg(struct rusage *) rusage;
+};
+
+struct sys_chdir_args {
+ syscallarg(const char *) path;
+};
+
+struct sys_fchdir_args {
+ syscallarg(int) fd;
+};
+
+struct sys_mknod_args {
+ syscallarg(const char *) path;
+ syscallarg(mode_t) mode;
+ syscallarg(dev_t) dev;
+};
+
+struct sys_chmod_args {
+ syscallarg(const char *) path;
+ syscallarg(mode_t) mode;
+};
+
+struct sys_chown_args {
+ syscallarg(const char *) path;
+ syscallarg(uid_t) uid;
+ syscallarg(gid_t) gid;
+};
+
+struct sys_obreak_args {
+ syscallarg(char *) nsize;
+};
+
+struct sys_getrusage_args {
+ syscallarg(int) who;
+ syscallarg(struct rusage *) rusage;
+};
+
+struct sys_mount_args {
+ syscallarg(const char *) type;
+ syscallarg(const char *) path;
+ syscallarg(int) flags;
+ syscallarg(void *) data;
+};
+
+struct sys_unmount_args {
+ syscallarg(const char *) path;
+ syscallarg(int) flags;
+};
+
+struct sys_setuid_args {
+ syscallarg(uid_t) uid;
+};
+
+struct sys_ptrace_args {
+ syscallarg(int) req;
+ syscallarg(pid_t) pid;
+ syscallarg(caddr_t) addr;
+ syscallarg(int) data;
+};
+
+struct sys_recvmsg_args {
+ syscallarg(int) s;
+ syscallarg(struct msghdr *) msg;
+ syscallarg(int) flags;
+};
+
+struct sys_sendmsg_args {
+ syscallarg(int) s;
+ syscallarg(const struct msghdr *) msg;
+ syscallarg(int) flags;
+};
+
+struct sys_recvfrom_args {
+ syscallarg(int) s;
+ syscallarg(void *) buf;
+ syscallarg(size_t) len;
+ syscallarg(int) flags;
+ syscallarg(struct sockaddr *) from;
+ syscallarg(socklen_t *) fromlenaddr;
+};
+
+struct sys_accept_args {
+ syscallarg(int) s;
+ syscallarg(struct sockaddr *) name;
+ syscallarg(socklen_t *) anamelen;
+};
+
+struct sys_getpeername_args {
+ syscallarg(int) fdes;
+ syscallarg(struct sockaddr *) asa;
+ syscallarg(socklen_t *) alen;
+};
+
+struct sys_getsockname_args {
+ syscallarg(int) fdes;
+ syscallarg(struct sockaddr *) asa;
+ syscallarg(socklen_t *) alen;
+};
+
+struct sys_access_args {
+ syscallarg(const char *) path;
+ syscallarg(int) amode;
+};
+
+struct sys_chflags_args {
+ syscallarg(const char *) path;
+ syscallarg(u_int) flags;
+};
+
+struct sys_fchflags_args {
+ syscallarg(int) fd;
+ syscallarg(u_int) flags;
+};
+
+struct sys_msyscall_args {
+ syscallarg(void *) addr;
+ syscallarg(size_t) len;
+};
+
+struct sys_stat_args {
+ syscallarg(const char *) path;
+ syscallarg(struct stat *) ub;
+};
+
+struct sys_lstat_args {
+ syscallarg(const char *) path;
+ syscallarg(struct stat *) ub;
+};
+
+struct sys_dup_args {
+ syscallarg(int) fd;
+};
+
+struct sys_fstatat_args {
+ syscallarg(int) fd;
+ syscallarg(const char *) path;
+ syscallarg(struct stat *) buf;
+ syscallarg(int) flag;
+};
+
+struct sys_profil_args {
+ syscallarg(caddr_t) samples;
+ syscallarg(size_t) size;
+ syscallarg(u_long) offset;
+ syscallarg(u_int) scale;
+};
+
+struct sys_ktrace_args {
+ syscallarg(const char *) fname;
+ syscallarg(int) ops;
+ syscallarg(int) facs;
+ syscallarg(pid_t) pid;
+};
+
+struct sys_sigaction_args {
+ syscallarg(int) signum;
+ syscallarg(const struct sigaction *) nsa;
+ syscallarg(struct sigaction *) osa;
+};
+
+struct sys_sigprocmask_args {
+ syscallarg(int) how;
+ syscallarg(sigset_t) mask;
+};
+
+struct sys_setlogin_args {
+ syscallarg(const char *) namebuf;
+};
+
+struct sys_acct_args {
+ syscallarg(const char *) path;
+};
+
+struct sys_fstat_args {
+ syscallarg(int) fd;
+ syscallarg(struct stat *) sb;
+};
+
+struct sys_ioctl_args {
+ syscallarg(int) fd;
+ syscallarg(u_long) com;
+ syscallarg(void *) data;
+};
+
+struct sys_reboot_args {
+ syscallarg(int) opt;
+};
+
+struct sys_revoke_args {
+ syscallarg(const char *) path;
+};
+
+struct sys_symlink_args {
+ syscallarg(const char *) path;
+ syscallarg(const char *) link;
+};
+
+struct sys_readlink_args {
+ syscallarg(const char *) path;
+ syscallarg(char *) buf;
+ syscallarg(size_t) count;
+};
+
+struct sys_execve_args {
+ syscallarg(const char *) path;
+ syscallarg(char *const *) argp;
+ syscallarg(char *const *) envp;
+};
+
+struct sys_umask_args {
+ syscallarg(mode_t) newmask;
+};
+
+struct sys_chroot_args {
+ syscallarg(const char *) path;
+};
+
+struct sys_getfsstat_args {
+ syscallarg(struct statfs *) buf;
+ syscallarg(size_t) bufsize;
+ syscallarg(int) flags;
+};
+
+struct sys_statfs_args {
+ syscallarg(const char *) path;
+ syscallarg(struct statfs *) buf;
+};
+
+struct sys_fstatfs_args {
+ syscallarg(int) fd;
+ syscallarg(struct statfs *) buf;
+};
+
+struct sys_fhstatfs_args {
+ syscallarg(const fhandle_t *) fhp;
+ syscallarg(struct statfs *) buf;
+};
+
+struct sys_gettimeofday_args {
+ syscallarg(struct timeval *) tp;
+ syscallarg(struct timezone *) tzp;
+};
+
+struct sys_settimeofday_args {
+ syscallarg(const struct timeval *) tv;
+ syscallarg(const struct timezone *) tzp;
+};
+
+struct sys_setitimer_args {
+ syscallarg(int) which;
+ syscallarg(const struct itimerval *) itv;
+ syscallarg(struct itimerval *) oitv;
+};
+
+struct sys_getitimer_args {
+ syscallarg(int) which;
+ syscallarg(struct itimerval *) itv;
+};
+
+struct sys_select_args {
+ syscallarg(int) nd;
+ syscallarg(fd_set *) in;
+ syscallarg(fd_set *) ou;
+ syscallarg(fd_set *) ex;
+ syscallarg(struct timeval *) tv;
+};
+
+struct sys_kevent_args {
+ syscallarg(int) fd;
+ syscallarg(const struct kevent *) changelist;
+ syscallarg(int) nchanges;
+ syscallarg(struct kevent *) eventlist;
+ syscallarg(int) nevents;
+ syscallarg(const struct timespec *) timeout;
+};
+
+struct sys_munmap_args {
+ syscallarg(void *) addr;
+ syscallarg(size_t) len;
+};
+
+struct sys_mprotect_args {
+ syscallarg(void *) addr;
+ syscallarg(size_t) len;
+ syscallarg(int) prot;
+};
+
+struct sys_madvise_args {
+ syscallarg(void *) addr;
+ syscallarg(size_t) len;
+ syscallarg(int) behav;
+};
+
+struct sys_utimes_args {
+ syscallarg(const char *) path;
+ syscallarg(const struct timeval *) tptr;
+};
+
+struct sys_futimes_args {
+ syscallarg(int) fd;
+ syscallarg(const struct timeval *) tptr;
+};
+
+struct sys_getgroups_args {
+ syscallarg(int) gidsetsize;
+ syscallarg(gid_t *) gidset;
+};
+
+struct sys_setgroups_args {
+ syscallarg(int) gidsetsize;
+ syscallarg(const gid_t *) gidset;
+};
+
+struct sys_setpgid_args {
+ syscallarg(pid_t) pid;
+ syscallarg(pid_t) pgid;
+};
+
+struct sys_futex_args {
+ syscallarg(uint32_t *) f;
+ syscallarg(int) op;
+ syscallarg(int) val;
+ syscallarg(const struct timespec *) timeout;
+ syscallarg(uint32_t *) g;
+};
+
+struct sys_utimensat_args {
+ syscallarg(int) fd;
+ syscallarg(const char *) path;
+ syscallarg(const struct timespec *) times;
+ syscallarg(int) flag;
+};
+
+struct sys_futimens_args {
+ syscallarg(int) fd;
+ syscallarg(const struct timespec *) times;
+};
+
+struct sys_kbind_args {
+ syscallarg(const struct __kbind *) param;
+ syscallarg(size_t) psize;
+ syscallarg(int64_t) proc_cookie;
+};
+
+struct sys_clock_gettime_args {
+ syscallarg(clockid_t) clock_id;
+ syscallarg(struct timespec *) tp;
+};
+
+struct sys_clock_settime_args {
+ syscallarg(clockid_t) clock_id;
+ syscallarg(const struct timespec *) tp;
+};
+
+struct sys_clock_getres_args {
+ syscallarg(clockid_t) clock_id;
+ syscallarg(struct timespec *) tp;
+};
+
+struct sys_dup2_args {
+ syscallarg(int) from;
+ syscallarg(int) to;
+};
+
+struct sys_nanosleep_args {
+ syscallarg(const struct timespec *) rqtp;
+ syscallarg(struct timespec *) rmtp;
+};
+
+struct sys_fcntl_args {
+ syscallarg(int) fd;
+ syscallarg(int) cmd;
+ syscallarg(void *) arg;
+};
+
+struct sys_accept4_args {
+ syscallarg(int) s;
+ syscallarg(struct sockaddr *) name;
+ syscallarg(socklen_t *) anamelen;
+ syscallarg(int) flags;
+};
+
+struct sys___thrsleep_args {
+ syscallarg(const volatile void *) ident;
+ syscallarg(clockid_t) clock_id;
+ syscallarg(const struct timespec *) tp;
+ syscallarg(void *) lock;
+ syscallarg(const int *) abort;
+};
+
+struct sys_fsync_args {
+ syscallarg(int) fd;
+};
+
+struct sys_setpriority_args {
+ syscallarg(int) which;
+ syscallarg(id_t) who;
+ syscallarg(int) prio;
+};
+
+struct sys_socket_args {
+ syscallarg(int) domain;
+ syscallarg(int) type;
+ syscallarg(int) protocol;
+};
+
+struct sys_connect_args {
+ syscallarg(int) s;
+ syscallarg(const struct sockaddr *) name;
+ syscallarg(socklen_t) namelen;
+};
+
+struct sys_getdents_args {
+ syscallarg(int) fd;
+ syscallarg(void *) buf;
+ syscallarg(size_t) buflen;
+};
+
+struct sys_getpriority_args {
+ syscallarg(int) which;
+ syscallarg(id_t) who;
+};
+
+struct sys_pipe2_args {
+ syscallarg(int *) fdp;
+ syscallarg(int) flags;
+};
+
+struct sys_dup3_args {
+ syscallarg(int) from;
+ syscallarg(int) to;
+ syscallarg(int) flags;
+};
+
+struct sys_sigreturn_args {
+ syscallarg(struct sigcontext *) sigcntxp;
+};
+
+struct sys_bind_args {
+ syscallarg(int) s;
+ syscallarg(const struct sockaddr *) name;
+ syscallarg(socklen_t) namelen;
+};
+
+struct sys_setsockopt_args {
+ syscallarg(int) s;
+ syscallarg(int) level;
+ syscallarg(int) name;
+ syscallarg(const void *) val;
+ syscallarg(socklen_t) valsize;
+};
+
+struct sys_listen_args {
+ syscallarg(int) s;
+ syscallarg(int) backlog;
+};
+
+struct sys_chflagsat_args {
+ syscallarg(int) fd;
+ syscallarg(const char *) path;
+ syscallarg(u_int) flags;
+ syscallarg(int) atflags;
+};
+
+struct sys_pledge_args {
+ syscallarg(const char *) promises;
+ syscallarg(const char *) execpromises;
+};
+
+struct sys_ppoll_args {
+ syscallarg(struct pollfd *) fds;
+ syscallarg(u_int) nfds;
+ syscallarg(const struct timespec *) ts;
+ syscallarg(const sigset_t *) mask;
+};
+
+struct sys_pselect_args {
+ syscallarg(int) nd;
+ syscallarg(fd_set *) in;
+ syscallarg(fd_set *) ou;
+ syscallarg(fd_set *) ex;
+ syscallarg(const struct timespec *) ts;
+ syscallarg(const sigset_t *) mask;
+};
+
+struct sys_sigsuspend_args {
+ syscallarg(int) mask;
+};
+
+struct sys_sendsyslog_args {
+ syscallarg(const char *) buf;
+ syscallarg(size_t) nbyte;
+ syscallarg(int) flags;
+};
+
+struct sys_unveil_args {
+ syscallarg(const char *) path;
+ syscallarg(const char *) permissions;
+};
+
+struct sys___realpath_args {
+ syscallarg(const char *) pathname;
+ syscallarg(char *) resolved;
+};
+
+struct sys_getsockopt_args {
+ syscallarg(int) s;
+ syscallarg(int) level;
+ syscallarg(int) name;
+ syscallarg(void *) val;
+ syscallarg(socklen_t *) avalsize;
+};
+
+struct sys_thrkill_args {
+ syscallarg(pid_t) tid;
+ syscallarg(int) signum;
+ syscallarg(void *) tcb;
+};
+
+struct sys_readv_args {
+ syscallarg(int) fd;
+ syscallarg(const struct iovec *) iovp;
+ syscallarg(int) iovcnt;
+};
+
+struct sys_writev_args {
+ syscallarg(int) fd;
+ syscallarg(const struct iovec *) iovp;
+ syscallarg(int) iovcnt;
+};
+
+struct sys_kill_args {
+ syscallarg(int) pid;
+ syscallarg(int) signum;
+};
+
+struct sys_fchown_args {
+ syscallarg(int) fd;
+ syscallarg(uid_t) uid;
+ syscallarg(gid_t) gid;
+};
+
+struct sys_fchmod_args {
+ syscallarg(int) fd;
+ syscallarg(mode_t) mode;
+};
+
+struct sys_setreuid_args {
+ syscallarg(uid_t) ruid;
+ syscallarg(uid_t) euid;
+};
+
+struct sys_setregid_args {
+ syscallarg(gid_t) rgid;
+ syscallarg(gid_t) egid;
+};
+
+struct sys_rename_args {
+ syscallarg(const char *) from;
+ syscallarg(const char *) to;
+};
+
+struct sys_flock_args {
+ syscallarg(int) fd;
+ syscallarg(int) how;
+};
+
+struct sys_mkfifo_args {
+ syscallarg(const char *) path;
+ syscallarg(mode_t) mode;
+};
+
+struct sys_sendto_args {
+ syscallarg(int) s;
+ syscallarg(const void *) buf;
+ syscallarg(size_t) len;
+ syscallarg(int) flags;
+ syscallarg(const struct sockaddr *) to;
+ syscallarg(socklen_t) tolen;
+};
+
+struct sys_shutdown_args {
+ syscallarg(int) s;
+ syscallarg(int) how;
+};
+
+struct sys_socketpair_args {
+ syscallarg(int) domain;
+ syscallarg(int) type;
+ syscallarg(int) protocol;
+ syscallarg(int *) rsv;
+};
+
+struct sys_mkdir_args {
+ syscallarg(const char *) path;
+ syscallarg(mode_t) mode;
+};
+
+struct sys_rmdir_args {
+ syscallarg(const char *) path;
+};
+
+struct sys_adjtime_args {
+ syscallarg(const struct timeval *) delta;
+ syscallarg(struct timeval *) olddelta;
+};
+
+struct sys_getlogin_r_args {
+ syscallarg(char *) namebuf;
+ syscallarg(u_int) namelen;
+};
+
+struct sys_quotactl_args {
+ syscallarg(const char *) path;
+ syscallarg(int) cmd;
+ syscallarg(int) uid;
+ syscallarg(char *) arg;
+};
+
+struct sys_nfssvc_args {
+ syscallarg(int) flag;
+ syscallarg(void *) argp;
+};
+
+struct sys_getfh_args {
+ syscallarg(const char *) fname;
+ syscallarg(fhandle_t *) fhp;
+};
+
+struct sys___tmpfd_args {
+ syscallarg(int) flags;
+};
+
+struct sys_sysarch_args {
+ syscallarg(int) op;
+ syscallarg(void *) parms;
+};
+
+struct sys_pread_args {
+ syscallarg(int) fd;
+ syscallarg(void *) buf;
+ syscallarg(size_t) nbyte;
+ syscallarg(int) pad;
+ syscallarg(off_t) offset;
+};
+
+struct sys_pwrite_args {
+ syscallarg(int) fd;
+ syscallarg(const void *) buf;
+ syscallarg(size_t) nbyte;
+ syscallarg(int) pad;
+ syscallarg(off_t) offset;
+};
+
+struct sys_setgid_args {
+ syscallarg(gid_t) gid;
+};
+
+struct sys_setegid_args {
+ syscallarg(gid_t) egid;
+};
+
+struct sys_seteuid_args {
+ syscallarg(uid_t) euid;
+};
+
+struct sys_pathconf_args {
+ syscallarg(const char *) path;
+ syscallarg(int) name;
+};
+
+struct sys_fpathconf_args {
+ syscallarg(int) fd;
+ syscallarg(int) name;
+};
+
+struct sys_swapctl_args {
+ syscallarg(int) cmd;
+ syscallarg(const void *) arg;
+ syscallarg(int) misc;
+};
+
+struct sys_getrlimit_args {
+ syscallarg(int) which;
+ syscallarg(struct rlimit *) rlp;
+};
+
+struct sys_setrlimit_args {
+ syscallarg(int) which;
+ syscallarg(const struct rlimit *) rlp;
+};
+
+struct sys_mmap_args {
+ syscallarg(void *) addr;
+ syscallarg(size_t) len;
+ syscallarg(int) prot;
+ syscallarg(int) flags;
+ syscallarg(int) fd;
+ syscallarg(long) pad;
+ syscallarg(off_t) pos;
+};
+
+struct sys_lseek_args {
+ syscallarg(int) fd;
+ syscallarg(int) pad;
+ syscallarg(off_t) offset;
+ syscallarg(int) whence;
+};
+
+struct sys_truncate_args {
+ syscallarg(const char *) path;
+ syscallarg(int) pad;
+ syscallarg(off_t) length;
+};
+
+struct sys_ftruncate_args {
+ syscallarg(int) fd;
+ syscallarg(int) pad;
+ syscallarg(off_t) length;
+};
+
+struct sys_sysctl_args {
+ syscallarg(const int *) name;
+ syscallarg(u_int) namelen;
+ syscallarg(void *) old;
+ syscallarg(size_t *) oldlenp;
+ syscallarg(void *) new;
+ syscallarg(size_t) newlen;
+};
+
+struct sys_mlock_args {
+ syscallarg(const void *) addr;
+ syscallarg(size_t) len;
+};
+
+struct sys_munlock_args {
+ syscallarg(const void *) addr;
+ syscallarg(size_t) len;
+};
+
+struct sys_getpgid_args {
+ syscallarg(pid_t) pid;
+};
+
+struct sys_utrace_args {
+ syscallarg(const char *) label;
+ syscallarg(const void *) addr;
+ syscallarg(size_t) len;
+};
+
+struct sys_semget_args {
+ syscallarg(key_t) key;
+ syscallarg(int) nsems;
+ syscallarg(int) semflg;
+};
+
+struct sys_msgget_args {
+ syscallarg(key_t) key;
+ syscallarg(int) msgflg;
+};
+
+struct sys_msgsnd_args {
+ syscallarg(int) msqid;
+ syscallarg(const void *) msgp;
+ syscallarg(size_t) msgsz;
+ syscallarg(int) msgflg;
+};
+
+struct sys_msgrcv_args {
+ syscallarg(int) msqid;
+ syscallarg(void *) msgp;
+ syscallarg(size_t) msgsz;
+ syscallarg(long) msgtyp;
+ syscallarg(int) msgflg;
+};
+
+struct sys_shmat_args {
+ syscallarg(int) shmid;
+ syscallarg(const void *) shmaddr;
+ syscallarg(int) shmflg;
+};
+
+struct sys_shmdt_args {
+ syscallarg(const void *) shmaddr;
+};
+
+struct sys_minherit_args {
+ syscallarg(void *) addr;
+ syscallarg(size_t) len;
+ syscallarg(int) inherit;
+};
+
+struct sys_poll_args {
+ syscallarg(struct pollfd *) fds;
+ syscallarg(u_int) nfds;
+ syscallarg(int) timeout;
+};
+
+struct sys_lchown_args {
+ syscallarg(const char *) path;
+ syscallarg(uid_t) uid;
+ syscallarg(gid_t) gid;
+};
+
+struct sys_getsid_args {
+ syscallarg(pid_t) pid;
+};
+
+struct sys_msync_args {
+ syscallarg(void *) addr;
+ syscallarg(size_t) len;
+ syscallarg(int) flags;
+};
+
+struct sys_pipe_args {
+ syscallarg(int *) fdp;
+};
+
+struct sys_fhopen_args {
+ syscallarg(const fhandle_t *) fhp;
+ syscallarg(int) flags;
+};
+
+struct sys_preadv_args {
+ syscallarg(int) fd;
+ syscallarg(const struct iovec *) iovp;
+ syscallarg(int) iovcnt;
+ syscallarg(int) pad;
+ syscallarg(off_t) offset;
+};
+
+struct sys_pwritev_args {
+ syscallarg(int) fd;
+ syscallarg(const struct iovec *) iovp;
+ syscallarg(int) iovcnt;
+ syscallarg(int) pad;
+ syscallarg(off_t) offset;
+};
+
+struct sys_mlockall_args {
+ syscallarg(int) flags;
+};
+
+struct sys_getresuid_args {
+ syscallarg(uid_t *) ruid;
+ syscallarg(uid_t *) euid;
+ syscallarg(uid_t *) suid;
+};
+
+struct sys_setresuid_args {
+ syscallarg(uid_t) ruid;
+ syscallarg(uid_t) euid;
+ syscallarg(uid_t) suid;
+};
+
+struct sys_getresgid_args {
+ syscallarg(gid_t *) rgid;
+ syscallarg(gid_t *) egid;
+ syscallarg(gid_t *) sgid;
+};
+
+struct sys_setresgid_args {
+ syscallarg(gid_t) rgid;
+ syscallarg(gid_t) egid;
+ syscallarg(gid_t) sgid;
+};
+
+struct sys_mquery_args {
+ syscallarg(void *) addr;
+ syscallarg(size_t) len;
+ syscallarg(int) prot;
+ syscallarg(int) flags;
+ syscallarg(int) fd;
+ syscallarg(long) pad;
+ syscallarg(off_t) pos;
+};
+
+struct sys_closefrom_args {
+ syscallarg(int) fd;
+};
+
+struct sys_sigaltstack_args {
+ syscallarg(const struct sigaltstack *) nss;
+ syscallarg(struct sigaltstack *) oss;
+};
+
+struct sys_shmget_args {
+ syscallarg(key_t) key;
+ syscallarg(size_t) size;
+ syscallarg(int) shmflg;
+};
+
+struct sys_semop_args {
+ syscallarg(int) semid;
+ syscallarg(struct sembuf *) sops;
+ syscallarg(size_t) nsops;
+};
+
+struct sys_fhstat_args {
+ syscallarg(const fhandle_t *) fhp;
+ syscallarg(struct stat *) sb;
+};
+
+struct sys___semctl_args {
+ syscallarg(int) semid;
+ syscallarg(int) semnum;
+ syscallarg(int) cmd;
+ syscallarg(union semun *) arg;
+};
+
+struct sys_shmctl_args {
+ syscallarg(int) shmid;
+ syscallarg(int) cmd;
+ syscallarg(struct shmid_ds *) buf;
+};
+
+struct sys_msgctl_args {
+ syscallarg(int) msqid;
+ syscallarg(int) cmd;
+ syscallarg(struct msqid_ds *) buf;
+};
+
+struct sys___thrwakeup_args {
+ syscallarg(const volatile void *) ident;
+ syscallarg(int) n;
+};
+
+struct sys___threxit_args {
+ syscallarg(pid_t *) notdead;
+};
+
+struct sys___thrsigdivert_args {
+ syscallarg(sigset_t) sigmask;
+ syscallarg(siginfo_t *) info;
+ syscallarg(const struct timespec *) timeout;
+};
+
+struct sys___getcwd_args {
+ syscallarg(char *) buf;
+ syscallarg(size_t) len;
+};
+
+struct sys_adjfreq_args {
+ syscallarg(const int64_t *) freq;
+ syscallarg(int64_t *) oldfreq;
+};
+
+struct sys_setrtable_args {
+ syscallarg(int) rtableid;
+};
+
+struct sys_faccessat_args {
+ syscallarg(int) fd;
+ syscallarg(const char *) path;
+ syscallarg(int) amode;
+ syscallarg(int) flag;
+};
+
+struct sys_fchmodat_args {
+ syscallarg(int) fd;
+ syscallarg(const char *) path;
+ syscallarg(mode_t) mode;
+ syscallarg(int) flag;
+};
+
+struct sys_fchownat_args {
+ syscallarg(int) fd;
+ syscallarg(const char *) path;
+ syscallarg(uid_t) uid;
+ syscallarg(gid_t) gid;
+ syscallarg(int) flag;
+};
+
+struct sys_linkat_args {
+ syscallarg(int) fd1;
+ syscallarg(const char *) path1;
+ syscallarg(int) fd2;
+ syscallarg(const char *) path2;
+ syscallarg(int) flag;
+};
+
+struct sys_mkdirat_args {
+ syscallarg(int) fd;
+ syscallarg(const char *) path;
+ syscallarg(mode_t) mode;
+};
+
+struct sys_mkfifoat_args {
+ syscallarg(int) fd;
+ syscallarg(const char *) path;
+ syscallarg(mode_t) mode;
+};
+
+struct sys_mknodat_args {
+ syscallarg(int) fd;
+ syscallarg(const char *) path;
+ syscallarg(mode_t) mode;
+ syscallarg(dev_t) dev;
+};
+
+struct sys_openat_args {
+ syscallarg(int) fd;
+ syscallarg(const char *) path;
+ syscallarg(int) flags;
+ syscallarg(mode_t) mode;
+};
+
+struct sys_readlinkat_args {
+ syscallarg(int) fd;
+ syscallarg(const char *) path;
+ syscallarg(char *) buf;
+ syscallarg(size_t) count;
+};
+
+struct sys_renameat_args {
+ syscallarg(int) fromfd;
+ syscallarg(const char *) from;
+ syscallarg(int) tofd;
+ syscallarg(const char *) to;
+};
+
+struct sys_symlinkat_args {
+ syscallarg(const char *) path;
+ syscallarg(int) fd;
+ syscallarg(const char *) link;
+};
+
+struct sys_unlinkat_args {
+ syscallarg(int) fd;
+ syscallarg(const char *) path;
+ syscallarg(int) flag;
+};
+
+struct sys___set_tcb_args {
+ syscallarg(void *) tcb;
+};
+
+/*
+ * System call prototypes.
+ */
+
+int sys_exit(struct proc *, void *, register_t *);
+int sys_fork(struct proc *, void *, register_t *);
+int sys_read(struct proc *, void *, register_t *);
+int sys_write(struct proc *, void *, register_t *);
+int sys_open(struct proc *, void *, register_t *);
+int sys_close(struct proc *, void *, register_t *);
+int sys_getentropy(struct proc *, void *, register_t *);
+int sys___tfork(struct proc *, void *, register_t *);
+int sys_link(struct proc *, void *, register_t *);
+int sys_unlink(struct proc *, void *, register_t *);
+int sys_wait4(struct proc *, void *, register_t *);
+int sys_chdir(struct proc *, void *, register_t *);
+int sys_fchdir(struct proc *, void *, register_t *);
+int sys_mknod(struct proc *, void *, register_t *);
+int sys_chmod(struct proc *, void *, register_t *);
+int sys_chown(struct proc *, void *, register_t *);
+int sys_obreak(struct proc *, void *, register_t *);
+int sys_getdtablecount(struct proc *, void *, register_t *);
+int sys_getrusage(struct proc *, void *, register_t *);
+int sys_getpid(struct proc *, void *, register_t *);
+int sys_mount(struct proc *, void *, register_t *);
+int sys_unmount(struct proc *, void *, register_t *);
+int sys_setuid(struct proc *, void *, register_t *);
+int sys_getuid(struct proc *, void *, register_t *);
+int sys_geteuid(struct proc *, void *, register_t *);
+#ifdef PTRACE
+int sys_ptrace(struct proc *, void *, register_t *);
+#else
+#endif
+int sys_recvmsg(struct proc *, void *, register_t *);
+int sys_sendmsg(struct proc *, void *, register_t *);
+int sys_recvfrom(struct proc *, void *, register_t *);
+int sys_accept(struct proc *, void *, register_t *);
+int sys_getpeername(struct proc *, void *, register_t *);
+int sys_getsockname(struct proc *, void *, register_t *);
+int sys_access(struct proc *, void *, register_t *);
+int sys_chflags(struct proc *, void *, register_t *);
+int sys_fchflags(struct proc *, void *, register_t *);
+int sys_sync(struct proc *, void *, register_t *);
+int sys_msyscall(struct proc *, void *, register_t *);
+int sys_stat(struct proc *, void *, register_t *);
+int sys_getppid(struct proc *, void *, register_t *);
+int sys_lstat(struct proc *, void *, register_t *);
+int sys_dup(struct proc *, void *, register_t *);
+int sys_fstatat(struct proc *, void *, register_t *);
+int sys_getegid(struct proc *, void *, register_t *);
+int sys_profil(struct proc *, void *, register_t *);
+#ifdef KTRACE
+int sys_ktrace(struct proc *, void *, register_t *);
+#else
+#endif
+int sys_sigaction(struct proc *, void *, register_t *);
+int sys_getgid(struct proc *, void *, register_t *);
+int sys_sigprocmask(struct proc *, void *, register_t *);
+int sys_setlogin(struct proc *, void *, register_t *);
+#ifdef ACCOUNTING
+int sys_acct(struct proc *, void *, register_t *);
+#else
+#endif
+int sys_sigpending(struct proc *, void *, register_t *);
+int sys_fstat(struct proc *, void *, register_t *);
+int sys_ioctl(struct proc *, void *, register_t *);
+int sys_reboot(struct proc *, void *, register_t *);
+int sys_revoke(struct proc *, void *, register_t *);
+int sys_symlink(struct proc *, void *, register_t *);
+int sys_readlink(struct proc *, void *, register_t *);
+int sys_execve(struct proc *, void *, register_t *);
+int sys_umask(struct proc *, void *, register_t *);
+int sys_chroot(struct proc *, void *, register_t *);
+int sys_getfsstat(struct proc *, void *, register_t *);
+int sys_statfs(struct proc *, void *, register_t *);
+int sys_fstatfs(struct proc *, void *, register_t *);
+int sys_fhstatfs(struct proc *, void *, register_t *);
+int sys_vfork(struct proc *, void *, register_t *);
+int sys_gettimeofday(struct proc *, void *, register_t *);
+int sys_settimeofday(struct proc *, void *, register_t *);
+int sys_setitimer(struct proc *, void *, register_t *);
+int sys_getitimer(struct proc *, void *, register_t *);
+int sys_select(struct proc *, void *, register_t *);
+int sys_kevent(struct proc *, void *, register_t *);
+int sys_munmap(struct proc *, void *, register_t *);
+int sys_mprotect(struct proc *, void *, register_t *);
+int sys_madvise(struct proc *, void *, register_t *);
+int sys_utimes(struct proc *, void *, register_t *);
+int sys_futimes(struct proc *, void *, register_t *);
+int sys_getgroups(struct proc *, void *, register_t *);
+int sys_setgroups(struct proc *, void *, register_t *);
+int sys_getpgrp(struct proc *, void *, register_t *);
+int sys_setpgid(struct proc *, void *, register_t *);
+int sys_futex(struct proc *, void *, register_t *);
+int sys_utimensat(struct proc *, void *, register_t *);
+int sys_futimens(struct proc *, void *, register_t *);
+int sys_kbind(struct proc *, void *, register_t *);
+int sys_clock_gettime(struct proc *, void *, register_t *);
+int sys_clock_settime(struct proc *, void *, register_t *);
+int sys_clock_getres(struct proc *, void *, register_t *);
+int sys_dup2(struct proc *, void *, register_t *);
+int sys_nanosleep(struct proc *, void *, register_t *);
+int sys_fcntl(struct proc *, void *, register_t *);
+int sys_accept4(struct proc *, void *, register_t *);
+int sys___thrsleep(struct proc *, void *, register_t *);
+int sys_fsync(struct proc *, void *, register_t *);
+int sys_setpriority(struct proc *, void *, register_t *);
+int sys_socket(struct proc *, void *, register_t *);
+int sys_connect(struct proc *, void *, register_t *);
+int sys_getdents(struct proc *, void *, register_t *);
+int sys_getpriority(struct proc *, void *, register_t *);
+int sys_pipe2(struct proc *, void *, register_t *);
+int sys_dup3(struct proc *, void *, register_t *);
+int sys_sigreturn(struct proc *, void *, register_t *);
+int sys_bind(struct proc *, void *, register_t *);
+int sys_setsockopt(struct proc *, void *, register_t *);
+int sys_listen(struct proc *, void *, register_t *);
+int sys_chflagsat(struct proc *, void *, register_t *);
+int sys_pledge(struct proc *, void *, register_t *);
+int sys_ppoll(struct proc *, void *, register_t *);
+int sys_pselect(struct proc *, void *, register_t *);
+int sys_sigsuspend(struct proc *, void *, register_t *);
+int sys_sendsyslog(struct proc *, void *, register_t *);
+int sys_unveil(struct proc *, void *, register_t *);
+int sys___realpath(struct proc *, void *, register_t *);
+int sys_getsockopt(struct proc *, void *, register_t *);
+int sys_thrkill(struct proc *, void *, register_t *);
+int sys_readv(struct proc *, void *, register_t *);
+int sys_writev(struct proc *, void *, register_t *);
+int sys_kill(struct proc *, void *, register_t *);
+int sys_fchown(struct proc *, void *, register_t *);
+int sys_fchmod(struct proc *, void *, register_t *);
+int sys_setreuid(struct proc *, void *, register_t *);
+int sys_setregid(struct proc *, void *, register_t *);
+int sys_rename(struct proc *, void *, register_t *);
+int sys_flock(struct proc *, void *, register_t *);
+int sys_mkfifo(struct proc *, void *, register_t *);
+int sys_sendto(struct proc *, void *, register_t *);
+int sys_shutdown(struct proc *, void *, register_t *);
+int sys_socketpair(struct proc *, void *, register_t *);
+int sys_mkdir(struct proc *, void *, register_t *);
+int sys_rmdir(struct proc *, void *, register_t *);
+int sys_adjtime(struct proc *, void *, register_t *);
+int sys_getlogin_r(struct proc *, void *, register_t *);
+int sys_setsid(struct proc *, void *, register_t *);
+int sys_quotactl(struct proc *, void *, register_t *);
+#if defined(NFSCLIENT) || defined(NFSSERVER)
+int sys_nfssvc(struct proc *, void *, register_t *);
+#else
+#endif
+int sys_getfh(struct proc *, void *, register_t *);
+int sys___tmpfd(struct proc *, void *, register_t *);
+int sys_sysarch(struct proc *, void *, register_t *);
+int sys_pread(struct proc *, void *, register_t *);
+int sys_pwrite(struct proc *, void *, register_t *);
+int sys_setgid(struct proc *, void *, register_t *);
+int sys_setegid(struct proc *, void *, register_t *);
+int sys_seteuid(struct proc *, void *, register_t *);
+int sys_pathconf(struct proc *, void *, register_t *);
+int sys_fpathconf(struct proc *, void *, register_t *);
+int sys_swapctl(struct proc *, void *, register_t *);
+int sys_getrlimit(struct proc *, void *, register_t *);
+int sys_setrlimit(struct proc *, void *, register_t *);
+int sys_mmap(struct proc *, void *, register_t *);
+int sys_lseek(struct proc *, void *, register_t *);
+int sys_truncate(struct proc *, void *, register_t *);
+int sys_ftruncate(struct proc *, void *, register_t *);
+int sys_sysctl(struct proc *, void *, register_t *);
+int sys_mlock(struct proc *, void *, register_t *);
+int sys_munlock(struct proc *, void *, register_t *);
+int sys_getpgid(struct proc *, void *, register_t *);
+int sys_utrace(struct proc *, void *, register_t *);
+#ifdef SYSVSEM
+int sys_semget(struct proc *, void *, register_t *);
+#else
+#endif
+#ifdef SYSVMSG
+int sys_msgget(struct proc *, void *, register_t *);
+int sys_msgsnd(struct proc *, void *, register_t *);
+int sys_msgrcv(struct proc *, void *, register_t *);
+#else
+#endif
+#ifdef SYSVSHM
+int sys_shmat(struct proc *, void *, register_t *);
+int sys_shmdt(struct proc *, void *, register_t *);
+#else
+#endif
+int sys_minherit(struct proc *, void *, register_t *);
+int sys_poll(struct proc *, void *, register_t *);
+int sys_issetugid(struct proc *, void *, register_t *);
+int sys_lchown(struct proc *, void *, register_t *);
+int sys_getsid(struct proc *, void *, register_t *);
+int sys_msync(struct proc *, void *, register_t *);
+int sys_pipe(struct proc *, void *, register_t *);
+int sys_fhopen(struct proc *, void *, register_t *);
+int sys_preadv(struct proc *, void *, register_t *);
+int sys_pwritev(struct proc *, void *, register_t *);
+int sys_kqueue(struct proc *, void *, register_t *);
+int sys_mlockall(struct proc *, void *, register_t *);
+int sys_munlockall(struct proc *, void *, register_t *);
+int sys_getresuid(struct proc *, void *, register_t *);
+int sys_setresuid(struct proc *, void *, register_t *);
+int sys_getresgid(struct proc *, void *, register_t *);
+int sys_setresgid(struct proc *, void *, register_t *);
+int sys_mquery(struct proc *, void *, register_t *);
+int sys_closefrom(struct proc *, void *, register_t *);
+int sys_sigaltstack(struct proc *, void *, register_t *);
+#ifdef SYSVSHM
+int sys_shmget(struct proc *, void *, register_t *);
+#else
+#endif
+#ifdef SYSVSEM
+int sys_semop(struct proc *, void *, register_t *);
+#else
+#endif
+int sys_fhstat(struct proc *, void *, register_t *);
+#ifdef SYSVSEM
+int sys___semctl(struct proc *, void *, register_t *);
+#else
+#endif
+#ifdef SYSVSHM
+int sys_shmctl(struct proc *, void *, register_t *);
+#else
+#endif
+#ifdef SYSVMSG
+int sys_msgctl(struct proc *, void *, register_t *);
+#else
+#endif
+int sys_sched_yield(struct proc *, void *, register_t *);
+int sys_getthrid(struct proc *, void *, register_t *);
+int sys___thrwakeup(struct proc *, void *, register_t *);
+int sys___threxit(struct proc *, void *, register_t *);
+int sys___thrsigdivert(struct proc *, void *, register_t *);
+int sys___getcwd(struct proc *, void *, register_t *);
+int sys_adjfreq(struct proc *, void *, register_t *);
+int sys_setrtable(struct proc *, void *, register_t *);
+int sys_getrtable(struct proc *, void *, register_t *);
+int sys_faccessat(struct proc *, void *, register_t *);
+int sys_fchmodat(struct proc *, void *, register_t *);
+int sys_fchownat(struct proc *, void *, register_t *);
+int sys_linkat(struct proc *, void *, register_t *);
+int sys_mkdirat(struct proc *, void *, register_t *);
+int sys_mkfifoat(struct proc *, void *, register_t *);
+int sys_mknodat(struct proc *, void *, register_t *);
+int sys_openat(struct proc *, void *, register_t *);
+int sys_readlinkat(struct proc *, void *, register_t *);
+int sys_renameat(struct proc *, void *, register_t *);
+int sys_symlinkat(struct proc *, void *, register_t *);
+int sys_unlinkat(struct proc *, void *, register_t *);
+int sys___set_tcb(struct proc *, void *, register_t *);
+int sys___get_tcb(struct proc *, void *, register_t *);
diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h
new file mode 100644
index 0000000..9e2fc55
--- /dev/null
+++ b/sys/sys/sysctl.h
@@ -0,0 +1,1061 @@
+/* $OpenBSD: sysctl.h,v 1.205 2020/03/13 10:07:01 anton Exp $ */
+/* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */
+
+/*
+ * Copyright (c) 1989, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Mike Karels at Berkeley Software Design, Inc.
+ *
+ * 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.
+ *
+ * @(#)sysctl.h 8.2 (Berkeley) 3/30/95
+ */
+
+#ifndef _SYS_SYSCTL_H_
+#define _SYS_SYSCTL_H_
+
+#include <uvm/uvmexp.h>
+
+/*
+ * Definitions for sysctl call. The sysctl call uses a hierarchical name
+ * for objects that can be examined or modified. The name is expressed as
+ * a sequence of integers. Like a file path name, the meaning of each
+ * component depends on its place in the hierarchy. The top-level and kern
+ * identifiers are defined here, and other identifiers are defined in the
+ * respective subsystem header files.
+ */
+
+#define CTL_MAXNAME 12 /* largest number of components supported */
+
+/*
+ * Each subsystem defined by sysctl defines a list of variables
+ * for that subsystem. Each name is either a node with further
+ * levels defined below it, or it is a leaf of some particular
+ * type given below. Each sysctl level defines a set of name/type
+ * pairs to be used by sysctl(1) in manipulating the subsystem.
+ */
+struct ctlname {
+ char *ctl_name; /* subsystem name */
+ int ctl_type; /* type of name */
+};
+#define CTLTYPE_NODE 1 /* name is a node */
+#define CTLTYPE_INT 2 /* name describes an integer */
+#define CTLTYPE_STRING 3 /* name describes a string */
+#define CTLTYPE_QUAD 4 /* name describes a 64-bit number */
+#define CTLTYPE_STRUCT 5 /* name describes a structure */
+
+/*
+ * Top-level identifiers
+ */
+#define CTL_UNSPEC 0 /* unused */
+#define CTL_KERN 1 /* "high kernel": proc, limits */
+#define CTL_VM 2 /* virtual memory */
+#define CTL_FS 3 /* file system, mount type is next */
+#define CTL_NET 4 /* network, see socket.h */
+#define CTL_DEBUG 5 /* debugging parameters */
+#define CTL_HW 6 /* generic cpu/io */
+#define CTL_MACHDEP 7 /* machine dependent */
+/*define gap 8 was CTL_USER: removed 2013-04 */
+#define CTL_DDB 9 /* DDB user interface, see db_var.h */
+#define CTL_VFS 10 /* VFS sysctl's */
+#define CTL_MAXID 11 /* number of valid top-level ids */
+
+#define CTL_NAMES { \
+ { 0, 0 }, \
+ { "kern", CTLTYPE_NODE }, \
+ { "vm", CTLTYPE_NODE }, \
+ { "fs", CTLTYPE_NODE }, \
+ { "net", CTLTYPE_NODE }, \
+ { "debug", CTLTYPE_NODE }, \
+ { "hw", CTLTYPE_NODE }, \
+ { "machdep", CTLTYPE_NODE }, \
+ { "gap", 0 }, \
+ { "ddb", CTLTYPE_NODE }, \
+ { "vfs", CTLTYPE_NODE }, \
+}
+
+/*
+ * CTL_KERN identifiers
+ */
+#define KERN_OSTYPE 1 /* string: system version */
+#define KERN_OSRELEASE 2 /* string: system release */
+#define KERN_OSREV 3 /* int: system revision */
+#define KERN_VERSION 4 /* string: compile time info */
+#define KERN_MAXVNODES 5 /* int: max vnodes */
+#define KERN_MAXPROC 6 /* int: max processes */
+#define KERN_MAXFILES 7 /* int: max open files */
+#define KERN_ARGMAX 8 /* int: max arguments to exec */
+#define KERN_SECURELVL 9 /* int: system security level */
+#define KERN_HOSTNAME 10 /* string: hostname */
+#define KERN_HOSTID 11 /* int: host identifier */
+#define KERN_CLOCKRATE 12 /* struct: struct clockinfo */
+/* was KERN_DNSJACKPORT 13 */
+/* was KERN_PROC 14 */
+/* was KERN_FILE 15 */
+#define KERN_PROF 16 /* node: kernel profiling info */
+#define KERN_POSIX1 17 /* int: POSIX.1 version */
+#define KERN_NGROUPS 18 /* int: # of supplemental group ids */
+#define KERN_JOB_CONTROL 19 /* int: is job control available */
+#define KERN_SAVED_IDS 20 /* int: saved set-user/group-ID */
+#define KERN_BOOTTIME 21 /* struct: time kernel was booted */
+#define KERN_DOMAINNAME 22 /* string: (YP) domainname */
+#define KERN_MAXPARTITIONS 23 /* int: number of partitions/disk */
+#define KERN_RAWPARTITION 24 /* int: raw partition number */
+#define KERN_MAXTHREAD 25 /* int: max threads */
+#define KERN_NTHREADS 26 /* int: number of threads */
+#define KERN_OSVERSION 27 /* string: kernel build version */
+#define KERN_SOMAXCONN 28 /* int: listen queue maximum */
+#define KERN_SOMINCONN 29 /* int: half-open controllable param */
+/* was KERN_USERMOUNT 30 */
+/* was KERN_RND 31 */
+#define KERN_NOSUIDCOREDUMP 32 /* int: no setuid coredumps ever */
+#define KERN_FSYNC 33 /* int: file synchronization support */
+#define KERN_SYSVMSG 34 /* int: SysV message queue suppoprt */
+#define KERN_SYSVSEM 35 /* int: SysV semaphore support */
+#define KERN_SYSVSHM 36 /* int: SysV shared memory support */
+/* was KERN_ARND 37 */
+#define KERN_MSGBUFSIZE 38 /* int: size of message buffer */
+#define KERN_MALLOCSTATS 39 /* node: malloc statistics */
+#define KERN_CPTIME 40 /* array: cp_time */
+#define KERN_NCHSTATS 41 /* struct: vfs cache statistics */
+#define KERN_FORKSTAT 42 /* struct: fork statistics */
+#define KERN_NSELCOLL 43 /* int: select(2) collisions */
+#define KERN_TTY 44 /* node: tty information */
+#define KERN_CCPU 45 /* int: ccpu */
+#define KERN_FSCALE 46 /* int: fscale */
+#define KERN_NPROCS 47 /* int: number of processes */
+#define KERN_MSGBUF 48 /* message buffer, KERN_MSGBUFSIZE */
+#define KERN_POOL 49 /* struct: pool information */
+#define KERN_STACKGAPRANDOM 50 /* int: stackgap_random */
+#define KERN_SYSVIPC_INFO 51 /* struct: SysV sem/shm/msg info */
+#define KERN_ALLOWKMEM 52 /* int: allowkmem */
+#define KERN_WITNESSWATCH 53 /* int: witnesswatch */
+#define KERN_SPLASSERT 54 /* int: splassert */
+#define KERN_PROC_ARGS 55 /* node: proc args and env */
+#define KERN_NFILES 56 /* int: number of open files */
+#define KERN_TTYCOUNT 57 /* int: number of tty devices */
+#define KERN_NUMVNODES 58 /* int: number of vnodes in use */
+#define KERN_MBSTAT 59 /* struct: mbuf statistics */
+#define KERN_WITNESS 60 /* node: witness */
+#define KERN_SEMINFO 61 /* struct: SysV struct seminfo */
+#define KERN_SHMINFO 62 /* struct: SysV struct shminfo */
+#define KERN_INTRCNT 63 /* node: interrupt counters */
+#define KERN_WATCHDOG 64 /* node: watchdog */
+#define KERN_ALLOWDT 65 /* int: allowdt */
+#define KERN_PROC 66 /* struct: process entries */
+#define KERN_MAXCLUSTERS 67 /* number of mclusters */
+#define KERN_EVCOUNT 68 /* node: event counters */
+#define KERN_TIMECOUNTER 69 /* node: timecounter */
+#define KERN_MAXLOCKSPERUID 70 /* int: locks per uid */
+#define KERN_CPTIME2 71 /* array: cp_time2 */
+#define KERN_CACHEPCT 72 /* buffer cache % of physmem */
+#define KERN_FILE 73 /* struct: file entries */
+#define KERN_WXABORT 74 /* int: w^x sigabrt & core */
+#define KERN_CONSDEV 75 /* dev_t: console terminal device */
+#define KERN_NETLIVELOCKS 76 /* int: number of network livelocks */
+#define KERN_POOL_DEBUG 77 /* int: enable pool_debug */
+#define KERN_PROC_CWD 78 /* node: proc cwd */
+#define KERN_PROC_NOBROADCASTKILL 79 /* node: proc no broadcast kill */
+#define KERN_PROC_VMMAP 80 /* node: proc vmmap */
+#define KERN_GLOBAL_PTRACE 81 /* allow ptrace globally */
+#define KERN_CONSBUFSIZE 82 /* int: console message buffer size */
+#define KERN_CONSBUF 83 /* console message buffer */
+#define KERN_AUDIO 84 /* struct: audio properties */
+#define KERN_CPUSTATS 85 /* struct: cpu statistics */
+#define KERN_PFSTATUS 86 /* struct: pf status and stats */
+#define KERN_TIMEOUT_STATS 87 /* struct: timeout status and stats */
+#define KERN_UTC_OFFSET 88 /* int: adjust RTC time to UTC */
+#define KERN_MAXID 89 /* number of valid kern ids */
+
+#define CTL_KERN_NAMES { \
+ { 0, 0 }, \
+ { "ostype", CTLTYPE_STRING }, \
+ { "osrelease", CTLTYPE_STRING }, \
+ { "osrevision", CTLTYPE_INT }, \
+ { "version", CTLTYPE_STRING }, \
+ { "maxvnodes", CTLTYPE_INT }, \
+ { "maxproc", CTLTYPE_INT }, \
+ { "maxfiles", CTLTYPE_INT }, \
+ { "argmax", CTLTYPE_INT }, \
+ { "securelevel", CTLTYPE_INT }, \
+ { "hostname", CTLTYPE_STRING }, \
+ { "hostid", CTLTYPE_INT }, \
+ { "clockrate", CTLTYPE_STRUCT }, \
+ { "gap", 0 }, \
+ { "gap", 0 }, \
+ { "gap", 0 }, \
+ { "profiling", CTLTYPE_NODE }, \
+ { "posix1version", CTLTYPE_INT }, \
+ { "ngroups", CTLTYPE_INT }, \
+ { "job_control", CTLTYPE_INT }, \
+ { "saved_ids", CTLTYPE_INT }, \
+ { "boottime", CTLTYPE_STRUCT }, \
+ { "domainname", CTLTYPE_STRING }, \
+ { "maxpartitions", CTLTYPE_INT }, \
+ { "rawpartition", CTLTYPE_INT }, \
+ { "maxthread", CTLTYPE_INT }, \
+ { "nthreads", CTLTYPE_INT }, \
+ { "osversion", CTLTYPE_STRING }, \
+ { "somaxconn", CTLTYPE_INT }, \
+ { "sominconn", CTLTYPE_INT }, \
+ { "gap", 0 }, \
+ { "gap", 0 }, \
+ { "nosuidcoredump", CTLTYPE_INT }, \
+ { "fsync", CTLTYPE_INT }, \
+ { "sysvmsg", CTLTYPE_INT }, \
+ { "sysvsem", CTLTYPE_INT }, \
+ { "sysvshm", CTLTYPE_INT }, \
+ { "gap", 0 }, \
+ { "msgbufsize", CTLTYPE_INT }, \
+ { "malloc", CTLTYPE_NODE }, \
+ { "cp_time", CTLTYPE_STRUCT }, \
+ { "nchstats", CTLTYPE_STRUCT }, \
+ { "forkstat", CTLTYPE_STRUCT }, \
+ { "nselcoll", CTLTYPE_INT }, \
+ { "tty", CTLTYPE_NODE }, \
+ { "ccpu", CTLTYPE_INT }, \
+ { "fscale", CTLTYPE_INT }, \
+ { "nprocs", CTLTYPE_INT }, \
+ { "msgbuf", CTLTYPE_STRUCT }, \
+ { "pool", CTLTYPE_NODE }, \
+ { "stackgap_random", CTLTYPE_INT }, \
+ { "sysvipc_info", CTLTYPE_INT }, \
+ { "allowkmem", CTLTYPE_INT }, \
+ { "witnesswatch", CTLTYPE_INT }, \
+ { "splassert", CTLTYPE_INT }, \
+ { "procargs", CTLTYPE_NODE }, \
+ { "nfiles", CTLTYPE_INT }, \
+ { "ttycount", CTLTYPE_INT }, \
+ { "numvnodes", CTLTYPE_INT }, \
+ { "mbstat", CTLTYPE_STRUCT }, \
+ { "witness", CTLTYPE_NODE }, \
+ { "seminfo", CTLTYPE_STRUCT }, \
+ { "shminfo", CTLTYPE_STRUCT }, \
+ { "intrcnt", CTLTYPE_NODE }, \
+ { "watchdog", CTLTYPE_NODE }, \
+ { "allowdt", CTLTYPE_INT }, \
+ { "proc", CTLTYPE_STRUCT }, \
+ { "maxclusters", CTLTYPE_INT }, \
+ { "evcount", CTLTYPE_NODE }, \
+ { "timecounter", CTLTYPE_NODE }, \
+ { "maxlocksperuid", CTLTYPE_INT }, \
+ { "cp_time2", CTLTYPE_STRUCT }, \
+ { "bufcachepercent", CTLTYPE_INT }, \
+ { "file", CTLTYPE_STRUCT }, \
+ { "wxabort", CTLTYPE_INT }, \
+ { "consdev", CTLTYPE_STRUCT }, \
+ { "netlivelocks", CTLTYPE_INT }, \
+ { "pool_debug", CTLTYPE_INT }, \
+ { "proc_cwd", CTLTYPE_NODE }, \
+ { "proc_nobroadcastkill", CTLTYPE_NODE }, \
+ { "proc_vmmap", CTLTYPE_NODE }, \
+ { "global_ptrace", CTLTYPE_INT }, \
+ { "consbufsize", CTLTYPE_INT }, \
+ { "consbuf", CTLTYPE_STRUCT }, \
+ { "audio", CTLTYPE_STRUCT }, \
+ { "cpustats", CTLTYPE_STRUCT }, \
+ { "pfstatus", CTLTYPE_STRUCT }, \
+ { "timeout_stats", CTLTYPE_STRUCT }, \
+ { "utc_offset", CTLTYPE_INT }, \
+}
+
+/*
+ * KERN_PROC subtypes
+ */
+#define KERN_PROC_ALL 0 /* everything but kernel threads */
+#define KERN_PROC_PID 1 /* by process id */
+#define KERN_PROC_PGRP 2 /* by process group id */
+#define KERN_PROC_SESSION 3 /* by session of pid */
+#define KERN_PROC_TTY 4 /* by controlling tty */
+#define KERN_PROC_UID 5 /* by effective uid */
+#define KERN_PROC_RUID 6 /* by real uid */
+#define KERN_PROC_KTHREAD 7 /* also return kernel threads */
+#define KERN_PROC_SHOW_THREADS 0x40000000/* also return normal threads */
+
+/*
+ * KERN_SYSVIPC_INFO subtypes
+ */
+#define KERN_SYSVIPC_MSG_INFO 1 /* msginfo and msqid_ds */
+#define KERN_SYSVIPC_SEM_INFO 2 /* seminfo and semid_ds */
+#define KERN_SYSVIPC_SHM_INFO 3 /* shminfo and shmid_ds */
+
+/*
+ * KERN_PROC_ARGS subtypes
+ */
+#define KERN_PROC_ARGV 1
+#define KERN_PROC_NARGV 2
+#define KERN_PROC_ENV 3
+#define KERN_PROC_NENV 4
+
+/*
+ * KERN_AUDIO
+ */
+#define KERN_AUDIO_RECORD 1
+#define KERN_AUDIO_MAXID 2
+
+#define CTL_KERN_AUDIO_NAMES { \
+ { 0, 0 }, \
+ { "record", CTLTYPE_INT }, \
+}
+
+/*
+ * KERN_WITNESS
+ */
+#define KERN_WITNESS_WATCH 1 /* int: operating mode */
+#define KERN_WITNESS_LOCKTRACE 2 /* int: stack trace saving mode */
+#define KERN_WITNESS_MAXID 3
+
+#define CTL_KERN_WITNESS_NAMES { \
+ { 0, 0 }, \
+ { "watch", CTLTYPE_INT }, \
+ { "locktrace", CTLTYPE_INT }, \
+}
+
+/*
+ * KERN_PROC subtype ops return arrays of relatively fixed size
+ * structures of process info. Use 8 byte alignment, and new
+ * elements should only be added to the end of this structure so
+ * binary compatibility can be preserved.
+ */
+#define KI_NGROUPS 16
+#define KI_MAXCOMLEN 24 /* extra for 8 byte alignment */
+#define KI_WMESGLEN 8
+#define KI_MAXLOGNAME 32
+#define KI_EMULNAMELEN 8
+
+#define KI_NOCPU (~(u_int64_t)0)
+
+struct kinfo_proc {
+ u_int64_t p_forw; /* PTR: linked run/sleep queue. */
+ u_int64_t p_back;
+ u_int64_t p_paddr; /* PTR: address of proc */
+
+ u_int64_t p_addr; /* PTR: Kernel virtual addr of u-area */
+ u_int64_t p_fd; /* PTR: Ptr to open files structure. */
+ u_int64_t p_stats; /* unused, always zero. */
+ u_int64_t p_limit; /* PTR: Process limits. */
+ u_int64_t p_vmspace; /* PTR: Address space. */
+ u_int64_t p_sigacts; /* PTR: Signal actions, state */
+ u_int64_t p_sess; /* PTR: session pointer */
+ u_int64_t p_tsess; /* PTR: tty session pointer */
+ u_int64_t p_ru; /* PTR: Exit information. XXX */
+
+ int32_t p_eflag; /* LONG: extra kinfo_proc flags */
+#define EPROC_CTTY 0x01 /* controlling tty vnode active */
+#define EPROC_SLEADER 0x02 /* session leader */
+#define EPROC_UNVEIL 0x04 /* has unveil settings */
+#define EPROC_LKUNVEIL 0x08 /* unveil is locked */
+ int32_t p_exitsig; /* unused, always zero. */
+ int32_t p_flag; /* INT: P_* flags. */
+
+ int32_t p_pid; /* PID_T: Process identifier. */
+ int32_t p_ppid; /* PID_T: Parent process id */
+ int32_t p_sid; /* PID_T: session id */
+ int32_t p__pgid; /* PID_T: process group id */
+ /* XXX: <sys/proc.h> hijacks p_pgid */
+ int32_t p_tpgid; /* PID_T: tty process group id */
+
+ u_int32_t p_uid; /* UID_T: effective user id */
+ u_int32_t p_ruid; /* UID_T: real user id */
+ u_int32_t p_gid; /* GID_T: effective group id */
+ u_int32_t p_rgid; /* GID_T: real group id */
+
+ u_int32_t p_groups[KI_NGROUPS]; /* GID_T: groups */
+ int16_t p_ngroups; /* SHORT: number of groups */
+
+ int16_t p_jobc; /* SHORT: job control counter */
+ u_int32_t p_tdev; /* DEV_T: controlling tty dev */
+
+ u_int32_t p_estcpu; /* U_INT: Time averaged value of p_cpticks. */
+ u_int32_t p_rtime_sec; /* STRUCT TIMEVAL: Real time. */
+ u_int32_t p_rtime_usec; /* STRUCT TIMEVAL: Real time. */
+ int32_t p_cpticks; /* INT: Ticks of cpu time. */
+ u_int32_t p_pctcpu; /* FIXPT_T: %cpu for this process */
+ u_int32_t p_swtime; /* unused, always zero */
+ u_int32_t p_slptime; /* U_INT: Time since last blocked. */
+ int32_t p_schedflags; /* INT: PSCHED_* flags */
+
+ u_int64_t p_uticks; /* U_QUAD_T: Statclock hits in user mode. */
+ u_int64_t p_sticks; /* U_QUAD_T: Statclock hits in system mode. */
+ u_int64_t p_iticks; /* U_QUAD_T: Statclock hits processing intr. */
+
+ u_int64_t p_tracep; /* PTR: Trace to vnode or file */
+ int32_t p_traceflag; /* INT: Kernel trace points. */
+
+ int32_t p_holdcnt; /* INT: If non-zero, don't swap. */
+
+ int32_t p_siglist; /* INT: Signals arrived but not delivered. */
+ u_int32_t p_sigmask; /* SIGSET_T: Current signal mask. */
+ u_int32_t p_sigignore; /* SIGSET_T: Signals being ignored. */
+ u_int32_t p_sigcatch; /* SIGSET_T: Signals being caught by user. */
+
+ int8_t p_stat; /* CHAR: S* process status (from LWP). */
+ u_int8_t p_priority; /* U_CHAR: Process priority. */
+ u_int8_t p_usrpri; /* U_CHAR: User-priority based on p_estcpu and ps_nice. */
+ u_int8_t p_nice; /* U_CHAR: Process "nice" value. */
+
+ u_int16_t p_xstat; /* U_SHORT: Exit status for wait; also stop signal. */
+ u_int16_t p_acflag; /* U_SHORT: Accounting flags. */
+
+ char p_comm[KI_MAXCOMLEN];
+
+ char p_wmesg[KI_WMESGLEN]; /* wchan message */
+ u_int64_t p_wchan; /* PTR: sleep address. */
+
+ char p_login[KI_MAXLOGNAME]; /* setlogin() name */
+
+ int32_t p_vm_rssize; /* SEGSZ_T: current resident set size in pages */
+ int32_t p_vm_tsize; /* SEGSZ_T: text size (pages) */
+ int32_t p_vm_dsize; /* SEGSZ_T: data size (pages) */
+ int32_t p_vm_ssize; /* SEGSZ_T: stack size (pages) */
+
+ int64_t p_uvalid; /* CHAR: following p_u* members from struct user are valid */
+ /* XXX 64 bits for alignment */
+ u_int64_t p_ustart_sec; /* STRUCT TIMEVAL: starting time. */
+ u_int32_t p_ustart_usec; /* STRUCT TIMEVAL: starting time. */
+
+ u_int32_t p_uutime_sec; /* STRUCT TIMEVAL: user time. */
+ u_int32_t p_uutime_usec; /* STRUCT TIMEVAL: user time. */
+ u_int32_t p_ustime_sec; /* STRUCT TIMEVAL: system time. */
+ u_int32_t p_ustime_usec; /* STRUCT TIMEVAL: system time. */
+
+ u_int64_t p_uru_maxrss; /* LONG: max resident set size. */
+ u_int64_t p_uru_ixrss; /* LONG: integral shared memory size. */
+ u_int64_t p_uru_idrss; /* LONG: integral unshared data ". */
+ u_int64_t p_uru_isrss; /* LONG: integral unshared stack ". */
+ u_int64_t p_uru_minflt; /* LONG: page reclaims. */
+ u_int64_t p_uru_majflt; /* LONG: page faults. */
+ u_int64_t p_uru_nswap; /* LONG: swaps. */
+ u_int64_t p_uru_inblock; /* LONG: block input operations. */
+ u_int64_t p_uru_oublock; /* LONG: block output operations. */
+ u_int64_t p_uru_msgsnd; /* LONG: messages sent. */
+ u_int64_t p_uru_msgrcv; /* LONG: messages received. */
+ u_int64_t p_uru_nsignals; /* LONG: signals received. */
+ u_int64_t p_uru_nvcsw; /* LONG: voluntary context switches. */
+ u_int64_t p_uru_nivcsw; /* LONG: involuntary ". */
+
+ u_int32_t p_uctime_sec; /* STRUCT TIMEVAL: child u+s time. */
+ u_int32_t p_uctime_usec; /* STRUCT TIMEVAL: child u+s time. */
+ u_int32_t p_psflags; /* UINT: PS_* flags on the process. */
+ int32_t p_spare; /* INT: unused. */
+ u_int32_t p_svuid; /* UID_T: saved user id */
+ u_int32_t p_svgid; /* GID_T: saved group id */
+ char p_emul[KI_EMULNAMELEN]; /* syscall emulation name */
+ u_int64_t p_rlim_rss_cur; /* RLIM_T: soft limit for rss */
+ u_int64_t p_cpuid; /* LONG: CPU id */
+ u_int64_t p_vm_map_size; /* VSIZE_T: virtual size */
+ int32_t p_tid; /* PID_T: Thread identifier. */
+ u_int32_t p_rtableid; /* U_INT: Routing table identifier. */
+
+ u_int64_t p_pledge; /* U_INT64_T: Pledge flags. */
+};
+
+/*
+ * VM address range entry, matching struct vm_map_entry. Useful for
+ * debuggers to know process's addresses.
+ *
+ * To iterate entries, set the last kve_end as the base address into
+ * kve_start.
+ */
+struct kinfo_vmentry {
+ u_long kve_start; /* vaddr_t */
+ u_long kve_end; /* vaddr_t */
+ u_long kve_guard; /* vsize_t */
+ u_long kve_fspace; /* vsize_t */
+ u_long kve_fspace_augment; /* vsize_t */
+ u_int64_t kve_offset; /* voff_t */
+ int kve_wired_count;
+ int kve_etype;
+ int kve_protection;
+ int kve_max_protection;
+ int kve_advice;
+ int kve_inheritance;
+ u_int8_t kve_flags; /* u_int8_t */
+};
+
+/* keep in sync with UVM_ET_* */
+#define KVE_ET_OBJ 0x00000001
+#define KVE_ET_SUBMAP 0x00000002
+#define KVE_ET_COPYONWRITE 0x00000004
+#define KVE_ET_NEEDSCOPY 0x00000008
+#define KVE_ET_HOLE 0x00000010
+#define KVE_ET_NOFAULT 0x00000020
+#define KVE_ET_STACK 0x00000040
+#define KVE_ET_WC 0x00000080
+#define KVE_ET_CONCEAL 0x00000100
+#define KVE_ET_SYSCALL 0x00000200
+#define KVE_ET_FREEMAPPED 0x00000800
+
+#define KVE_PROT_NONE 0x00000000
+#define KVE_PROT_READ 0x00000001
+#define KVE_PROT_WRITE 0x00000002
+#define KVE_PROT_EXEC 0x00000004
+
+#define KVE_ADV_NORMAL 0x00000000
+#define KVE_ADV_RANDOM 0x00000001
+#define KVE_ADV_SEQUENTIAL 0x00000002
+
+#define KVE_INH_SHARE 0x00000000
+#define KVE_INH_COPY 0x00000010
+#define KVE_INH_NONE 0x00000020
+#define KVE_INH_ZERO 0x00000030
+
+#define KVE_F_STATIC 0x01
+#define KVE_F_KMEM 0x02
+
+#if defined(_KERNEL) || defined(_LIBKVM)
+
+/*
+ * Macros for filling in the bulk of a kinfo_proc structure, used
+ * in the kernel to implement the KERN_PROC sysctl and in userland
+ * in libkvm to implement reading from kernel crashes. The macro
+ * arguments are all pointers; by name they are:
+ * kp - target kinfo_proc structure
+ * copy_str - a function or macro invoked as copy_str(dst,src,maxlen)
+ * that has strlcpy or memcpy semantics; the destination is
+ * pre-filled with zeros; for libkvm, src is a kvm address
+ * p - source struct proc
+ * pr - source struct process
+ * uc - source struct ucreds
+ * pg - source struct pgrp
+ * paddr - kernel address of the source struct proc
+ * praddr - kernel address of the source struct process
+ * sess - source struct session
+ * vm - source struct vmspace
+ * lim - source struct plimits
+ * sa - source struct sigacts
+ * There are some members that are not handled by these macros
+ * because they're too painful to generalize: p_ppid, p_sid, p_tdev,
+ * p_tpgid, p_tsess, p_vm_rssize, p_u[us]time_{sec,usec}, p_cpuid
+ */
+
+#if defined(_KERNEL)
+#define PR_LOCK(pr) mtx_enter(&(pr)->ps_mtx)
+#define PR_UNLOCK(pr) mtx_leave(&(pr)->ps_mtx)
+#else
+#define PR_LOCK(pr) /* nothing */
+#define PR_UNLOCK(pr) /* nothing */
+#endif
+
+#define _getcompatprio(_p) \
+ ((_p)->p_stat == SRUN ? (_p)->p_runpri : \
+ ((_p)->p_stat == SSLEEP) ? (_p)->p_slppri : (_p)->p_usrpri)
+
+#define PTRTOINT64(_x) ((u_int64_t)(u_long)(_x))
+
+#define FILL_KPROC(kp, copy_str, p, pr, uc, pg, paddr, \
+ praddr, sess, vm, lim, sa, isthread, show_addresses) \
+do { \
+ memset((kp), 0, sizeof(*(kp))); \
+ \
+ if (show_addresses) { \
+ (kp)->p_paddr = PTRTOINT64(paddr); \
+ (kp)->p_fd = PTRTOINT64((pr)->ps_fd); \
+ (kp)->p_limit = PTRTOINT64((pr)->ps_limit); \
+ (kp)->p_vmspace = PTRTOINT64((pr)->ps_vmspace); \
+ (kp)->p_sigacts = PTRTOINT64((pr)->ps_sigacts); \
+ (kp)->p_sess = PTRTOINT64((pg)->pg_session); \
+ (kp)->p_ru = PTRTOINT64((pr)->ps_ru); \
+ } \
+ (kp)->p_stats = 0; \
+ (kp)->p_exitsig = 0; \
+ (kp)->p_flag = (p)->p_flag; \
+ (kp)->p_pid = (pr)->ps_pid; \
+ (kp)->p_psflags = (pr)->ps_flags; \
+ \
+ (kp)->p__pgid = (pg)->pg_id; \
+ \
+ (kp)->p_uid = (uc)->cr_uid; \
+ (kp)->p_ruid = (uc)->cr_ruid; \
+ (kp)->p_gid = (uc)->cr_gid; \
+ (kp)->p_rgid = (uc)->cr_rgid; \
+ (kp)->p_svuid = (uc)->cr_svuid; \
+ (kp)->p_svgid = (uc)->cr_svgid; \
+ \
+ memcpy((kp)->p_groups, (uc)->cr_groups, \
+ MIN(sizeof((kp)->p_groups), sizeof((uc)->cr_groups))); \
+ (kp)->p_ngroups = (uc)->cr_ngroups; \
+ \
+ (kp)->p_jobc = (pg)->pg_jobc; \
+ \
+ (kp)->p_estcpu = (p)->p_estcpu; \
+ if (isthread) { \
+ (kp)->p_rtime_sec = (p)->p_tu.tu_runtime.tv_sec; \
+ (kp)->p_rtime_usec = (p)->p_tu.tu_runtime.tv_nsec/1000; \
+ (kp)->p_tid = (p)->p_tid + THREAD_PID_OFFSET; \
+ (kp)->p_uticks = (p)->p_tu.tu_uticks; \
+ (kp)->p_sticks = (p)->p_tu.tu_sticks; \
+ (kp)->p_iticks = (p)->p_tu.tu_iticks; \
+ } else { \
+ (kp)->p_rtime_sec = (pr)->ps_tu.tu_runtime.tv_sec; \
+ (kp)->p_rtime_usec = (pr)->ps_tu.tu_runtime.tv_nsec/1000; \
+ (kp)->p_tid = -1; \
+ (kp)->p_uticks = (pr)->ps_tu.tu_uticks; \
+ (kp)->p_sticks = (pr)->ps_tu.tu_sticks; \
+ (kp)->p_iticks = (pr)->ps_tu.tu_iticks; \
+ } \
+ (kp)->p_cpticks = (p)->p_cpticks; \
+ \
+ if (show_addresses) \
+ (kp)->p_tracep = PTRTOINT64((pr)->ps_tracevp); \
+ (kp)->p_traceflag = (pr)->ps_traceflag; \
+ \
+ (kp)->p_siglist = (p)->p_siglist | (pr)->ps_siglist; \
+ (kp)->p_sigmask = (p)->p_sigmask; \
+ (kp)->p_sigignore = (sa) ? (sa)->ps_sigignore : 0; \
+ (kp)->p_sigcatch = (sa) ? (sa)->ps_sigcatch : 0; \
+ \
+ (kp)->p_stat = (p)->p_stat; \
+ (kp)->p_nice = (pr)->ps_nice; \
+ \
+ (kp)->p_xstat = W_EXITCODE((pr)->ps_xexit, (pr)->ps_xsig); \
+ (kp)->p_acflag = (pr)->ps_acflag; \
+ (kp)->p_pledge = (pr)->ps_pledge; \
+ \
+ /* XXX depends on e_name being an array and not a pointer */ \
+ copy_str((kp)->p_emul, (char *)(pr)->ps_emul + \
+ offsetof(struct emul, e_name), sizeof((kp)->p_emul)); \
+ strlcpy((kp)->p_comm, (pr)->ps_comm, sizeof((kp)->p_comm)); \
+ strlcpy((kp)->p_login, (sess)->s_login, \
+ MIN(sizeof((kp)->p_login), sizeof((sess)->s_login))); \
+ \
+ if ((sess)->s_ttyvp) \
+ (kp)->p_eflag |= EPROC_CTTY; \
+ if ((pr)->ps_uvpaths) \
+ (kp)->p_eflag |= EPROC_UNVEIL; \
+ if ((pr)->ps_uvdone || \
+ (((pr)->ps_flags & PS_PLEDGE) && \
+ ((pr)->ps_pledge & PLEDGE_UNVEIL) == 0)) \
+ (kp)->p_eflag |= EPROC_LKUNVEIL; \
+ \
+ if (((pr)->ps_flags & (PS_EMBRYO | PS_ZOMBIE)) == 0) { \
+ if ((vm) != NULL) { \
+ (kp)->p_vm_rssize = (vm)->vm_rssize; \
+ (kp)->p_vm_tsize = (vm)->vm_tsize; \
+ (kp)->p_vm_dsize = (vm)->vm_dused; \
+ (kp)->p_vm_ssize = (vm)->vm_ssize; \
+ } \
+ (kp)->p_addr = PTRTOINT64((p)->p_addr); \
+ (kp)->p_stat = (p)->p_stat; \
+ (kp)->p_slptime = (p)->p_slptime; \
+ (kp)->p_holdcnt = 1; \
+ (kp)->p_priority = _getcompatprio(p); \
+ (kp)->p_usrpri = (p)->p_usrpri; \
+ if ((p)->p_wchan && (p)->p_wmesg) \
+ copy_str((kp)->p_wmesg, (p)->p_wmesg, \
+ sizeof((kp)->p_wmesg)); \
+ if (show_addresses) \
+ (kp)->p_wchan = PTRTOINT64((p)->p_wchan); \
+ } \
+ \
+ PR_LOCK(pr); \
+ if (lim) \
+ (kp)->p_rlim_rss_cur = \
+ (lim)->pl_rlimit[RLIMIT_RSS].rlim_cur; \
+ PR_UNLOCK(pr); \
+ \
+ if (((pr)->ps_flags & PS_ZOMBIE) == 0) { \
+ struct timeval tv; \
+ \
+ (kp)->p_uvalid = 1; \
+ \
+ (kp)->p_uru_maxrss = (p)->p_ru.ru_maxrss; \
+ (kp)->p_uru_ixrss = (p)->p_ru.ru_ixrss; \
+ (kp)->p_uru_idrss = (p)->p_ru.ru_idrss; \
+ (kp)->p_uru_isrss = (p)->p_ru.ru_isrss; \
+ (kp)->p_uru_minflt = (p)->p_ru.ru_minflt; \
+ (kp)->p_uru_majflt = (p)->p_ru.ru_majflt; \
+ (kp)->p_uru_nswap = (p)->p_ru.ru_nswap; \
+ (kp)->p_uru_inblock = (p)->p_ru.ru_inblock; \
+ (kp)->p_uru_oublock = (p)->p_ru.ru_oublock; \
+ (kp)->p_uru_msgsnd = (p)->p_ru.ru_msgsnd; \
+ (kp)->p_uru_msgrcv = (p)->p_ru.ru_msgrcv; \
+ (kp)->p_uru_nsignals = (p)->p_ru.ru_nsignals; \
+ (kp)->p_uru_nvcsw = (p)->p_ru.ru_nvcsw; \
+ (kp)->p_uru_nivcsw = (p)->p_ru.ru_nivcsw; \
+ \
+ timeradd(&(pr)->ps_cru.ru_utime, \
+ &(pr)->ps_cru.ru_stime, &tv); \
+ (kp)->p_uctime_sec = tv.tv_sec; \
+ (kp)->p_uctime_usec = tv.tv_usec; \
+ } \
+ \
+ (kp)->p_cpuid = KI_NOCPU; \
+ (kp)->p_rtableid = (pr)->ps_rtableid; \
+} while (0)
+
+#endif /* defined(_KERNEL) || defined(_LIBKVM) */
+
+
+/*
+ * kern.file returns an array of these structures, which are designed
+ * both to be immune to 32/64 bit emulation issues and to
+ * provide backwards compatibility. The order differs slightly from
+ * that of the real struct file, and some fields are taken from other
+ * structures (struct vnode, struct proc) in order to make the file
+ * information more useful.
+ */
+#define KERN_FILE_BYFILE 1
+#define KERN_FILE_BYPID 2
+#define KERN_FILE_BYUID 3
+#define KERN_FILESLOP 10
+
+#define KERN_FILE_TEXT -1
+#define KERN_FILE_CDIR -2
+#define KERN_FILE_RDIR -3
+#define KERN_FILE_TRACE -4
+
+#define KI_MNAMELEN 96 /* rounded up from 90 */
+#define KI_UNPPATHLEN 104
+
+struct kinfo_file {
+ uint64_t f_fileaddr; /* PTR: address of struct file */
+ uint32_t f_flag; /* UINT: flags (see fcntl.h) */
+ uint32_t f_iflags; /* UINT: internal flags */
+ uint32_t f_type; /* INT: descriptor type */
+ uint32_t f_count; /* UINT: reference count */
+ uint32_t f_msgcount; /* UINT: references from msg queue */
+ uint32_t f_usecount; /* INT: number active users */
+ uint64_t f_ucred; /* PTR: creds for descriptor */
+ uint32_t f_uid; /* UID_T: descriptor credentials */
+ uint32_t f_gid; /* GID_T: descriptor credentials */
+ uint64_t f_ops; /* PTR: address of fileops */
+ uint64_t f_offset; /* OFF_T: offset */
+ uint64_t f_data; /* PTR: descriptor data */
+ uint64_t f_rxfer; /* UINT64: number of read xfers */
+ uint64_t f_rwfer; /* UINT64: number of write xfers */
+ uint64_t f_seek; /* UINT64: number of seek operations */
+ uint64_t f_rbytes; /* UINT64: total bytes read */
+ uint64_t f_wbytes; /* UINT64: total bytes written */
+
+ /* information about the vnode associated with this file */
+ uint64_t v_un; /* PTR: socket, specinfo, etc */
+ uint32_t v_type; /* ENUM: vnode type */
+ uint32_t v_tag; /* ENUM: type of underlying data */
+ uint32_t v_flag; /* UINT: vnode flags */
+ uint32_t va_rdev; /* DEV_T: raw device */
+ uint64_t v_data; /* PTR: private data for fs */
+ uint64_t v_mount; /* PTR: mount info for fs */
+ uint64_t va_fileid; /* LONG: file id */
+ uint64_t va_size; /* UINT64_T: file size in bytes */
+ uint32_t va_mode; /* MODE_T: file access mode and type */
+ uint32_t va_fsid; /* DEV_T: filesystem device */
+ char f_mntonname[KI_MNAMELEN];
+
+ /* socket information */
+ uint32_t so_type; /* SHORT: socket type */
+ uint32_t so_state; /* SHORT: socket state */
+ uint64_t so_pcb; /* PTR: socket pcb */
+ /* for non-root: -1 if not NULL */
+ uint32_t so_protocol; /* SHORT: socket protocol type */
+ uint32_t so_family; /* INT: socket domain family */
+ uint64_t inp_ppcb; /* PTR: pointer to per-protocol pcb */
+ uint32_t inp_lport; /* SHORT: local inet port */
+ uint32_t inp_laddru[4]; /* STRUCT: local inet addr */
+ uint32_t inp_fport; /* SHORT: foreign inet port */
+ uint32_t inp_faddru[4]; /* STRUCT: foreign inet addr */
+ uint64_t unp_conn; /* PTR: connected socket cntrl block */
+
+ /* pipe information */
+ uint64_t pipe_peer; /* PTR: link with other direction */
+ uint32_t pipe_state; /* UINT: pipe status info */
+
+ /* kqueue information */
+ uint32_t kq_count; /* INT: number of pending events */
+ uint32_t kq_state; /* INT: kqueue status information */
+
+ uint32_t __unused1; /* INT: unused */
+
+ /* process information when retrieved via KERN_FILE_BY[PU]ID */
+ uint32_t p_pid; /* PID_T: process id */
+ int32_t fd_fd; /* INT: descriptor number */
+ uint32_t fd_ofileflags; /* CHAR: open file flags */
+ uint32_t p_uid; /* UID_T: process credentials */
+ uint32_t p_gid; /* GID_T: process credentials */
+ uint32_t p_tid; /* PID_T: thread id */
+ char p_comm[KI_MAXCOMLEN];
+
+ /* more socket information */
+ uint32_t inp_rtableid; /* UINT: Routing table identifier. */
+ uint64_t so_splice; /* PTR: f_data of spliced socket */
+ int64_t so_splicelen; /* OFF_T: already spliced count or */
+ /* -1 if this is target of splice */
+ uint64_t so_rcv_cc; /* LONG: chars in receive buf */
+ uint64_t so_snd_cc; /* LONG: chars in send buf */
+ uint64_t unp_refs; /* PTR: connected sockets */
+ uint64_t unp_nextref; /* PTR: link to next connected socket */
+ uint64_t unp_addr; /* PTR: address of the socket address */
+ char unp_path[KI_UNPPATHLEN];
+ uint32_t inp_proto; /* CHAR: raw protocol id */
+ uint32_t t_state; /* SHORT: tcp state */
+ uint64_t t_rcv_wnd; /* ULONG: tcp receive window */
+ uint64_t t_snd_wnd; /* ULONG: tcp send window */
+ uint64_t t_snd_cwnd; /* ULONG: congestion-controlled win */
+
+ uint32_t va_nlink; /* NLINK_T: number of references to file */
+};
+
+/*
+ * KERN_INTRCNT
+ */
+#define KERN_INTRCNT_NUM 1 /* int: # intrcnt */
+#define KERN_INTRCNT_CNT 2 /* node: intrcnt */
+#define KERN_INTRCNT_NAME 3 /* node: names */
+#define KERN_INTRCNT_VECTOR 4 /* node: interrupt vector # */
+#define KERN_INTRCNT_MAXID 5
+
+#define CTL_KERN_INTRCNT_NAMES { \
+ { 0, 0 }, \
+ { "nintrcnt", CTLTYPE_INT }, \
+ { "intrcnt", CTLTYPE_NODE }, \
+ { "intrname", CTLTYPE_NODE }, \
+}
+
+/*
+ * KERN_WATCHDOG
+ */
+#define KERN_WATCHDOG_PERIOD 1 /* int: watchdog period */
+#define KERN_WATCHDOG_AUTO 2 /* int: automatic tickle */
+#define KERN_WATCHDOG_MAXID 3
+
+#define CTL_KERN_WATCHDOG_NAMES { \
+ { 0, 0 }, \
+ { "period", CTLTYPE_INT }, \
+ { "auto", CTLTYPE_INT }, \
+}
+
+/*
+ * KERN_TIMECOUNTER
+ */
+#define KERN_TIMECOUNTER_TICK 1 /* int: number of revolutions */
+#define KERN_TIMECOUNTER_TIMESTEPWARNINGS 2 /* int: log a warning when time changes */
+#define KERN_TIMECOUNTER_HARDWARE 3 /* string: tick hardware used */
+#define KERN_TIMECOUNTER_CHOICE 4 /* string: tick hardware used */
+#define KERN_TIMECOUNTER_MAXID 5
+
+#define CTL_KERN_TIMECOUNTER_NAMES { \
+ { 0, 0 }, \
+ { "tick", CTLTYPE_INT }, \
+ { "timestepwarnings", CTLTYPE_INT }, \
+ { "hardware", CTLTYPE_STRING }, \
+ { "choice", CTLTYPE_STRING }, \
+}
+
+/*
+ * CTL_FS identifiers
+ */
+#define FS_POSIX 1 /* POSIX flags */
+#define FS_MAXID 2
+
+#define CTL_FS_NAMES { \
+ { 0, 0 }, \
+ { "posix", CTLTYPE_NODE }, \
+}
+
+/*
+ * CTL_FS identifiers
+ */
+#define FS_POSIX_SETUID 1 /* int: always clear SGID/SUID bit when owner change */
+#define FS_POSIX_MAXID 2
+
+#define CTL_FS_POSIX_NAMES { \
+ { 0, 0 }, \
+ { "setuid", CTLTYPE_INT }, \
+}
+
+/*
+ * CTL_HW identifiers
+ */
+#define HW_MACHINE 1 /* string: machine class */
+#define HW_MODEL 2 /* string: specific machine model */
+#define HW_NCPU 3 /* int: number of configured cpus */
+#define HW_BYTEORDER 4 /* int: machine byte order */
+#define HW_PHYSMEM 5 /* int: total memory */
+#define HW_USERMEM 6 /* int: non-kernel memory */
+#define HW_PAGESIZE 7 /* int: software page size */
+#define HW_DISKNAMES 8 /* strings: disk drive names */
+#define HW_DISKSTATS 9 /* struct: diskstats[] */
+#define HW_DISKCOUNT 10 /* int: number of disks */
+#define HW_SENSORS 11 /* node: hardware monitors */
+#define HW_CPUSPEED 12 /* get CPU frequency */
+#define HW_SETPERF 13 /* set CPU performance % */
+#define HW_VENDOR 14 /* string: vendor name */
+#define HW_PRODUCT 15 /* string: product name */
+#define HW_VERSION 16 /* string: hardware version */
+#define HW_SERIALNO 17 /* string: hardware serial number */
+#define HW_UUID 18 /* string: universal unique id */
+#define HW_PHYSMEM64 19 /* quad: total memory */
+#define HW_USERMEM64 20 /* quad: non-kernel memory */
+#define HW_NCPUFOUND 21 /* int: number of cpus found */
+#define HW_ALLOWPOWERDOWN 22 /* allow power button shutdown */
+#define HW_PERFPOLICY 23 /* set performance policy */
+#define HW_SMT 24 /* int: enable SMT/HT/CMT */
+#define HW_NCPUONLINE 25 /* int: number of cpus being used */
+#define HW_MAXID 26 /* number of valid hw ids */
+
+#define CTL_HW_NAMES { \
+ { 0, 0 }, \
+ { "machine", CTLTYPE_STRING }, \
+ { "model", CTLTYPE_STRING }, \
+ { "ncpu", CTLTYPE_INT }, \
+ { "byteorder", CTLTYPE_INT }, \
+ { "gap", 0 }, \
+ { "gap", 0 }, \
+ { "pagesize", CTLTYPE_INT }, \
+ { "disknames", CTLTYPE_STRING }, \
+ { "diskstats", CTLTYPE_STRUCT }, \
+ { "diskcount", CTLTYPE_INT }, \
+ { "sensors", CTLTYPE_NODE}, \
+ { "cpuspeed", CTLTYPE_INT }, \
+ { "setperf", CTLTYPE_INT }, \
+ { "vendor", CTLTYPE_STRING }, \
+ { "product", CTLTYPE_STRING }, \
+ { "version", CTLTYPE_STRING }, \
+ { "serialno", CTLTYPE_STRING }, \
+ { "uuid", CTLTYPE_STRING }, \
+ { "physmem", CTLTYPE_QUAD }, \
+ { "usermem", CTLTYPE_QUAD }, \
+ { "ncpufound", CTLTYPE_INT }, \
+ { "allowpowerdown", CTLTYPE_INT }, \
+ { "perfpolicy", CTLTYPE_STRING }, \
+ { "smt", CTLTYPE_INT }, \
+ { "ncpuonline", CTLTYPE_INT }, \
+}
+
+/*
+ * CTL_DEBUG definitions
+ *
+ * Second level identifier specifies which debug variable.
+ * Third level identifier specifies which structure component.
+ */
+#define CTL_DEBUG_NAME 0 /* string: variable name */
+#define CTL_DEBUG_VALUE 1 /* int: variable value */
+#define CTL_DEBUG_MAXID 20
+
+#ifdef _KERNEL
+#ifdef DEBUG
+/*
+ * CTL_DEBUG variables.
+ *
+ * These are declared as separate variables so that they can be
+ * individually initialized at the location of their associated
+ * variable. The loader prevents multiple use by issuing errors
+ * if a variable is initialized in more than one place. They are
+ * aggregated into an array in debug_sysctl(), so that it can
+ * conveniently locate them when querried. If more debugging
+ * variables are added, they must also be declared here and also
+ * entered into the array.
+ */
+struct ctldebug {
+ char *debugname; /* name of debugging variable */
+ int *debugvar; /* pointer to debugging variable */
+};
+extern struct ctldebug debug0, debug1, debug2, debug3, debug4;
+extern struct ctldebug debug5, debug6, debug7, debug8, debug9;
+extern struct ctldebug debug10, debug11, debug12, debug13, debug14;
+extern struct ctldebug debug15, debug16, debug17, debug18, debug19;
+#endif /* DEBUG */
+
+/*
+ * Internal sysctl function calling convention:
+ *
+ * (*sysctlfn)(name, namelen, oldval, oldlenp, newval, newlen);
+ *
+ * The name parameter points at the next component of the name to be
+ * interpreted. The namelen parameter is the number of integers in
+ * the name.
+ */
+typedef int (sysctlfn)(int *, u_int, void *, size_t *, void *, size_t, struct proc *);
+
+int sysctl_int(void *, size_t *, void *, size_t, int *);
+int sysctl_int_lower(void *, size_t *, void *, size_t, int *);
+int sysctl_rdint(void *, size_t *, void *, int);
+int sysctl_int_arr(int **, int *, u_int, void *, size_t *, void *, size_t);
+int sysctl_quad(void *, size_t *, void *, size_t, int64_t *);
+int sysctl_rdquad(void *, size_t *, void *, int64_t);
+int sysctl_string(void *, size_t *, void *, size_t, char *, size_t);
+int sysctl_tstring(void *, size_t *, void *, size_t, char *, size_t);
+int sysctl__string(void *, size_t *, void *, size_t, char *, size_t, int);
+int sysctl_rdstring(void *, size_t *, void *, const char *);
+int sysctl_rdstruct(void *, size_t *, void *, const void *, size_t);
+int sysctl_struct(void *, size_t *, void *, size_t, void *, size_t);
+int sysctl_file(int *, u_int, char *, size_t *, struct proc *);
+int sysctl_doproc(int *, u_int, char *, size_t *);
+struct mbuf_queue;
+int sysctl_mq(int *, u_int, void *, size_t *, void *, size_t,
+ struct mbuf_queue *);
+struct rtentry;
+struct walkarg;
+int sysctl_dumpentry(struct rtentry *, void *, unsigned int);
+int sysctl_rtable(int *, u_int, void *, size_t *, void *, size_t);
+int sysctl_clockrate(char *, size_t *, void *);
+int sysctl_vnode(char *, size_t *, struct proc *);
+#if defined(GPROF) || defined(DDBPROF)
+int sysctl_doprof(int *, u_int, void *, size_t *, void *, size_t);
+#endif
+int sysctl_dopool(int *, u_int, char *, size_t *);
+
+int kern_sysctl(int *, u_int, void *, size_t *, void *, size_t,
+ struct proc *);
+int hw_sysctl(int *, u_int, void *, size_t *, void *, size_t,
+ struct proc *);
+#ifdef DEBUG
+int debug_sysctl(int *, u_int, void *, size_t *, void *, size_t,
+ struct proc *);
+#endif
+int vm_sysctl(int *, u_int, void *, size_t *, void *, size_t,
+ struct proc *);
+int fs_sysctl(int *, u_int, void *, size_t *, void *, size_t,
+ struct proc *);
+int fs_posix_sysctl(int *, u_int, void *, size_t *, void *, size_t,
+ struct proc *);
+int net_sysctl(int *, u_int, void *, size_t *, void *, size_t,
+ struct proc *);
+int cpu_sysctl(int *, u_int, void *, size_t *, void *, size_t,
+ struct proc *);
+int vfs_sysctl(int *, u_int, void *, size_t *, void *, size_t,
+ struct proc *);
+int sysctl_sysvipc(int *, u_int, void *, size_t *);
+int sysctl_wdog(int *, u_int, void *, size_t *, void *, size_t);
+
+extern int (*cpu_cpuspeed)(int *);
+extern void (*cpu_setperf)(int);
+
+int net_ifiq_sysctl(int *, u_int, void *, size_t *, void *, size_t);
+int bpf_sysctl(int *, u_int, void *, size_t *, void *, size_t);
+int pflow_sysctl(int *, u_int, void *, size_t *, void *, size_t);
+int pipex_sysctl(int *, u_int, void *, size_t *, void *, size_t);
+int mpls_sysctl(int *, u_int, void *, size_t *, void *, size_t);
+int pf_sysctl(void *, size_t *, void *, size_t);
+
+#else /* !_KERNEL */
+
+__BEGIN_DECLS
+int sysctl(const int *, u_int, void *, size_t *, void *, size_t);
+__END_DECLS
+#endif /* _KERNEL */
+#endif /* !_SYS_SYSCTL_H_ */
diff --git a/sys/sys/syslimits.h b/sys/sys/syslimits.h
new file mode 100644
index 0000000..891c9b4
--- /dev/null
+++ b/sys/sys/syslimits.h
@@ -0,0 +1,77 @@
+/* $OpenBSD: syslimits.h,v 1.14 2020/04/02 18:00:00 deraadt Exp $ */
+/* $NetBSD: syslimits.h,v 1.12 1995/10/05 05:26:19 thorpej Exp $ */
+
+/*
+ * Copyright (c) 1988, 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.
+ *
+ * @(#)syslimits.h 8.1 (Berkeley) 6/2/93
+ */
+
+#include <sys/cdefs.h>
+
+#if __POSIX_VISIBLE || __XPG_VISIBLE || __BSD_VISIBLE
+#define ARG_MAX (512 * 1024) /* max bytes for an exec function */
+#define CHILD_MAX 80 /* max simultaneous processes */
+#define LINK_MAX 32767 /* max file link count */
+#define MAX_CANON 255 /* max bytes in term canon input line */
+#define MAX_INPUT 255 /* max bytes in terminal input */
+#define NAME_MAX 255 /* max bytes in a file name */
+#define NGROUPS_MAX 16 /* max supplemental group id's */
+#define OPEN_MAX 64 /* max open files per process */
+#define PATH_MAX 1024 /* max bytes in pathname */
+#define PIPE_BUF 512 /* max bytes for atomic pipe writes */
+#define SYMLINK_MAX PATH_MAX /* max bytes in a symbolic link */
+#define SYMLOOP_MAX 32 /* max symlinks per path (for loops) */
+
+#define BC_BASE_MAX INT_MAX /* max ibase/obase values in bc(1) */
+#define BC_DIM_MAX 65535 /* max array elements in bc(1) */
+#define BC_SCALE_MAX INT_MAX /* max scale value in bc(1) */
+#define BC_STRING_MAX INT_MAX /* max const string length in bc(1) */
+#define COLL_WEIGHTS_MAX 2 /* max weights for order keyword */
+#define EXPR_NEST_MAX 32 /* max expressions nested in expr(1) */
+#define LINE_MAX 2048 /* max bytes in an input line */
+#ifndef RE_DUP_MAX
+#define RE_DUP_MAX 255 /* max RE's in interval notation */
+#define SEM_VALUE_MAX UINT_MAX /* max value of a sem_* semaphore */
+#endif
+
+#if __XPG_VISIBLE
+#define IOV_MAX 1024 /* max # of iov's (readv,sendmsg,etc) */
+#define NZERO 20 /* default "nice" */
+#endif /* __XPG_VISIBLE */
+
+#endif /* __POSIX_VISIBLE || __XPG_VISIBLE || __BSD_VISIBLE */
+
+#if __XPG_VISIBLE >= 500 || __POSIX_VISIBLE >= 199506 || __BSD_VISIBLE
+#define TTY_NAME_MAX 260 /* max tty device name length w/ NUL */
+#define LOGIN_NAME_MAX 32 /* max login name length w/ NUL */
+#endif /* __XPG_VISIBLE >= 500 || __POSIX_VISIBLE >= 199506 || __BSD_VISIBLE */
+
+#if __POSIX_VISIBLE >= 200112
+#define HOST_NAME_MAX 255 /* max hostname length w/o NUL */
+#endif
diff --git a/sys/sys/syslog.h b/sys/sys/syslog.h
new file mode 100644
index 0000000..c70a660
--- /dev/null
+++ b/sys/sys/syslog.h
@@ -0,0 +1,221 @@
+/* $OpenBSD: syslog.h,v 1.16 2017/08/08 14:23:23 bluhm Exp $ */
+/* $NetBSD: syslog.h,v 1.14 1996/04/03 20:46:44 christos Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 1988, 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.
+ *
+ * @(#)syslog.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _SYS_SYSLOG_H_
+#define _SYS_SYSLOG_H_
+
+#define _PATH_LOG "/dev/log"
+
+#define LIOCSFD _IOW('l', 127, int) /* set sendsyslog() fd */
+
+#define LOG_MAXLINE 8192 /* maximum line length */
+
+/*
+ * priorities/facilities are encoded into a single 32-bit quantity, where the
+ * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility
+ * (0-big number). Both the priorities and the facilities map roughly
+ * one-to-one to strings in the syslogd(8) source code. This mapping is
+ * included in this file.
+ *
+ * priorities (these are ordered)
+ */
+#define LOG_EMERG 0 /* system is unusable */
+#define LOG_ALERT 1 /* action must be taken immediately */
+#define LOG_CRIT 2 /* critical conditions */
+#define LOG_ERR 3 /* error conditions */
+#define LOG_WARNING 4 /* warning conditions */
+#define LOG_NOTICE 5 /* normal but significant condition */
+#define LOG_INFO 6 /* informational */
+#define LOG_DEBUG 7 /* debug-level messages */
+
+#define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */
+ /* extract priority */
+#define LOG_PRI(p) ((p) & LOG_PRIMASK)
+
+#ifdef SYSLOG_NAMES
+#define INTERNAL_NOPRI 0x10 /* the "no priority" priority */
+ /* mark "facility" */
+#define INTERNAL_MARK (LOG_NFACILITIES<<3)
+typedef struct _code {
+ char *c_name;
+ int c_val;
+} CODE;
+
+CODE prioritynames[] = {
+ { "alert", LOG_ALERT },
+ { "crit", LOG_CRIT },
+ { "debug", LOG_DEBUG },
+ { "emerg", LOG_EMERG },
+ { "err", LOG_ERR },
+ { "error", LOG_ERR }, /* DEPRECATED */
+ { "info", LOG_INFO },
+ { "none", INTERNAL_NOPRI }, /* INTERNAL */
+ { "notice", LOG_NOTICE },
+ { "panic", LOG_EMERG }, /* DEPRECATED */
+ { "warn", LOG_WARNING }, /* DEPRECATED */
+ { "warning", LOG_WARNING },
+ { NULL, -1 },
+};
+#endif
+
+/* facility codes */
+#define LOG_KERN (0<<3) /* kernel messages */
+#define LOG_USER (1<<3) /* random user-level messages */
+#define LOG_MAIL (2<<3) /* mail system */
+#define LOG_DAEMON (3<<3) /* system daemons */
+#define LOG_AUTH (4<<3) /* security/authorization messages */
+#define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */
+#define LOG_LPR (6<<3) /* line printer subsystem */
+#define LOG_NEWS (7<<3) /* network news subsystem */
+#define LOG_UUCP (8<<3) /* UUCP subsystem */
+#define LOG_CRON (9<<3) /* clock daemon */
+#define LOG_AUTHPRIV (10<<3) /* security/authorization messages (private) */
+#define LOG_FTP (11<<3) /* ftp daemon */
+
+ /* other codes through 15 reserved for system use */
+#define LOG_LOCAL0 (16<<3) /* reserved for local use */
+#define LOG_LOCAL1 (17<<3) /* reserved for local use */
+#define LOG_LOCAL2 (18<<3) /* reserved for local use */
+#define LOG_LOCAL3 (19<<3) /* reserved for local use */
+#define LOG_LOCAL4 (20<<3) /* reserved for local use */
+#define LOG_LOCAL5 (21<<3) /* reserved for local use */
+#define LOG_LOCAL6 (22<<3) /* reserved for local use */
+#define LOG_LOCAL7 (23<<3) /* reserved for local use */
+
+#define LOG_NFACILITIES 24 /* current number of facilities */
+#define LOG_FACMASK 0x03f8 /* mask to extract facility part */
+ /* facility of pri */
+#define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3)
+
+#ifdef SYSLOG_NAMES
+CODE facilitynames[] = {
+ { "auth", LOG_AUTH },
+ { "authpriv", LOG_AUTHPRIV },
+ { "cron", LOG_CRON },
+ { "daemon", LOG_DAEMON },
+ { "ftp", LOG_FTP },
+ { "kern", LOG_KERN },
+ { "lpr", LOG_LPR },
+ { "mail", LOG_MAIL },
+ { "mark", INTERNAL_MARK }, /* INTERNAL */
+ { "news", LOG_NEWS },
+ { "security", LOG_AUTH }, /* DEPRECATED */
+ { "syslog", LOG_SYSLOG },
+ { "user", LOG_USER },
+ { "uucp", LOG_UUCP },
+ { "local0", LOG_LOCAL0 },
+ { "local1", LOG_LOCAL1 },
+ { "local2", LOG_LOCAL2 },
+ { "local3", LOG_LOCAL3 },
+ { "local4", LOG_LOCAL4 },
+ { "local5", LOG_LOCAL5 },
+ { "local6", LOG_LOCAL6 },
+ { "local7", LOG_LOCAL7 },
+ { NULL, -1 },
+};
+#endif
+
+/* Used by reentrant functions */
+
+struct syslog_data {
+ int log_stat;
+ const char *log_tag;
+ int log_fac;
+ int log_mask;
+};
+
+#define SYSLOG_DATA_INIT {0, (const char *)0, LOG_USER, 0xff}
+
+#ifdef _KERNEL
+#define LOG_PRINTF -1 /* pseudo-priority to indicate use of printf */
+#endif
+
+/*
+ * arguments to setlogmask.
+ */
+#define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */
+#define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */
+
+/*
+ * Option flags for openlog.
+ *
+ * LOG_ODELAY no longer does anything.
+ * LOG_NDELAY is the inverse of what it used to be.
+ */
+#define LOG_PID 0x01 /* log the pid with each message */
+#define LOG_CONS 0x02 /* log on the console if errors in sending */
+#define LOG_ODELAY 0x04 /* delay open until first syslog() (default) */
+#define LOG_NDELAY 0x08 /* don't delay open */
+#define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */
+#define LOG_PERROR 0x20 /* log to stderr as well */
+
+#ifndef _KERNEL
+
+/*
+ * Don't use va_list in the vsyslog() prototype. Va_list is typedef'd in two
+ * places (<machine/varargs.h> and <machine/stdarg.h>), so if we include one
+ * of them here we may collide with the utility's includes. It's unreasonable
+ * for utilities to have to include one of them to include syslog.h, so we get
+ * __va_list from <machine/_types.h> and use it.
+ */
+#include <sys/cdefs.h>
+#include <machine/_types.h>
+
+__BEGIN_DECLS
+void closelog(void);
+void openlog(const char *, int, int);
+int setlogmask(int);
+void syslog(int, const char *, ...)
+ __attribute__((__format__(__syslog__,2,3)));
+void vsyslog(int, const char *, __va_list);
+void closelog_r(struct syslog_data *);
+void openlog_r(const char *, int, int, struct syslog_data *);
+int setlogmask_r(int, struct syslog_data *);
+void syslog_r(int, struct syslog_data *, const char *, ...)
+ __attribute__((__format__(__syslog__,3,4)));
+void vsyslog_r(int, struct syslog_data *, const char *, __va_list);
+__END_DECLS
+
+#else /* !_KERNEL */
+
+void logpri(int);
+void log(int, const char *, ...)
+ __attribute__((__format__(__kprintf__,2,3)));
+int addlog(const char *, ...)
+ __attribute__((__format__(__kprintf__,1,2)));
+void logwakeup(void);
+
+#endif /* !_KERNEL */
+#endif /* !_SYS_SYSLOG_H_ */
+
diff --git a/sys/sys/systm.h b/sys/sys/systm.h
new file mode 100644
index 0000000..5dec672
--- /dev/null
+++ b/sys/sys/systm.h
@@ -0,0 +1,409 @@
+/* $OpenBSD: systm.h,v 1.145 2020/03/20 03:37:08 cheloha Exp $ */
+/* $NetBSD: systm.h,v 1.50 1996/06/09 04:55:09 briggs Exp $ */
+
+/*-
+ * Copyright (c) 1982, 1988, 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)systm.h 8.4 (Berkeley) 2/23/94
+ */
+
+#ifndef __SYSTM_H__
+#define __SYSTM_H__
+
+#include <sys/queue.h>
+#include <sys/stdarg.h>
+
+/*
+ * The `securelevel' variable controls the security level of the system.
+ * It can only be decreased by process 1 (/sbin/init).
+ *
+ * Security levels are as follows:
+ * -1 permanently insecure mode - always run system in level 0 mode.
+ * 0 insecure mode - immutable and append-only flags may be turned off.
+ * All devices may be read or written subject to permission modes.
+ * 1 secure mode - immutable and append-only flags may not be changed;
+ * raw disks of mounted filesystems, /dev/mem, and /dev/kmem are
+ * read-only.
+ * 2 highly secure mode - same as (1) plus raw disks are always
+ * read-only whether mounted or not. This level precludes tampering
+ * with filesystems by unmounting them, but also inhibits running
+ * newfs while the system is secured.
+ *
+ * In normal operation, the system runs in level 0 mode while single user
+ * and in level 1 mode while multiuser. If level 2 mode is desired while
+ * running multiuser, it can be set in the multiuser startup script
+ * (/etc/rc.local) using sysctl(1). If it is desired to run the system
+ * in level 0 mode while multiuser, initialize the variable securelevel
+ * in /sys/kern/kern_sysctl.c to -1. Note that it is NOT initialized to
+ * zero as that would allow the vmunix binary to be patched to -1.
+ * Without initialization, securelevel loads in the BSS area which only
+ * comes into existence when the kernel is loaded and hence cannot be
+ * patched by a stalking hacker.
+ */
+extern int securelevel; /* system security level */
+extern const char *panicstr; /* panic message */
+extern const char *faultstr; /* fault message */
+extern const char version[]; /* system version */
+extern const char copyright[]; /* system copyright */
+extern const char ostype[];
+extern const char osversion[];
+extern const char osrelease[];
+extern int cold; /* cold start flag initialized in locore */
+extern int db_active; /* running currently inside ddb(4) */
+
+extern int ncpus; /* number of CPUs used */
+extern int ncpusfound; /* number of CPUs found */
+extern int nblkdev; /* number of entries in bdevsw */
+extern int nchrdev; /* number of entries in cdevsw */
+
+extern int selwait; /* select timeout address */
+extern int maxmem; /* max memory per process */
+extern int physmem; /* physical memory */
+
+extern dev_t dumpdev; /* dump device */
+extern long dumplo; /* offset into dumpdev */
+
+extern dev_t rootdev; /* root device */
+extern u_char bootduid[8]; /* boot device disklabel uid */
+extern u_char rootduid[8]; /* root device disklabel uid */
+extern struct vnode *rootvp; /* vnode equivalent to above */
+
+extern dev_t swapdev; /* swapping device */
+extern struct vnode *swapdev_vp;/* vnode equivalent to above */
+
+struct proc;
+struct process;
+#define curproc curcpu()->ci_curproc
+
+typedef int sy_call_t(struct proc *, void *, register_t *);
+
+extern struct sysent { /* system call table */
+ short sy_narg; /* number of args */
+ short sy_argsize; /* total size of arguments */
+ int sy_flags;
+ sy_call_t *sy_call; /* implementing function */
+} sysent[];
+
+#define SY_NOLOCK 0x01
+
+#if _BYTE_ORDER == _BIG_ENDIAN
+#define SCARG(p, k) ((p)->k.be.datum) /* get arg from args pointer */
+#elif _BYTE_ORDER == _LITTLE_ENDIAN
+#define SCARG(p, k) ((p)->k.le.datum) /* get arg from args pointer */
+#else
+#error "what byte order is this machine?"
+#endif
+
+#if defined(_KERNEL) && defined(SYSCALL_DEBUG)
+void scdebug_call(struct proc *p, register_t code, const register_t retval[]);
+void scdebug_ret(struct proc *p, register_t code, int error,
+ const register_t retval[]);
+#endif /* _KERNEL && SYSCALL_DEBUG */
+
+extern int boothowto; /* reboot flags, from console subsystem */
+
+extern void (*v_putc)(int); /* Virtual console putc routine */
+
+/*
+ * General function declarations.
+ */
+int nullop(void *);
+int enodev(void);
+int enosys(void);
+int enoioctl(void);
+int enxio(void);
+int eopnotsupp(void *);
+
+struct vnodeopv_desc;
+void vfs_opv_init_explicit(struct vnodeopv_desc *);
+void vfs_opv_init_default(struct vnodeopv_desc *);
+void vfs_op_init(void);
+
+int seltrue(dev_t dev, int which, struct proc *);
+int selfalse(dev_t dev, int which, struct proc *);
+void *hashinit(int, int, int, u_long *);
+void hashfree(void *, int, int);
+int sys_nosys(struct proc *, void *, register_t *);
+
+void panic(const char *, ...)
+ __attribute__((__noreturn__,__format__(__kprintf__,1,2)));
+void __assert(const char *, const char *, int, const char *)
+ __attribute__((__noreturn__));
+int printf(const char *, ...)
+ __attribute__((__format__(__kprintf__,1,2)));
+void uprintf(const char *, ...)
+ __attribute__((__format__(__kprintf__,1,2)));
+int vprintf(const char *, va_list)
+ __attribute__((__format__(__kprintf__,1,0)));
+int vsnprintf(char *, size_t, const char *, va_list)
+ __attribute__((__format__(__kprintf__,3,0)));
+int snprintf(char *buf, size_t, const char *, ...)
+ __attribute__((__format__(__kprintf__,3,4)));
+struct tty;
+void ttyprintf(struct tty *, const char *, ...)
+ __attribute__((__format__(__kprintf__,2,3)));
+
+void splassert_fail(int, int, const char *);
+extern int splassert_ctl;
+
+void assertwaitok(void);
+
+void tablefull(const char *);
+
+int kcopy(const void *, void *, size_t)
+ __attribute__ ((__bounded__(__buffer__,1,3)))
+ __attribute__ ((__bounded__(__buffer__,2,3)));
+
+void bcopy(const void *, void *, size_t)
+ __attribute__ ((__bounded__(__buffer__,1,3)))
+ __attribute__ ((__bounded__(__buffer__,2,3)));
+void bzero(void *, size_t)
+ __attribute__ ((__bounded__(__buffer__,1,2)));
+void explicit_bzero(void *, size_t)
+ __attribute__ ((__bounded__(__buffer__,1,2)));
+int bcmp(const void *, const void *, size_t);
+void *memcpy(void *, const void *, size_t)
+ __attribute__ ((__bounded__(__buffer__,1,3)))
+ __attribute__ ((__bounded__(__buffer__,2,3)));
+void *memmove(void *, const void *, size_t)
+ __attribute__ ((__bounded__(__buffer__,1,3)))
+ __attribute__ ((__bounded__(__buffer__,2,3)));
+void *memset(void *, int, size_t)
+ __attribute__ ((__bounded__(__buffer__,1,3)));
+
+int copystr(const void *, void *, size_t, size_t *)
+ __attribute__ ((__bounded__(__string__,2,3)));
+int copyinstr(const void *, void *, size_t, size_t *)
+ __attribute__ ((__bounded__(__string__,2,3)));
+int copyoutstr(const void *, void *, size_t, size_t *);
+int copyin(const void *, void *, size_t)
+ __attribute__ ((__bounded__(__buffer__,2,3)));
+int copyout(const void *, void *, size_t);
+int copyin32(const uint32_t *, uint32_t *);
+
+struct arc4random_ctx;
+void arc4random_buf(void *, size_t)
+ __attribute__ ((__bounded__(__buffer__,1,2)));
+struct arc4random_ctx *arc4random_ctx_new(void);
+void arc4random_ctx_free(struct arc4random_ctx *);
+void arc4random_ctx_buf(struct arc4random_ctx *, void *, size_t);
+u_int32_t arc4random(void);
+u_int32_t arc4random_uniform(u_int32_t);
+
+struct timeval;
+struct timespec;
+int tvtohz(const struct timeval *);
+int tstohz(const struct timespec *);
+void realitexpire(void *);
+
+struct clockframe;
+void hardclock(struct clockframe *);
+void statclock(struct clockframe *);
+
+void initclocks(void);
+void inittodr(time_t);
+void resettodr(void);
+void cpu_initclocks(void);
+
+void startprofclock(struct process *);
+void stopprofclock(struct process *);
+void setstatclockrate(int);
+
+void start_periodic_resettodr(void);
+void stop_periodic_resettodr(void);
+
+struct sleep_state;
+void sleep_setup(struct sleep_state *, const volatile void *, int,
+ const char *);
+void sleep_setup_timeout(struct sleep_state *, int);
+void sleep_setup_signal(struct sleep_state *);
+void sleep_finish(struct sleep_state *, int);
+int sleep_finish_timeout(struct sleep_state *);
+int sleep_finish_signal(struct sleep_state *);
+int sleep_finish_all(struct sleep_state *, int);
+void sleep_queue_init(void);
+
+struct cond;
+void cond_init(struct cond *);
+void cond_wait(struct cond *, const char *);
+void cond_signal(struct cond *);
+
+#define INFSLP UINT64_MAX
+#define MAXTSLP (UINT64_MAX - 1)
+
+struct mutex;
+struct rwlock;
+void wakeup_n(const volatile void *, int);
+void wakeup(const volatile void *);
+#define wakeup_one(c) wakeup_n((c), 1)
+int tsleep(const volatile void *, int, const char *, int);
+int tsleep_nsec(const volatile void *, int, const char *, uint64_t);
+int msleep(const volatile void *, struct mutex *, int, const char*, int);
+int msleep_nsec(const volatile void *, struct mutex *, int, const char*,
+ uint64_t);
+int rwsleep(const volatile void *, struct rwlock *, int, const char *, int);
+int rwsleep_nsec(const volatile void *, struct rwlock *, int, const char *,
+ uint64_t);
+void yield(void);
+
+void wdog_register(int (*)(void *, int), void *);
+void wdog_shutdown(void *);
+
+/*
+ * Startup hooks are functions running after the scheduler has started
+ * but before any threads have been created or root has been mounted.
+ */
+
+struct hook_desc {
+ TAILQ_ENTRY(hook_desc) hd_list;
+ void (*hd_fn)(void *);
+ void *hd_arg;
+};
+TAILQ_HEAD(hook_desc_head, hook_desc);
+
+extern struct hook_desc_head startuphook_list;
+
+void *hook_establish(struct hook_desc_head *, int, void (*)(void *), void *);
+void hook_disestablish(struct hook_desc_head *, void *);
+void dohooks(struct hook_desc_head *, int);
+
+#define HOOK_REMOVE 0x01
+#define HOOK_FREE 0x02
+
+#define startuphook_establish(fn, arg) \
+ hook_establish(&startuphook_list, 1, (fn), (arg))
+#define startuphook_disestablish(vhook) \
+ hook_disestablish(&startuphook_list, (vhook))
+#define dostartuphooks() dohooks(&startuphook_list, HOOK_REMOVE|HOOK_FREE)
+
+struct uio;
+int uiomove(void *, size_t, struct uio *);
+
+#if defined(_KERNEL)
+
+#include <sys/rwlock.h>
+
+extern struct rwlock netlock;
+
+#define NET_LOCK() NET_WLOCK()
+#define NET_UNLOCK() NET_WUNLOCK()
+#define NET_ASSERT_UNLOCKED() NET_ASSERT_WUNLOCKED()
+
+
+#define NET_WLOCK() do { rw_enter_write(&netlock); } while (0)
+#define NET_WUNLOCK() do { rw_exit_write(&netlock); } while (0)
+
+#define NET_ASSERT_WLOCKED() \
+do { \
+ int _s = rw_status(&netlock); \
+ if ((splassert_ctl > 0) && (_s != RW_WRITE)) \
+ splassert_fail(RW_WRITE, _s, __func__); \
+} while (0)
+
+#define NET_ASSERT_WUNLOCKED() \
+do { \
+ int _s = rw_status(&netlock); \
+ if ((splassert_ctl > 0) && (_s == RW_WRITE)) \
+ splassert_fail(0, RW_WRITE, __func__); \
+} while (0)
+
+#define NET_RLOCK() do { rw_enter_read(&netlock); } while (0)
+#define NET_RUNLOCK() do { rw_exit_read(&netlock); } while (0)
+
+#define NET_ASSERT_LOCKED() \
+do { \
+ int _s = rw_status(&netlock); \
+ if ((splassert_ctl > 0) && (_s != RW_WRITE && _s != RW_READ)) \
+ splassert_fail(RW_READ, _s, __func__); \
+} while (0)
+
+__returns_twice int setjmp(label_t *);
+__dead void longjmp(label_t *);
+#endif
+
+void consinit(void);
+
+void cpu_startup(void);
+void cpu_configure(void);
+void diskconf(void);
+
+int nfs_mountroot(void);
+int dk_mountroot(void);
+extern int (*mountroot)(void);
+
+#include <lib/libkern/libkern.h>
+
+#define bzero(b, n) __builtin_bzero((b), (n))
+#define memcmp(b1, b2, n) __builtin_memcmp((b1), (b2), (n))
+#define memcpy(d, s, n) __builtin_memcpy((d), (s), (n))
+#define memset(b, c, n) __builtin_memset((b), (c), (n))
+#if (defined(__GNUC__) && __GNUC__ >= 4)
+#define memmove(d, s, n) __builtin_memmove((d), (s), (n))
+#endif
+#if !defined(__clang__) && (defined(__GNUC__) && __GNUC__ >= 4)
+#define bcmp(b1, b2, n) __builtin_bcmp((b1), (b2), (n))
+#define bcopy(s, d, n) __builtin_bcopy((s), (d), (n))
+#endif
+
+#if defined(DDB)
+/* debugger entry points */
+void db_enter(void); /* in DDB only */
+#endif
+
+#ifdef BOOT_CONFIG
+void user_config(void);
+#endif
+
+#if defined(MULTIPROCESSOR)
+void _kernel_lock_init(void);
+void _kernel_lock(void);
+void _kernel_unlock(void);
+int _kernel_lock_held(void);
+
+#define KERNEL_LOCK_INIT() _kernel_lock_init()
+#define KERNEL_LOCK() _kernel_lock()
+#define KERNEL_UNLOCK() _kernel_unlock()
+#define KERNEL_ASSERT_LOCKED() KASSERT(_kernel_lock_held())
+#define KERNEL_ASSERT_UNLOCKED() KASSERT(!_kernel_lock_held())
+
+#else /* ! MULTIPROCESSOR */
+
+#define KERNEL_LOCK_INIT() /* nothing */
+#define KERNEL_LOCK() /* nothing */
+#define KERNEL_UNLOCK() /* nothing */
+#define KERNEL_ASSERT_LOCKED() /* nothing */
+#define KERNEL_ASSERT_UNLOCKED() /* nothing */
+
+#endif /* MULTIPROCESSOR */
+
+#endif /* __SYSTM_H__ */
diff --git a/sys/sys/task.h b/sys/sys/task.h
new file mode 100644
index 0000000..222c2a7
--- /dev/null
+++ b/sys/sys/task.h
@@ -0,0 +1,60 @@
+/* $OpenBSD: task.h,v 1.16 2019/06/23 12:56:10 kettenis Exp $ */
+
+/*
+ * Copyright (c) 2013 David Gwynne <dlg@openbsd.org>
+ *
+ * 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.
+ */
+
+#ifndef _SYS_TASK_H_
+#define _SYS_TASK_H_
+
+#include <sys/queue.h>
+
+struct taskq;
+
+struct task {
+ TAILQ_ENTRY(task) t_entry;
+ void (*t_func)(void *);
+ void *t_arg;
+ unsigned int t_flags;
+};
+
+#define TASK_ONQUEUE 1
+#define TASK_BARRIER 2
+
+TAILQ_HEAD(task_list, task);
+
+#define TASKQ_MPSAFE (1 << 0)
+
+#define TASK_INITIALIZER(_f, _a) {{ NULL, NULL }, (_f), (_a), 0 }
+
+#ifdef _KERNEL
+extern struct taskq *const systq;
+extern struct taskq *const systqmp;
+
+struct taskq *taskq_create(const char *, unsigned int, int, unsigned int);
+void taskq_destroy(struct taskq *);
+void taskq_barrier(struct taskq *);
+
+void taskq_del_barrier(struct taskq *, struct task *);
+
+void task_set(struct task *, void (*)(void *), void *);
+int task_add(struct taskq *, struct task *);
+int task_del(struct taskq *, struct task *);
+
+#define task_pending(_t) ((_t)->t_flags & TASK_ONQUEUE)
+
+#endif /* _KERNEL */
+
+#endif /* _SYS_TASK_H_ */
diff --git a/sys/sys/termios.h b/sys/sys/termios.h
new file mode 100644
index 0000000..af21a97
--- /dev/null
+++ b/sys/sys/termios.h
@@ -0,0 +1,299 @@
+/* $OpenBSD: termios.h,v 1.13 2016/09/20 21:10:22 fcambus Exp $ */
+/* $NetBSD: termios.h,v 1.14 1996/04/09 20:55:41 cgd Exp $ */
+
+/*
+ * Copyright (c) 1988, 1989, 1993, 1994
+ * 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.
+ *
+ * @(#)termios.h 8.3 (Berkeley) 3/28/94
+ */
+
+#ifndef _SYS_TERMIOS_H_
+#define _SYS_TERMIOS_H_
+
+#include <sys/cdefs.h>
+
+/*
+ * Special Control Characters
+ *
+ * Index into c_cc[] character array.
+ *
+ * Name Subscript Enabled by
+ */
+#define VEOF 0 /* ICANON */
+#define VEOL 1 /* ICANON */
+#if __BSD_VISIBLE
+#define VEOL2 2 /* ICANON */
+#endif
+#define VERASE 3 /* ICANON */
+#if __BSD_VISIBLE
+#define VWERASE 4 /* ICANON */
+#endif
+#define VKILL 5 /* ICANON */
+#if __BSD_VISIBLE
+#define VREPRINT 6 /* ICANON */
+#endif
+/* 7 spare 1 */
+#define VINTR 8 /* ISIG */
+#define VQUIT 9 /* ISIG */
+#define VSUSP 10 /* ISIG */
+#if __BSD_VISIBLE
+#define VDSUSP 11 /* ISIG */
+#endif
+#define VSTART 12 /* IXON, IXOFF */
+#define VSTOP 13 /* IXON, IXOFF */
+#if __BSD_VISIBLE
+#define VLNEXT 14 /* IEXTEN */
+#define VDISCARD 15 /* IEXTEN */
+#endif
+#define VMIN 16 /* !ICANON */
+#define VTIME 17 /* !ICANON */
+#if __BSD_VISIBLE
+#define VSTATUS 18 /* ICANON */
+/* 19 spare 2 */
+#endif
+#define NCCS 20
+
+#define _POSIX_VDISABLE (0377)
+
+#if __BSD_VISIBLE
+#define CCEQ(val, c) (c == val ? val != _POSIX_VDISABLE : 0)
+#endif
+
+/*
+ * Input flags - software input processing
+ */
+#define IGNBRK 0x00000001 /* ignore BREAK condition */
+#define BRKINT 0x00000002 /* map BREAK to SIGINT */
+#define IGNPAR 0x00000004 /* ignore (discard) parity errors */
+#define PARMRK 0x00000008 /* mark parity and framing errors */
+#define INPCK 0x00000010 /* enable checking of parity errors */
+#define ISTRIP 0x00000020 /* strip 8th bit off chars */
+#define INLCR 0x00000040 /* map NL into CR */
+#define IGNCR 0x00000080 /* ignore CR */
+#define ICRNL 0x00000100 /* map CR to NL (ala CRMOD) */
+#define IXON 0x00000200 /* enable output flow control */
+#define IXOFF 0x00000400 /* enable input flow control */
+#if __BSD_VISIBLE
+#define IXANY 0x00000800 /* any char will restart after stop */
+#define IUCLC 0x00001000 /* translate upper to lower case */
+#define IMAXBEL 0x00002000 /* ring bell on input queue full */
+#endif /* __BSD_VISIBLE */
+
+/*
+ * Output flags - software output processing
+ */
+#define OPOST 0x00000001 /* enable following output processing */
+#if __XPG_VISIBLE
+#define ONLCR 0x00000002 /* map NL to CR-NL (ala CRMOD) */
+#endif
+#if __BSD_VISIBLE
+#define OXTABS 0x00000004 /* expand tabs to spaces */
+#define ONOEOT 0x00000008 /* discard EOT's (^D) on output */
+#endif
+#if __XPG_VISIBLE
+#define OCRNL 0x00000010 /* map CR to NL */
+#define OLCUC 0x00000020 /* translate lower case to upper case */
+#define ONOCR 0x00000040 /* No CR output at column 0 */
+#define ONLRET 0x00000080 /* NL performs the CR function */
+#endif /* __XPG_VISIBLE */
+
+/*
+ * Control flags - hardware control of terminal
+ */
+#if __BSD_VISIBLE
+#define CIGNORE 0x00000001 /* ignore control flags */
+#endif
+#define CSIZE 0x00000300 /* character size mask */
+#define CS5 0x00000000 /* 5 bits (pseudo) */
+#define CS6 0x00000100 /* 6 bits */
+#define CS7 0x00000200 /* 7 bits */
+#define CS8 0x00000300 /* 8 bits */
+#define CSTOPB 0x00000400 /* send 2 stop bits */
+#define CREAD 0x00000800 /* enable receiver */
+#define PARENB 0x00001000 /* parity enable */
+#define PARODD 0x00002000 /* odd parity, else even */
+#define HUPCL 0x00004000 /* hang up on last close */
+#define CLOCAL 0x00008000 /* ignore modem status lines */
+#if __BSD_VISIBLE
+#define CRTSCTS 0x00010000 /* RTS/CTS full-duplex flow control */
+#define CRTS_IFLOW CRTSCTS /* XXX compat */
+#define CCTS_OFLOW CRTSCTS /* XXX compat */
+#define MDMBUF 0x00100000 /* DTR/DCD hardware flow control */
+#define CHWFLOW (MDMBUF|CRTSCTS) /* all types of hw flow control */
+#endif /* __BSD_VISIBLE */
+
+/*
+ * "Local" flags - dumping ground for other state
+ *
+ * Warning: some flags in this structure begin with
+ * the letter "I" and look like they belong in the
+ * input flag.
+ */
+
+#if __BSD_VISIBLE
+#define ECHOKE 0x00000001 /* visual erase for line kill */
+#endif
+#define ECHOE 0x00000002 /* visually erase chars */
+#define ECHOK 0x00000004 /* echo NL after line kill */
+#define ECHO 0x00000008 /* enable echoing */
+#define ECHONL 0x00000010 /* echo NL even if ECHO is off */
+#if __BSD_VISIBLE
+#define ECHOPRT 0x00000020 /* visual erase mode for hardcopy */
+#define ECHOCTL 0x00000040 /* echo control chars as ^(Char) */
+#endif
+#define ISIG 0x00000080 /* enable signals INTR, QUIT, [D]SUSP */
+#define ICANON 0x00000100 /* canonicalize input lines */
+#if __BSD_VISIBLE
+#define ALTWERASE 0x00000200 /* use alternate WERASE algorithm */
+#endif
+#define IEXTEN 0x00000400 /* enable DISCARD and LNEXT */
+#define EXTPROC 0x00000800 /* external processing */
+#define TOSTOP 0x00400000 /* stop background jobs from output */
+#if __BSD_VISIBLE
+#define FLUSHO 0x00800000 /* output being flushed (state) */
+#define XCASE 0x01000000 /* canonical upper/lower case */
+#define NOKERNINFO 0x02000000 /* no kernel output from VSTATUS */
+#define PENDIN 0x20000000 /* XXX retype pending input (state) */
+#endif
+#define NOFLSH 0x80000000 /* don't flush after interrupt */
+
+typedef unsigned int tcflag_t;
+typedef unsigned char cc_t;
+typedef unsigned int speed_t;
+
+struct termios {
+ tcflag_t c_iflag; /* input flags */
+ tcflag_t c_oflag; /* output flags */
+ tcflag_t c_cflag; /* control flags */
+ tcflag_t c_lflag; /* local flags */
+ cc_t c_cc[NCCS]; /* control chars */
+ int c_ispeed; /* input speed */
+ int c_ospeed; /* output speed */
+};
+
+/*
+ * Commands passed to tcsetattr() for setting the termios structure.
+ */
+#define TCSANOW 0 /* make change immediate */
+#define TCSADRAIN 1 /* drain output, then change */
+#define TCSAFLUSH 2 /* drain output, flush input */
+#if __BSD_VISIBLE
+#define TCSASOFT 0x10 /* flag - don't alter h.w. state */
+#endif
+
+/*
+ * Standard speeds
+ */
+#define B0 0
+#define B50 50
+#define B75 75
+#define B110 110
+#define B134 134
+#define B150 150
+#define B200 200
+#define B300 300
+#define B600 600
+#define B1200 1200
+#define B1800 1800
+#define B2400 2400
+#define B4800 4800
+#define B9600 9600
+#define B19200 19200
+#define B38400 38400
+#if __BSD_VISIBLE
+#define B7200 7200
+#define B14400 14400
+#define B28800 28800
+#define B57600 57600
+#define B76800 76800
+#define B115200 115200
+#define B230400 230400
+#define EXTA 19200
+#define EXTB 38400
+#endif /* __BSD_VISIBLE */
+
+#ifndef _KERNEL
+
+#define TCIFLUSH 1
+#define TCOFLUSH 2
+#define TCIOFLUSH 3
+#define TCOOFF 1
+#define TCOON 2
+#define TCIOFF 3
+#define TCION 4
+
+#include <sys/_types.h>
+
+#if __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200809
+#ifndef _PID_T_DEFINED_
+#define _PID_T_DEFINED_
+typedef __pid_t pid_t;
+#endif
+#endif
+
+__BEGIN_DECLS
+speed_t cfgetispeed(const struct termios *);
+speed_t cfgetospeed(const struct termios *);
+int cfsetispeed(struct termios *, speed_t);
+int cfsetospeed(struct termios *, speed_t);
+int tcgetattr(int, struct termios *);
+int tcsetattr(int, int, const struct termios *);
+int tcdrain(int);
+int tcflow(int, int);
+int tcflush(int, int);
+int tcsendbreak(int, int);
+
+#if __XPG_VISIBLE >= 420 || __POSIX_VISIBLE >= 200809
+pid_t tcgetsid(int);
+#endif
+
+#if __BSD_VISIBLE
+void cfmakeraw(struct termios *);
+int cfsetspeed(struct termios *, speed_t);
+#endif /* __BSD_VISIBLE */
+__END_DECLS
+
+#endif /* !_KERNEL */
+
+#if __BSD_VISIBLE
+/*
+ * Include tty ioctl's that aren't just for backwards compatibility
+ * with the old tty driver. These ioctl definitions were previously
+ * in <sys/ioctl.h>.
+ */
+#include <sys/ttycom.h>
+#endif
+
+/*
+ * END OF PROTECTED INCLUDE.
+ */
+#endif /* !_SYS_TERMIOS_H_ */
+
+#if __BSD_VISIBLE
+#include <sys/ttydefaults.h>
+#endif
diff --git a/sys/sys/time.h b/sys/sys/time.h
new file mode 100644
index 0000000..564bae3
--- /dev/null
+++ b/sys/sys/time.h
@@ -0,0 +1,418 @@
+/* $OpenBSD: time.h,v 1.50 2020/01/15 13:17:35 mpi Exp $ */
+/* $NetBSD: time.h,v 1.18 1996/04/23 10:29:33 mycroft 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.
+ * 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.
+ *
+ * @(#)time.h 8.2 (Berkeley) 7/10/94
+ */
+
+#ifndef _SYS_TIME_H_
+#define _SYS_TIME_H_
+
+#include <sys/select.h>
+
+#ifndef _TIMEVAL_DECLARED
+#define _TIMEVAL_DECLARED
+/*
+ * Structure returned by gettimeofday(2) system call,
+ * and used in other calls.
+ */
+struct timeval {
+ time_t tv_sec; /* seconds */
+ suseconds_t tv_usec; /* and microseconds */
+};
+#endif
+
+#ifndef _TIMESPEC_DECLARED
+#define _TIMESPEC_DECLARED
+/*
+ * Structure defined by POSIX.1b to be like a timeval.
+ */
+struct timespec {
+ time_t tv_sec; /* seconds */
+ long tv_nsec; /* and nanoseconds */
+};
+#endif
+
+#define TIMEVAL_TO_TIMESPEC(tv, ts) do { \
+ (ts)->tv_sec = (tv)->tv_sec; \
+ (ts)->tv_nsec = (tv)->tv_usec * 1000; \
+} while (0)
+#define TIMESPEC_TO_TIMEVAL(tv, ts) do { \
+ (tv)->tv_sec = (ts)->tv_sec; \
+ (tv)->tv_usec = (ts)->tv_nsec / 1000; \
+} while (0)
+
+struct timezone {
+ int tz_minuteswest; /* minutes west of Greenwich */
+ int tz_dsttime; /* type of dst correction */
+};
+#define DST_NONE 0 /* not on dst */
+#define DST_USA 1 /* USA style dst */
+#define DST_AUST 2 /* Australian style dst */
+#define DST_WET 3 /* Western European dst */
+#define DST_MET 4 /* Middle European dst */
+#define DST_EET 5 /* Eastern European dst */
+#define DST_CAN 6 /* Canada */
+
+/* Operations on timevals. */
+#define timerclear(tvp) (tvp)->tv_sec = (tvp)->tv_usec = 0
+#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
+#define timerisvalid(tvp) \
+ ((tvp)->tv_usec >= 0 && (tvp)->tv_usec < 1000000)
+#define timercmp(tvp, uvp, cmp) \
+ (((tvp)->tv_sec == (uvp)->tv_sec) ? \
+ ((tvp)->tv_usec cmp (uvp)->tv_usec) : \
+ ((tvp)->tv_sec cmp (uvp)->tv_sec))
+#define timeradd(tvp, uvp, vvp) \
+ do { \
+ (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \
+ (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \
+ if ((vvp)->tv_usec >= 1000000) { \
+ (vvp)->tv_sec++; \
+ (vvp)->tv_usec -= 1000000; \
+ } \
+ } while (0)
+#define timersub(tvp, uvp, vvp) \
+ do { \
+ (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \
+ (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \
+ if ((vvp)->tv_usec < 0) { \
+ (vvp)->tv_sec--; \
+ (vvp)->tv_usec += 1000000; \
+ } \
+ } while (0)
+
+/* Operations on timespecs. */
+#define timespecclear(tsp) (tsp)->tv_sec = (tsp)->tv_nsec = 0
+#define timespecisset(tsp) ((tsp)->tv_sec || (tsp)->tv_nsec)
+#define timespecisvalid(tsp) \
+ ((tsp)->tv_nsec >= 0 && (tsp)->tv_nsec < 1000000000L)
+#define timespeccmp(tsp, usp, cmp) \
+ (((tsp)->tv_sec == (usp)->tv_sec) ? \
+ ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \
+ ((tsp)->tv_sec cmp (usp)->tv_sec))
+#define timespecadd(tsp, usp, vsp) \
+ do { \
+ (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \
+ (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \
+ if ((vsp)->tv_nsec >= 1000000000L) { \
+ (vsp)->tv_sec++; \
+ (vsp)->tv_nsec -= 1000000000L; \
+ } \
+ } while (0)
+#define timespecsub(tsp, usp, vsp) \
+ do { \
+ (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \
+ (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \
+ if ((vsp)->tv_nsec < 0) { \
+ (vsp)->tv_sec--; \
+ (vsp)->tv_nsec += 1000000000L; \
+ } \
+ } while (0)
+
+/*
+ * Names of the interval timers, and structure
+ * defining a timer setting.
+ */
+#define ITIMER_REAL 0
+#define ITIMER_VIRTUAL 1
+#define ITIMER_PROF 2
+
+struct itimerval {
+ struct timeval it_interval; /* timer interval */
+ struct timeval it_value; /* current value */
+};
+
+#if __BSD_VISIBLE
+/*
+ * clock information structure for sysctl({CTL_KERN, KERN_CLOCKRATE})
+ */
+struct clockinfo {
+ int hz; /* clock frequency */
+ int tick; /* micro-seconds per hz tick */
+ int tickadj; /* clock skew rate for adjtime() */
+ int stathz; /* statistics clock frequency */
+ int profhz; /* profiling clock frequency */
+};
+#endif /* __BSD_VISIBLE */
+
+#if defined(_KERNEL) || defined(_STANDALONE)
+#include <sys/_time.h>
+
+/* Time expressed as seconds and fractions of a second + operations on it. */
+struct bintime {
+ time_t sec;
+ uint64_t frac;
+};
+
+#define bintimecmp(btp, ctp, cmp) \
+ ((btp)->sec == (ctp)->sec ? \
+ (btp)->frac cmp (ctp)->frac : \
+ (btp)->sec cmp (ctp)->sec)
+
+static inline void
+bintimeaddfrac(const struct bintime *bt, uint64_t x, struct bintime *ct)
+{
+ ct->sec = bt->sec;
+ if (bt->frac > bt->frac + x)
+ ct->sec++;
+ ct->frac = bt->frac + x;
+}
+
+static inline void
+bintimeadd(const struct bintime *bt, const struct bintime *ct,
+ struct bintime *dt)
+{
+ dt->sec = bt->sec + ct->sec;
+ if (bt->frac > bt->frac + ct->frac)
+ dt->sec++;
+ dt->frac = bt->frac + ct->frac;
+}
+
+static inline void
+bintimesub(const struct bintime *bt, const struct bintime *ct,
+ struct bintime *dt)
+{
+ dt->sec = bt->sec - ct->sec;
+ if (bt->frac < bt->frac - ct->frac)
+ dt->sec--;
+ dt->frac = bt->frac - ct->frac;
+}
+
+/*-
+ * Background information:
+ *
+ * When converting between timestamps on parallel timescales of differing
+ * resolutions it is historical and scientific practice to round down rather
+ * than doing 4/5 rounding.
+ *
+ * The date changes at midnight, not at noon.
+ *
+ * Even at 15:59:59.999999999 it's not four'o'clock.
+ *
+ * time_second ticks after N.999999999 not after N.4999999999
+ */
+
+static inline void
+BINTIME_TO_TIMESPEC(const struct bintime *bt, struct timespec *ts)
+{
+ ts->tv_sec = bt->sec;
+ ts->tv_nsec = (long)(((uint64_t)1000000000 * (uint32_t)(bt->frac >> 32)) >> 32);
+}
+
+static inline void
+TIMESPEC_TO_BINTIME(const struct timespec *ts, struct bintime *bt)
+{
+ bt->sec = ts->tv_sec;
+ /* 18446744073 = int(2^64 / 1000000000) */
+ bt->frac = (uint64_t)ts->tv_nsec * (uint64_t)18446744073ULL;
+}
+
+static inline void
+BINTIME_TO_TIMEVAL(const struct bintime *bt, struct timeval *tv)
+{
+ tv->tv_sec = bt->sec;
+ tv->tv_usec = (long)(((uint64_t)1000000 * (uint32_t)(bt->frac >> 32)) >> 32);
+}
+
+static inline void
+TIMEVAL_TO_BINTIME(const struct timeval *tv, struct bintime *bt)
+{
+ bt->sec = (time_t)tv->tv_sec;
+ /* 18446744073709 = int(2^64 / 1000000) */
+ bt->frac = (uint64_t)tv->tv_usec * (uint64_t)18446744073709ULL;
+}
+
+extern volatile time_t time_second; /* Seconds since epoch, wall time. */
+extern volatile time_t time_uptime; /* Seconds since reboot. */
+
+/*
+ * Functions for looking at our clocks: [get]{bin,nano,micro}[boot|up]time()
+ *
+ * Functions without the "get" prefix returns the best timestamp
+ * we can produce in the given format.
+ *
+ * "bin" == struct bintime == seconds + 64 bit fraction of seconds.
+ * "nano" == struct timespec == seconds + nanoseconds.
+ * "micro" == struct timeval == seconds + microseconds.
+ *
+ * Functions containing "up" returns time relative to boot and
+ * should be used for calculating time intervals.
+ *
+ * Functions containing "boot" return the GMT time at which the
+ * system booted.
+ *
+ * Functions with just "time" return the current GMT time.
+ *
+ * Functions with the "get" prefix returns a less precise result
+ * much faster than the functions without "get" prefix and should
+ * be used where a precision of 10 msec is acceptable or where
+ * performance is priority. (NB: "precision", _not_ "resolution" !)
+ */
+
+void bintime(struct bintime *);
+void nanotime(struct timespec *);
+void microtime(struct timeval *);
+
+void getnanotime(struct timespec *);
+void getmicrotime(struct timeval *);
+
+void binuptime(struct bintime *);
+void nanouptime(struct timespec *);
+void microuptime(struct timeval *);
+
+void getnanouptime(struct timespec *);
+void getmicrouptime(struct timeval *);
+
+void binboottime(struct bintime *);
+void microboottime(struct timeval *);
+void nanoboottime(struct timespec *);
+
+struct proc;
+int clock_gettime(struct proc *, clockid_t, struct timespec *);
+
+int itimerfix(struct timeval *);
+int itimerdecr(struct itimerspec *, long);
+int settime(const struct timespec *);
+int ratecheck(struct timeval *, const struct timeval *);
+int ppsratecheck(struct timeval *, int *, int);
+
+/*
+ * "POSIX time" to/from "YY/MM/DD/hh/mm/ss"
+ */
+struct clock_ymdhms {
+ u_short dt_year;
+ u_char dt_mon;
+ u_char dt_day;
+ u_char dt_wday; /* Day of week */
+ u_char dt_hour;
+ u_char dt_min;
+ u_char dt_sec;
+};
+
+time_t clock_ymdhms_to_secs(struct clock_ymdhms *);
+void clock_secs_to_ymdhms(time_t, struct clock_ymdhms *);
+/*
+ * BCD to decimal and decimal to BCD.
+ */
+#define FROMBCD(x) (((x) >> 4) * 10 + ((x) & 0xf))
+#define TOBCD(x) (((x) / 10 * 16) + ((x) % 10))
+
+/* Some handy constants. */
+#define SECDAY 86400L
+#define SECYR (SECDAY * 365)
+
+/* Traditional POSIX base year */
+#define POSIX_BASE_YEAR 1970
+
+#include <sys/stdint.h>
+
+static inline void
+NSEC_TO_TIMEVAL(uint64_t ns, struct timeval *tv)
+{
+ tv->tv_sec = ns / 1000000000L;
+ tv->tv_usec = (ns % 1000000000L) / 1000;
+}
+
+static inline uint64_t
+TIMEVAL_TO_NSEC(const struct timeval *tv)
+{
+ uint64_t nsecs;
+
+ if (tv->tv_sec > UINT64_MAX / 1000000000ULL)
+ return UINT64_MAX;
+ nsecs = tv->tv_sec * 1000000000ULL;
+ if (tv->tv_usec * 1000ULL > UINT64_MAX - nsecs)
+ return UINT64_MAX;
+ return nsecs + tv->tv_usec * 1000ULL;
+}
+
+static inline void
+NSEC_TO_TIMESPEC(uint64_t ns, struct timespec *ts)
+{
+ ts->tv_sec = ns / 1000000000L;
+ ts->tv_nsec = ns % 1000000000L;
+}
+
+static inline uint64_t
+SEC_TO_NSEC(uint64_t seconds)
+{
+ if (seconds > UINT64_MAX / 1000000000ULL)
+ return UINT64_MAX;
+ return seconds * 1000000000ULL;
+}
+
+static inline uint64_t
+MSEC_TO_NSEC(uint64_t milliseconds)
+{
+ if (milliseconds > UINT64_MAX / 1000000ULL)
+ return UINT64_MAX;
+ return milliseconds * 1000000ULL;
+}
+
+static inline uint64_t
+USEC_TO_NSEC(uint64_t microseconds)
+{
+ if (microseconds > UINT64_MAX / 1000ULL)
+ return UINT64_MAX;
+ return microseconds * 1000ULL;
+}
+
+static inline uint64_t
+TIMESPEC_TO_NSEC(const struct timespec *ts)
+{
+ if (ts->tv_sec > (UINT64_MAX - ts->tv_nsec) / 1000000000ULL)
+ return UINT64_MAX;
+ return ts->tv_sec * 1000000000ULL + ts->tv_nsec;
+}
+
+#else /* !_KERNEL */
+#include <time.h>
+
+#if __BSD_VISIBLE || __XPG_VISIBLE
+__BEGIN_DECLS
+#if __BSD_VISIBLE
+int adjtime(const struct timeval *, struct timeval *);
+int adjfreq(const int64_t *, int64_t *);
+#endif
+#if __XPG_VISIBLE
+int futimes(int, const struct timeval *);
+int getitimer(int, struct itimerval *);
+int gettimeofday(struct timeval *, struct timezone *);
+int setitimer(int, const struct itimerval *, struct itimerval *);
+int settimeofday(const struct timeval *, const struct timezone *);
+int utimes(const char *, const struct timeval *);
+#endif /* __XPG_VISIBLE */
+__END_DECLS
+#endif /* __BSD_VISIBLE || __XPG_VISIBLE */
+
+#endif /* !_KERNEL */
+
+#endif /* !_SYS_TIME_H_ */
diff --git a/sys/sys/timeout.h b/sys/sys/timeout.h
new file mode 100644
index 0000000..1cd9fca
--- /dev/null
+++ b/sys/sys/timeout.h
@@ -0,0 +1,137 @@
+/* $OpenBSD: timeout.h,v 1.36 2020/01/03 02:16:38 cheloha Exp $ */
+/*
+ * Copyright (c) 2000-2001 Artur Grabowski <art@openbsd.org>
+ * 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. 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 _SYS_TIMEOUT_H_
+#define _SYS_TIMEOUT_H_
+
+/*
+ * Interface for handling time driven events in the kernel.
+ *
+ * The basic component of this API is the struct timeout. The user should not
+ * touch the internals of this structure, but it's the users responsibility
+ * to allocate and deallocate timeouts.
+ *
+ * The functions used to manipulate timeouts are:
+ * - timeout_set(timeout, function, argument)
+ * Initializes a timeout struct to call the function with the argument.
+ * A timeout only needs to be initialized once.
+ * - timeout_add(timeout, ticks)
+ * Schedule this timeout to run in "ticks" ticks (there are hz ticks in
+ * one second). You may not touch the timeout with timeout_set once the
+ * timeout is scheduled. A second call to timeout_add with an already
+ * scheduled timeout will cause the old timeout to be canceled and the
+ * new will be scheduled.
+ * - timeout_del(timeout)
+ * Remove the timeout from the timeout queue. It's legal to remove
+ * a timeout that has already happened.
+ *
+ * These functions may be called in interrupt context (anything below splhigh).
+ */
+
+struct circq {
+ struct circq *next; /* next element */
+ struct circq *prev; /* previous element */
+};
+
+struct timeout {
+ struct circq to_list; /* timeout queue, don't move */
+ void (*to_func)(void *); /* function to call */
+ void *to_arg; /* function argument */
+ int to_time; /* ticks on event */
+ int to_flags; /* misc flags */
+};
+
+/*
+ * flags in the to_flags field.
+ */
+#define TIMEOUT_PROC 0x01 /* needs a process context */
+#define TIMEOUT_ONQUEUE 0x02 /* on any timeout queue */
+#define TIMEOUT_INITIALIZED 0x04 /* initialized */
+#define TIMEOUT_TRIGGERED 0x08 /* running or ran */
+#define TIMEOUT_SCHEDULED 0x10 /* put on wheel at least once */
+
+struct timeoutstat {
+ uint64_t tos_added; /* timeout_add*(9) calls */
+ uint64_t tos_cancelled; /* dequeued during timeout_del*(9) */
+ uint64_t tos_deleted; /* timeout_del*(9) calls */
+ uint64_t tos_late; /* run after deadline */
+ uint64_t tos_pending; /* number currently ONQUEUE */
+ uint64_t tos_readded; /* timeout_add*(9) + already ONQUEUE */
+ uint64_t tos_rescheduled; /* bucketed + already SCHEDULED */
+ uint64_t tos_run_softclock; /* run from softclock() */
+ uint64_t tos_run_thread; /* run from softclock_thread() */
+ uint64_t tos_scheduled; /* bucketed during softclock() */
+ uint64_t tos_softclocks; /* softclock() calls */
+ uint64_t tos_thread_wakeups; /* wakeups in softclock_thread() */
+};
+
+#ifdef _KERNEL
+int timeout_sysctl(void *, size_t *, void *, size_t);
+
+/*
+ * special macros
+ *
+ * timeout_pending(to) - is this timeout already scheduled to run?
+ * timeout_initialized(to) - is this timeout initialized?
+ */
+#define timeout_pending(to) ((to)->to_flags & TIMEOUT_ONQUEUE)
+#define timeout_initialized(to) ((to)->to_flags & TIMEOUT_INITIALIZED)
+#define timeout_triggered(to) ((to)->to_flags & TIMEOUT_TRIGGERED)
+
+#define TIMEOUT_INITIALIZER_FLAGS(fn, arg, flags) { \
+ .to_list = { NULL, NULL }, \
+ .to_func = (fn), \
+ .to_arg = (arg), \
+ .to_time = 0, \
+ .to_flags = (flags) | TIMEOUT_INITIALIZED \
+}
+
+#define TIMEOUT_INITIALIZER(_f, _a) TIMEOUT_INITIALIZER_FLAGS((_f), (_a), 0)
+
+struct bintime;
+
+void timeout_set(struct timeout *, void (*)(void *), void *);
+void timeout_set_flags(struct timeout *, void (*)(void *), void *, int);
+void timeout_set_proc(struct timeout *, void (*)(void *), void *);
+int timeout_add(struct timeout *, int);
+int timeout_add_tv(struct timeout *, const struct timeval *);
+int timeout_add_ts(struct timeout *, const struct timespec *);
+int timeout_add_bt(struct timeout *, const struct bintime *);
+int timeout_add_sec(struct timeout *, int);
+int timeout_add_msec(struct timeout *, int);
+int timeout_add_usec(struct timeout *, int);
+int timeout_add_nsec(struct timeout *, int);
+int timeout_del(struct timeout *);
+int timeout_del_barrier(struct timeout *);
+void timeout_barrier(struct timeout *);
+
+void timeout_adjust_ticks(int);
+void timeout_hardclock_update(void);
+void timeout_startup(void);
+
+#endif /* _KERNEL */
+
+#endif /* _SYS_TIMEOUT_H_ */
diff --git a/sys/sys/times.h b/sys/sys/times.h
new file mode 100644
index 0000000..4781ffd
--- /dev/null
+++ b/sys/sys/times.h
@@ -0,0 +1,63 @@
+/* $OpenBSD: times.h,v 1.6 2013/07/06 18:44:21 naddy Exp $ */
+/* $NetBSD: times.h,v 1.8 1995/03/26 20:24:54 jtc Exp $ */
+
+/*-
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)times.h 8.4 (Berkeley) 1/21/94
+ */
+
+#ifndef _SYS_TIMES_H_
+#define _SYS_TIMES_H_
+
+#include <sys/cdefs.h>
+#include <sys/_types.h>
+
+#ifndef _CLOCK_T_DEFINED_
+#define _CLOCK_T_DEFINED_
+typedef __clock_t clock_t;
+#endif
+
+struct tms {
+ clock_t tms_utime; /* User CPU time */
+ clock_t tms_stime; /* System CPU time */
+ clock_t tms_cutime; /* User CPU time of terminated child procs */
+ clock_t tms_cstime; /* System CPU time of terminated child procs */
+};
+
+#ifndef _KERNEL
+__BEGIN_DECLS
+clock_t times(struct tms *);
+__END_DECLS
+#endif
+#endif /* !_SYS_TIMES_H_ */
diff --git a/sys/sys/timetc.h b/sys/sys/timetc.h
new file mode 100644
index 0000000..ce81c34
--- /dev/null
+++ b/sys/sys/timetc.h
@@ -0,0 +1,107 @@
+/* $OpenBSD: timetc.h,v 1.10 2019/10/26 21:16:38 cheloha Exp $ */
+
+/*
+ * Copyright (c) 2000 Poul-Henning Kamp <phk@FreeBSD.org>
+ *
+ * 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.
+ */
+
+/*
+ * If we meet some day, and you think this stuff is worth it, you
+ * can buy me a beer in return. Poul-Henning Kamp
+ */
+
+#ifndef _SYS_TIMETC_H_
+#define _SYS_TIMETC_H_
+
+#ifndef _KERNEL
+#error "no user-serviceable parts inside"
+#endif
+
+#include <sys/queue.h>
+
+/*-
+ * `struct timecounter' is the interface between the hardware which implements
+ * a timecounter and the MI code which uses this to keep track of time.
+ *
+ * A timecounter is a binary counter which has two properties:
+ * * it runs at a fixed, known frequency.
+ * * it has sufficient bits to not roll over in less than approximately
+ * max(2 msec, 2/HZ seconds). (The value 2 here is really 1 + delta,
+ * for some indeterminate value of delta.)
+ */
+
+struct timecounter;
+typedef u_int timecounter_get_t(struct timecounter *);
+typedef void timecounter_pps_t(struct timecounter *);
+
+/*
+ * Locks used to protect struct members in this file:
+ * I immutable after initialization
+ * t tc_lock
+ * w windup_mtx
+ */
+
+struct timecounter {
+ timecounter_get_t *tc_get_timecount; /* [I] */
+ /*
+ * This function reads the counter. It is not required to
+ * mask any unimplemented bits out, as long as they are
+ * constant.
+ */
+ timecounter_pps_t *tc_poll_pps; /* [I] */
+ /*
+ * This function is optional. It will be called whenever the
+ * timecounter is rewound, and is intended to check for PPS
+ * events. Normal hardware does not need it but timecounters
+ * which latch PPS in hardware (like sys/pci/xrpu.c) do.
+ */
+ u_int tc_counter_mask; /* [I] */
+ /* This mask should mask off any unimplemented bits. */
+ u_int64_t tc_frequency; /* [I] */
+ /* Frequency of the counter in Hz. */
+ char *tc_name; /* [I] */
+ /* Name of the timecounter. */
+ int tc_quality; /* [I] */
+ /*
+ * Used to determine if this timecounter is better than
+ * another timecounter higher means better. Negative
+ * means "only use at explicit request".
+ */
+ void *tc_priv; /* [I] */
+ /* Pointer to the timecounter's private parts. */
+ SLIST_ENTRY(timecounter) tc_next; /* [I] */
+ /* Pointer to the next timecounter. */
+ int64_t tc_freq_adj; /* [tw] */
+ /* Current frequency adjustment. */
+ u_int64_t tc_precision; /* [I] */
+ /* Precision of the counter. Computed in tc_init(). */
+};
+
+struct rwlock;
+extern struct rwlock tc_lock;
+
+extern struct timecounter *timecounter;
+
+u_int64_t tc_getfrequency(void);
+u_int64_t tc_getprecision(void);
+void tc_init(struct timecounter *tc);
+void tc_setclock(const struct timespec *ts);
+void tc_setrealtimeclock(const struct timespec *ts);
+void tc_ticktock(void);
+void inittimecounter(void);
+int sysctl_tc(int *, u_int, void *, size_t *, void *, size_t);
+void tc_adjfreq(int64_t *, int64_t *);
+void tc_adjtime(int64_t *, int64_t *);
+
+#endif /* !_SYS_TIMETC_H_ */
diff --git a/sys/sys/tprintf.h b/sys/sys/tprintf.h
new file mode 100644
index 0000000..e17877c
--- /dev/null
+++ b/sys/sys/tprintf.h
@@ -0,0 +1,41 @@
+/* $OpenBSD: tprintf.h,v 1.6 2003/08/24 01:27:07 avsm Exp $ */
+/* $NetBSD: tprintf.h,v 1.10 1996/04/09 20:55:43 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1990, 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.
+ *
+ * @(#)tprintf.h 8.1 (Berkeley) 6/2/93
+ */
+
+typedef struct session *tpr_t;
+
+tpr_t tprintf_open(struct proc *);
+void tprintf_close(tpr_t);
+
+void tprintf(tpr_t, const char *fmt, ...)
+ __attribute__((__format__(__kprintf__,2,3)));
diff --git a/sys/sys/tracepoint.h b/sys/sys/tracepoint.h
new file mode 100644
index 0000000..d9a674a
--- /dev/null
+++ b/sys/sys/tracepoint.h
@@ -0,0 +1,36 @@
+/* $OpenBSD: tracepoint.h,v 1.1 2020/01/21 16:16:23 mpi Exp $ */
+
+/*
+ * Copyright (c) 2019 Martin Pieuchot <mpi@openbsd.org>
+ *
+ * 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.
+ */
+
+#ifndef _SYS_TRACEPOINT_H_
+#define _SYS_TRACEPOINT_H_
+
+#ifdef _KERNEL
+
+#include "dt.h"
+#if NDT > 0
+#include <dev/dt/dtvar.h>
+
+#define TRACEPOINT(func, name, args...) DT_STATIC_ENTER(func, name, args)
+
+#else /* NDT > 0 */
+
+#define TRACEPOINT(func, name, args...)
+
+#endif /* NDT > 0 */
+#endif /* _KERNEL */
+#endif /* _SYS_TRACEPOINT_H_ */
diff --git a/sys/sys/tree.h b/sys/sys/tree.h
new file mode 100644
index 0000000..ffcac90
--- /dev/null
+++ b/sys/sys/tree.h
@@ -0,0 +1,1006 @@
+/* $OpenBSD: tree.h,v 1.29 2017/07/30 19:27:20 deraadt Exp $ */
+/*
+ * Copyright 2002 Niels Provos <provos@citi.umich.edu>
+ * 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.
+ */
+
+#ifndef _SYS_TREE_H_
+#define _SYS_TREE_H_
+
+#include <sys/_null.h>
+
+/*
+ * This file defines data structures for different types of trees:
+ * splay trees and red-black trees.
+ *
+ * A splay tree is a self-organizing data structure. Every operation
+ * on the tree causes a splay to happen. The splay moves the requested
+ * node to the root of the tree and partly rebalances it.
+ *
+ * This has the benefit that request locality causes faster lookups as
+ * the requested nodes move to the top of the tree. On the other hand,
+ * every lookup causes memory writes.
+ *
+ * The Balance Theorem bounds the total access time for m operations
+ * and n inserts on an initially empty tree as O((m + n)lg n). The
+ * amortized cost for a sequence of m accesses to a splay tree is O(lg n);
+ *
+ * A red-black tree is a binary search tree with the node color as an
+ * extra attribute. It fulfills a set of conditions:
+ * - every search path from the root to a leaf consists of the
+ * same number of black nodes,
+ * - each red node (except for the root) has a black parent,
+ * - each leaf node is black.
+ *
+ * Every operation on a red-black tree is bounded as O(lg n).
+ * The maximum height of a red-black tree is 2lg (n+1).
+ */
+
+#define SPLAY_HEAD(name, type) \
+struct name { \
+ struct type *sph_root; /* root of the tree */ \
+}
+
+#define SPLAY_INITIALIZER(root) \
+ { NULL }
+
+#define SPLAY_INIT(root) do { \
+ (root)->sph_root = NULL; \
+} while (0)
+
+#define SPLAY_ENTRY(type) \
+struct { \
+ struct type *spe_left; /* left element */ \
+ struct type *spe_right; /* right element */ \
+}
+
+#define SPLAY_LEFT(elm, field) (elm)->field.spe_left
+#define SPLAY_RIGHT(elm, field) (elm)->field.spe_right
+#define SPLAY_ROOT(head) (head)->sph_root
+#define SPLAY_EMPTY(head) (SPLAY_ROOT(head) == NULL)
+
+/* SPLAY_ROTATE_{LEFT,RIGHT} expect that tmp hold SPLAY_{RIGHT,LEFT} */
+#define SPLAY_ROTATE_RIGHT(head, tmp, field) do { \
+ SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(tmp, field); \
+ SPLAY_RIGHT(tmp, field) = (head)->sph_root; \
+ (head)->sph_root = tmp; \
+} while (0)
+
+#define SPLAY_ROTATE_LEFT(head, tmp, field) do { \
+ SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(tmp, field); \
+ SPLAY_LEFT(tmp, field) = (head)->sph_root; \
+ (head)->sph_root = tmp; \
+} while (0)
+
+#define SPLAY_LINKLEFT(head, tmp, field) do { \
+ SPLAY_LEFT(tmp, field) = (head)->sph_root; \
+ tmp = (head)->sph_root; \
+ (head)->sph_root = SPLAY_LEFT((head)->sph_root, field); \
+} while (0)
+
+#define SPLAY_LINKRIGHT(head, tmp, field) do { \
+ SPLAY_RIGHT(tmp, field) = (head)->sph_root; \
+ tmp = (head)->sph_root; \
+ (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field); \
+} while (0)
+
+#define SPLAY_ASSEMBLE(head, node, left, right, field) do { \
+ SPLAY_RIGHT(left, field) = SPLAY_LEFT((head)->sph_root, field); \
+ SPLAY_LEFT(right, field) = SPLAY_RIGHT((head)->sph_root, field);\
+ SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(node, field); \
+ SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(node, field); \
+} while (0)
+
+/* Generates prototypes and inline functions */
+
+#define SPLAY_PROTOTYPE(name, type, field, cmp) \
+void name##_SPLAY(struct name *, struct type *); \
+void name##_SPLAY_MINMAX(struct name *, int); \
+struct type *name##_SPLAY_INSERT(struct name *, struct type *); \
+struct type *name##_SPLAY_REMOVE(struct name *, struct type *); \
+ \
+/* Finds the node with the same key as elm */ \
+static __unused __inline struct type * \
+name##_SPLAY_FIND(struct name *head, struct type *elm) \
+{ \
+ if (SPLAY_EMPTY(head)) \
+ return(NULL); \
+ name##_SPLAY(head, elm); \
+ if ((cmp)(elm, (head)->sph_root) == 0) \
+ return (head->sph_root); \
+ return (NULL); \
+} \
+ \
+static __unused __inline struct type * \
+name##_SPLAY_NEXT(struct name *head, struct type *elm) \
+{ \
+ name##_SPLAY(head, elm); \
+ if (SPLAY_RIGHT(elm, field) != NULL) { \
+ elm = SPLAY_RIGHT(elm, field); \
+ while (SPLAY_LEFT(elm, field) != NULL) { \
+ elm = SPLAY_LEFT(elm, field); \
+ } \
+ } else \
+ elm = NULL; \
+ return (elm); \
+} \
+ \
+static __unused __inline struct type * \
+name##_SPLAY_MIN_MAX(struct name *head, int val) \
+{ \
+ name##_SPLAY_MINMAX(head, val); \
+ return (SPLAY_ROOT(head)); \
+}
+
+/* Main splay operation.
+ * Moves node close to the key of elm to top
+ */
+#define SPLAY_GENERATE(name, type, field, cmp) \
+struct type * \
+name##_SPLAY_INSERT(struct name *head, struct type *elm) \
+{ \
+ if (SPLAY_EMPTY(head)) { \
+ SPLAY_LEFT(elm, field) = SPLAY_RIGHT(elm, field) = NULL; \
+ } else { \
+ int __comp; \
+ name##_SPLAY(head, elm); \
+ __comp = (cmp)(elm, (head)->sph_root); \
+ if(__comp < 0) { \
+ SPLAY_LEFT(elm, field) = SPLAY_LEFT((head)->sph_root, field);\
+ SPLAY_RIGHT(elm, field) = (head)->sph_root; \
+ SPLAY_LEFT((head)->sph_root, field) = NULL; \
+ } else if (__comp > 0) { \
+ SPLAY_RIGHT(elm, field) = SPLAY_RIGHT((head)->sph_root, field);\
+ SPLAY_LEFT(elm, field) = (head)->sph_root; \
+ SPLAY_RIGHT((head)->sph_root, field) = NULL; \
+ } else \
+ return ((head)->sph_root); \
+ } \
+ (head)->sph_root = (elm); \
+ return (NULL); \
+} \
+ \
+struct type * \
+name##_SPLAY_REMOVE(struct name *head, struct type *elm) \
+{ \
+ struct type *__tmp; \
+ if (SPLAY_EMPTY(head)) \
+ return (NULL); \
+ name##_SPLAY(head, elm); \
+ if ((cmp)(elm, (head)->sph_root) == 0) { \
+ if (SPLAY_LEFT((head)->sph_root, field) == NULL) { \
+ (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field);\
+ } else { \
+ __tmp = SPLAY_RIGHT((head)->sph_root, field); \
+ (head)->sph_root = SPLAY_LEFT((head)->sph_root, field);\
+ name##_SPLAY(head, elm); \
+ SPLAY_RIGHT((head)->sph_root, field) = __tmp; \
+ } \
+ return (elm); \
+ } \
+ return (NULL); \
+} \
+ \
+void \
+name##_SPLAY(struct name *head, struct type *elm) \
+{ \
+ struct type __node, *__left, *__right, *__tmp; \
+ int __comp; \
+\
+ SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\
+ __left = __right = &__node; \
+\
+ while ((__comp = (cmp)(elm, (head)->sph_root))) { \
+ if (__comp < 0) { \
+ __tmp = SPLAY_LEFT((head)->sph_root, field); \
+ if (__tmp == NULL) \
+ break; \
+ if ((cmp)(elm, __tmp) < 0){ \
+ SPLAY_ROTATE_RIGHT(head, __tmp, field); \
+ if (SPLAY_LEFT((head)->sph_root, field) == NULL)\
+ break; \
+ } \
+ SPLAY_LINKLEFT(head, __right, field); \
+ } else if (__comp > 0) { \
+ __tmp = SPLAY_RIGHT((head)->sph_root, field); \
+ if (__tmp == NULL) \
+ break; \
+ if ((cmp)(elm, __tmp) > 0){ \
+ SPLAY_ROTATE_LEFT(head, __tmp, field); \
+ if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\
+ break; \
+ } \
+ SPLAY_LINKRIGHT(head, __left, field); \
+ } \
+ } \
+ SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \
+} \
+ \
+/* Splay with either the minimum or the maximum element \
+ * Used to find minimum or maximum element in tree. \
+ */ \
+void name##_SPLAY_MINMAX(struct name *head, int __comp) \
+{ \
+ struct type __node, *__left, *__right, *__tmp; \
+\
+ SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\
+ __left = __right = &__node; \
+\
+ while (1) { \
+ if (__comp < 0) { \
+ __tmp = SPLAY_LEFT((head)->sph_root, field); \
+ if (__tmp == NULL) \
+ break; \
+ if (__comp < 0){ \
+ SPLAY_ROTATE_RIGHT(head, __tmp, field); \
+ if (SPLAY_LEFT((head)->sph_root, field) == NULL)\
+ break; \
+ } \
+ SPLAY_LINKLEFT(head, __right, field); \
+ } else if (__comp > 0) { \
+ __tmp = SPLAY_RIGHT((head)->sph_root, field); \
+ if (__tmp == NULL) \
+ break; \
+ if (__comp > 0) { \
+ SPLAY_ROTATE_LEFT(head, __tmp, field); \
+ if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\
+ break; \
+ } \
+ SPLAY_LINKRIGHT(head, __left, field); \
+ } \
+ } \
+ SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \
+}
+
+#define SPLAY_NEGINF -1
+#define SPLAY_INF 1
+
+#define SPLAY_INSERT(name, x, y) name##_SPLAY_INSERT(x, y)
+#define SPLAY_REMOVE(name, x, y) name##_SPLAY_REMOVE(x, y)
+#define SPLAY_FIND(name, x, y) name##_SPLAY_FIND(x, y)
+#define SPLAY_NEXT(name, x, y) name##_SPLAY_NEXT(x, y)
+#define SPLAY_MIN(name, x) (SPLAY_EMPTY(x) ? NULL \
+ : name##_SPLAY_MIN_MAX(x, SPLAY_NEGINF))
+#define SPLAY_MAX(name, x) (SPLAY_EMPTY(x) ? NULL \
+ : name##_SPLAY_MIN_MAX(x, SPLAY_INF))
+
+#define SPLAY_FOREACH(x, name, head) \
+ for ((x) = SPLAY_MIN(name, head); \
+ (x) != NULL; \
+ (x) = SPLAY_NEXT(name, head, x))
+
+/* Macros that define a red-black tree */
+#define RB_HEAD(name, type) \
+struct name { \
+ struct type *rbh_root; /* root of the tree */ \
+}
+
+#define RB_INITIALIZER(root) \
+ { NULL }
+
+#define RB_INIT(root) do { \
+ (root)->rbh_root = NULL; \
+} while (0)
+
+#define RB_BLACK 0
+#define RB_RED 1
+#define RB_ENTRY(type) \
+struct { \
+ struct type *rbe_left; /* left element */ \
+ struct type *rbe_right; /* right element */ \
+ struct type *rbe_parent; /* parent element */ \
+ int rbe_color; /* node color */ \
+}
+
+#define RB_LEFT(elm, field) (elm)->field.rbe_left
+#define RB_RIGHT(elm, field) (elm)->field.rbe_right
+#define RB_PARENT(elm, field) (elm)->field.rbe_parent
+#define RB_COLOR(elm, field) (elm)->field.rbe_color
+#define RB_ROOT(head) (head)->rbh_root
+#define RB_EMPTY(head) (RB_ROOT(head) == NULL)
+
+#define RB_SET(elm, parent, field) do { \
+ RB_PARENT(elm, field) = parent; \
+ RB_LEFT(elm, field) = RB_RIGHT(elm, field) = NULL; \
+ RB_COLOR(elm, field) = RB_RED; \
+} while (0)
+
+#define RB_SET_BLACKRED(black, red, field) do { \
+ RB_COLOR(black, field) = RB_BLACK; \
+ RB_COLOR(red, field) = RB_RED; \
+} while (0)
+
+#ifndef RB_AUGMENT
+#define RB_AUGMENT(x) do {} while (0)
+#endif
+
+#define RB_ROTATE_LEFT(head, elm, tmp, field) do { \
+ (tmp) = RB_RIGHT(elm, field); \
+ if ((RB_RIGHT(elm, field) = RB_LEFT(tmp, field))) { \
+ RB_PARENT(RB_LEFT(tmp, field), field) = (elm); \
+ } \
+ RB_AUGMENT(elm); \
+ if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field))) { \
+ if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \
+ RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \
+ else \
+ RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \
+ } else \
+ (head)->rbh_root = (tmp); \
+ RB_LEFT(tmp, field) = (elm); \
+ RB_PARENT(elm, field) = (tmp); \
+ RB_AUGMENT(tmp); \
+ if ((RB_PARENT(tmp, field))) \
+ RB_AUGMENT(RB_PARENT(tmp, field)); \
+} while (0)
+
+#define RB_ROTATE_RIGHT(head, elm, tmp, field) do { \
+ (tmp) = RB_LEFT(elm, field); \
+ if ((RB_LEFT(elm, field) = RB_RIGHT(tmp, field))) { \
+ RB_PARENT(RB_RIGHT(tmp, field), field) = (elm); \
+ } \
+ RB_AUGMENT(elm); \
+ if ((RB_PARENT(tmp, field) = RB_PARENT(elm, field))) { \
+ if ((elm) == RB_LEFT(RB_PARENT(elm, field), field)) \
+ RB_LEFT(RB_PARENT(elm, field), field) = (tmp); \
+ else \
+ RB_RIGHT(RB_PARENT(elm, field), field) = (tmp); \
+ } else \
+ (head)->rbh_root = (tmp); \
+ RB_RIGHT(tmp, field) = (elm); \
+ RB_PARENT(elm, field) = (tmp); \
+ RB_AUGMENT(tmp); \
+ if ((RB_PARENT(tmp, field))) \
+ RB_AUGMENT(RB_PARENT(tmp, field)); \
+} while (0)
+
+/* Generates prototypes and inline functions */
+#define RB_PROTOTYPE(name, type, field, cmp) \
+ RB_PROTOTYPE_INTERNAL(name, type, field, cmp,)
+#define RB_PROTOTYPE_STATIC(name, type, field, cmp) \
+ RB_PROTOTYPE_INTERNAL(name, type, field, cmp, __attribute__((__unused__)) static)
+#define RB_PROTOTYPE_INTERNAL(name, type, field, cmp, attr) \
+attr void name##_RB_INSERT_COLOR(struct name *, struct type *); \
+attr void name##_RB_REMOVE_COLOR(struct name *, struct type *, struct type *);\
+attr struct type *name##_RB_REMOVE(struct name *, struct type *); \
+attr struct type *name##_RB_INSERT(struct name *, struct type *); \
+attr struct type *name##_RB_FIND(struct name *, struct type *); \
+attr struct type *name##_RB_NFIND(struct name *, struct type *); \
+attr struct type *name##_RB_NEXT(struct type *); \
+attr struct type *name##_RB_PREV(struct type *); \
+attr struct type *name##_RB_MINMAX(struct name *, int); \
+ \
+
+/* Main rb operation.
+ * Moves node close to the key of elm to top
+ */
+#define RB_GENERATE(name, type, field, cmp) \
+ RB_GENERATE_INTERNAL(name, type, field, cmp,)
+#define RB_GENERATE_STATIC(name, type, field, cmp) \
+ RB_GENERATE_INTERNAL(name, type, field, cmp, __attribute__((__unused__)) static)
+#define RB_GENERATE_INTERNAL(name, type, field, cmp, attr) \
+attr void \
+name##_RB_INSERT_COLOR(struct name *head, struct type *elm) \
+{ \
+ struct type *parent, *gparent, *tmp; \
+ while ((parent = RB_PARENT(elm, field)) && \
+ RB_COLOR(parent, field) == RB_RED) { \
+ gparent = RB_PARENT(parent, field); \
+ if (parent == RB_LEFT(gparent, field)) { \
+ tmp = RB_RIGHT(gparent, field); \
+ if (tmp && RB_COLOR(tmp, field) == RB_RED) { \
+ RB_COLOR(tmp, field) = RB_BLACK; \
+ RB_SET_BLACKRED(parent, gparent, field);\
+ elm = gparent; \
+ continue; \
+ } \
+ if (RB_RIGHT(parent, field) == elm) { \
+ RB_ROTATE_LEFT(head, parent, tmp, field);\
+ tmp = parent; \
+ parent = elm; \
+ elm = tmp; \
+ } \
+ RB_SET_BLACKRED(parent, gparent, field); \
+ RB_ROTATE_RIGHT(head, gparent, tmp, field); \
+ } else { \
+ tmp = RB_LEFT(gparent, field); \
+ if (tmp && RB_COLOR(tmp, field) == RB_RED) { \
+ RB_COLOR(tmp, field) = RB_BLACK; \
+ RB_SET_BLACKRED(parent, gparent, field);\
+ elm = gparent; \
+ continue; \
+ } \
+ if (RB_LEFT(parent, field) == elm) { \
+ RB_ROTATE_RIGHT(head, parent, tmp, field);\
+ tmp = parent; \
+ parent = elm; \
+ elm = tmp; \
+ } \
+ RB_SET_BLACKRED(parent, gparent, field); \
+ RB_ROTATE_LEFT(head, gparent, tmp, field); \
+ } \
+ } \
+ RB_COLOR(head->rbh_root, field) = RB_BLACK; \
+} \
+ \
+attr void \
+name##_RB_REMOVE_COLOR(struct name *head, struct type *parent, struct type *elm) \
+{ \
+ struct type *tmp; \
+ while ((elm == NULL || RB_COLOR(elm, field) == RB_BLACK) && \
+ elm != RB_ROOT(head)) { \
+ if (RB_LEFT(parent, field) == elm) { \
+ tmp = RB_RIGHT(parent, field); \
+ if (RB_COLOR(tmp, field) == RB_RED) { \
+ RB_SET_BLACKRED(tmp, parent, field); \
+ RB_ROTATE_LEFT(head, parent, tmp, field);\
+ tmp = RB_RIGHT(parent, field); \
+ } \
+ if ((RB_LEFT(tmp, field) == NULL || \
+ RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\
+ (RB_RIGHT(tmp, field) == NULL || \
+ RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\
+ RB_COLOR(tmp, field) = RB_RED; \
+ elm = parent; \
+ parent = RB_PARENT(elm, field); \
+ } else { \
+ if (RB_RIGHT(tmp, field) == NULL || \
+ RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK) {\
+ struct type *oleft; \
+ if ((oleft = RB_LEFT(tmp, field)))\
+ RB_COLOR(oleft, field) = RB_BLACK;\
+ RB_COLOR(tmp, field) = RB_RED; \
+ RB_ROTATE_RIGHT(head, tmp, oleft, field);\
+ tmp = RB_RIGHT(parent, field); \
+ } \
+ RB_COLOR(tmp, field) = RB_COLOR(parent, field);\
+ RB_COLOR(parent, field) = RB_BLACK; \
+ if (RB_RIGHT(tmp, field)) \
+ RB_COLOR(RB_RIGHT(tmp, field), field) = RB_BLACK;\
+ RB_ROTATE_LEFT(head, parent, tmp, field);\
+ elm = RB_ROOT(head); \
+ break; \
+ } \
+ } else { \
+ tmp = RB_LEFT(parent, field); \
+ if (RB_COLOR(tmp, field) == RB_RED) { \
+ RB_SET_BLACKRED(tmp, parent, field); \
+ RB_ROTATE_RIGHT(head, parent, tmp, field);\
+ tmp = RB_LEFT(parent, field); \
+ } \
+ if ((RB_LEFT(tmp, field) == NULL || \
+ RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) &&\
+ (RB_RIGHT(tmp, field) == NULL || \
+ RB_COLOR(RB_RIGHT(tmp, field), field) == RB_BLACK)) {\
+ RB_COLOR(tmp, field) = RB_RED; \
+ elm = parent; \
+ parent = RB_PARENT(elm, field); \
+ } else { \
+ if (RB_LEFT(tmp, field) == NULL || \
+ RB_COLOR(RB_LEFT(tmp, field), field) == RB_BLACK) {\
+ struct type *oright; \
+ if ((oright = RB_RIGHT(tmp, field)))\
+ RB_COLOR(oright, field) = RB_BLACK;\
+ RB_COLOR(tmp, field) = RB_RED; \
+ RB_ROTATE_LEFT(head, tmp, oright, field);\
+ tmp = RB_LEFT(parent, field); \
+ } \
+ RB_COLOR(tmp, field) = RB_COLOR(parent, field);\
+ RB_COLOR(parent, field) = RB_BLACK; \
+ if (RB_LEFT(tmp, field)) \
+ RB_COLOR(RB_LEFT(tmp, field), field) = RB_BLACK;\
+ RB_ROTATE_RIGHT(head, parent, tmp, field);\
+ elm = RB_ROOT(head); \
+ break; \
+ } \
+ } \
+ } \
+ if (elm) \
+ RB_COLOR(elm, field) = RB_BLACK; \
+} \
+ \
+attr struct type * \
+name##_RB_REMOVE(struct name *head, struct type *elm) \
+{ \
+ struct type *child, *parent, *old = elm; \
+ int color; \
+ if (RB_LEFT(elm, field) == NULL) \
+ child = RB_RIGHT(elm, field); \
+ else if (RB_RIGHT(elm, field) == NULL) \
+ child = RB_LEFT(elm, field); \
+ else { \
+ struct type *left; \
+ elm = RB_RIGHT(elm, field); \
+ while ((left = RB_LEFT(elm, field))) \
+ elm = left; \
+ child = RB_RIGHT(elm, field); \
+ parent = RB_PARENT(elm, field); \
+ color = RB_COLOR(elm, field); \
+ if (child) \
+ RB_PARENT(child, field) = parent; \
+ if (parent) { \
+ if (RB_LEFT(parent, field) == elm) \
+ RB_LEFT(parent, field) = child; \
+ else \
+ RB_RIGHT(parent, field) = child; \
+ RB_AUGMENT(parent); \
+ } else \
+ RB_ROOT(head) = child; \
+ if (RB_PARENT(elm, field) == old) \
+ parent = elm; \
+ (elm)->field = (old)->field; \
+ if (RB_PARENT(old, field)) { \
+ if (RB_LEFT(RB_PARENT(old, field), field) == old)\
+ RB_LEFT(RB_PARENT(old, field), field) = elm;\
+ else \
+ RB_RIGHT(RB_PARENT(old, field), field) = elm;\
+ RB_AUGMENT(RB_PARENT(old, field)); \
+ } else \
+ RB_ROOT(head) = elm; \
+ RB_PARENT(RB_LEFT(old, field), field) = elm; \
+ if (RB_RIGHT(old, field)) \
+ RB_PARENT(RB_RIGHT(old, field), field) = elm; \
+ if (parent) { \
+ left = parent; \
+ do { \
+ RB_AUGMENT(left); \
+ } while ((left = RB_PARENT(left, field))); \
+ } \
+ goto color; \
+ } \
+ parent = RB_PARENT(elm, field); \
+ color = RB_COLOR(elm, field); \
+ if (child) \
+ RB_PARENT(child, field) = parent; \
+ if (parent) { \
+ if (RB_LEFT(parent, field) == elm) \
+ RB_LEFT(parent, field) = child; \
+ else \
+ RB_RIGHT(parent, field) = child; \
+ RB_AUGMENT(parent); \
+ } else \
+ RB_ROOT(head) = child; \
+color: \
+ if (color == RB_BLACK) \
+ name##_RB_REMOVE_COLOR(head, parent, child); \
+ return (old); \
+} \
+ \
+/* Inserts a node into the RB tree */ \
+attr struct type * \
+name##_RB_INSERT(struct name *head, struct type *elm) \
+{ \
+ struct type *tmp; \
+ struct type *parent = NULL; \
+ int comp = 0; \
+ tmp = RB_ROOT(head); \
+ while (tmp) { \
+ parent = tmp; \
+ comp = (cmp)(elm, parent); \
+ if (comp < 0) \
+ tmp = RB_LEFT(tmp, field); \
+ else if (comp > 0) \
+ tmp = RB_RIGHT(tmp, field); \
+ else \
+ return (tmp); \
+ } \
+ RB_SET(elm, parent, field); \
+ if (parent != NULL) { \
+ if (comp < 0) \
+ RB_LEFT(parent, field) = elm; \
+ else \
+ RB_RIGHT(parent, field) = elm; \
+ RB_AUGMENT(parent); \
+ } else \
+ RB_ROOT(head) = elm; \
+ name##_RB_INSERT_COLOR(head, elm); \
+ return (NULL); \
+} \
+ \
+/* Finds the node with the same key as elm */ \
+attr struct type * \
+name##_RB_FIND(struct name *head, struct type *elm) \
+{ \
+ struct type *tmp = RB_ROOT(head); \
+ int comp; \
+ while (tmp) { \
+ comp = cmp(elm, tmp); \
+ if (comp < 0) \
+ tmp = RB_LEFT(tmp, field); \
+ else if (comp > 0) \
+ tmp = RB_RIGHT(tmp, field); \
+ else \
+ return (tmp); \
+ } \
+ return (NULL); \
+} \
+ \
+/* Finds the first node greater than or equal to the search key */ \
+attr struct type * \
+name##_RB_NFIND(struct name *head, struct type *elm) \
+{ \
+ struct type *tmp = RB_ROOT(head); \
+ struct type *res = NULL; \
+ int comp; \
+ while (tmp) { \
+ comp = cmp(elm, tmp); \
+ if (comp < 0) { \
+ res = tmp; \
+ tmp = RB_LEFT(tmp, field); \
+ } \
+ else if (comp > 0) \
+ tmp = RB_RIGHT(tmp, field); \
+ else \
+ return (tmp); \
+ } \
+ return (res); \
+} \
+ \
+/* ARGSUSED */ \
+attr struct type * \
+name##_RB_NEXT(struct type *elm) \
+{ \
+ if (RB_RIGHT(elm, field)) { \
+ elm = RB_RIGHT(elm, field); \
+ while (RB_LEFT(elm, field)) \
+ elm = RB_LEFT(elm, field); \
+ } else { \
+ if (RB_PARENT(elm, field) && \
+ (elm == RB_LEFT(RB_PARENT(elm, field), field))) \
+ elm = RB_PARENT(elm, field); \
+ else { \
+ while (RB_PARENT(elm, field) && \
+ (elm == RB_RIGHT(RB_PARENT(elm, field), field)))\
+ elm = RB_PARENT(elm, field); \
+ elm = RB_PARENT(elm, field); \
+ } \
+ } \
+ return (elm); \
+} \
+ \
+/* ARGSUSED */ \
+attr struct type * \
+name##_RB_PREV(struct type *elm) \
+{ \
+ if (RB_LEFT(elm, field)) { \
+ elm = RB_LEFT(elm, field); \
+ while (RB_RIGHT(elm, field)) \
+ elm = RB_RIGHT(elm, field); \
+ } else { \
+ if (RB_PARENT(elm, field) && \
+ (elm == RB_RIGHT(RB_PARENT(elm, field), field))) \
+ elm = RB_PARENT(elm, field); \
+ else { \
+ while (RB_PARENT(elm, field) && \
+ (elm == RB_LEFT(RB_PARENT(elm, field), field)))\
+ elm = RB_PARENT(elm, field); \
+ elm = RB_PARENT(elm, field); \
+ } \
+ } \
+ return (elm); \
+} \
+ \
+attr struct type * \
+name##_RB_MINMAX(struct name *head, int val) \
+{ \
+ struct type *tmp = RB_ROOT(head); \
+ struct type *parent = NULL; \
+ while (tmp) { \
+ parent = tmp; \
+ if (val < 0) \
+ tmp = RB_LEFT(tmp, field); \
+ else \
+ tmp = RB_RIGHT(tmp, field); \
+ } \
+ return (parent); \
+}
+
+#define RB_NEGINF -1
+#define RB_INF 1
+
+#define RB_INSERT(name, x, y) name##_RB_INSERT(x, y)
+#define RB_REMOVE(name, x, y) name##_RB_REMOVE(x, y)
+#define RB_FIND(name, x, y) name##_RB_FIND(x, y)
+#define RB_NFIND(name, x, y) name##_RB_NFIND(x, y)
+#define RB_NEXT(name, x, y) name##_RB_NEXT(y)
+#define RB_PREV(name, x, y) name##_RB_PREV(y)
+#define RB_MIN(name, x) name##_RB_MINMAX(x, RB_NEGINF)
+#define RB_MAX(name, x) name##_RB_MINMAX(x, RB_INF)
+
+#define RB_FOREACH(x, name, head) \
+ for ((x) = RB_MIN(name, head); \
+ (x) != NULL; \
+ (x) = name##_RB_NEXT(x))
+
+#define RB_FOREACH_SAFE(x, name, head, y) \
+ for ((x) = RB_MIN(name, head); \
+ ((x) != NULL) && ((y) = name##_RB_NEXT(x), 1); \
+ (x) = (y))
+
+#define RB_FOREACH_REVERSE(x, name, head) \
+ for ((x) = RB_MAX(name, head); \
+ (x) != NULL; \
+ (x) = name##_RB_PREV(x))
+
+#define RB_FOREACH_REVERSE_SAFE(x, name, head, y) \
+ for ((x) = RB_MAX(name, head); \
+ ((x) != NULL) && ((y) = name##_RB_PREV(x), 1); \
+ (x) = (y))
+
+
+/*
+ * Copyright (c) 2016 David Gwynne <dlg@openbsd.org>
+ *
+ * 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.
+ */
+
+struct rb_type {
+ int (*t_compare)(const void *, const void *);
+ void (*t_augment)(void *);
+ unsigned int t_offset; /* offset of rb_entry in type */
+};
+
+struct rb_tree {
+ struct rb_entry *rbt_root;
+};
+
+struct rb_entry {
+ struct rb_entry *rbt_parent;
+ struct rb_entry *rbt_left;
+ struct rb_entry *rbt_right;
+ unsigned int rbt_color;
+};
+
+#define RBT_HEAD(_name, _type) \
+struct _name { \
+ struct rb_tree rbh_root; \
+}
+
+#define RBT_ENTRY(_type) struct rb_entry
+
+static inline void
+_rb_init(struct rb_tree *rbt)
+{
+ rbt->rbt_root = NULL;
+}
+
+static inline int
+_rb_empty(struct rb_tree *rbt)
+{
+ return (rbt->rbt_root == NULL);
+}
+
+void *_rb_insert(const struct rb_type *, struct rb_tree *, void *);
+void *_rb_remove(const struct rb_type *, struct rb_tree *, void *);
+void *_rb_find(const struct rb_type *, struct rb_tree *, const void *);
+void *_rb_nfind(const struct rb_type *, struct rb_tree *, const void *);
+void *_rb_root(const struct rb_type *, struct rb_tree *);
+void *_rb_min(const struct rb_type *, struct rb_tree *);
+void *_rb_max(const struct rb_type *, struct rb_tree *);
+void *_rb_next(const struct rb_type *, void *);
+void *_rb_prev(const struct rb_type *, void *);
+void *_rb_left(const struct rb_type *, void *);
+void *_rb_right(const struct rb_type *, void *);
+void *_rb_parent(const struct rb_type *, void *);
+void _rb_set_left(const struct rb_type *, void *, void *);
+void _rb_set_right(const struct rb_type *, void *, void *);
+void _rb_set_parent(const struct rb_type *, void *, void *);
+void _rb_poison(const struct rb_type *, void *, unsigned long);
+int _rb_check(const struct rb_type *, void *, unsigned long);
+
+#define RBT_INITIALIZER(_head) { { NULL } }
+
+#define RBT_PROTOTYPE(_name, _type, _field, _cmp) \
+extern const struct rb_type *const _name##_RBT_TYPE; \
+ \
+__unused static inline void \
+_name##_RBT_INIT(struct _name *head) \
+{ \
+ _rb_init(&head->rbh_root); \
+} \
+ \
+__unused static inline struct _type * \
+_name##_RBT_INSERT(struct _name *head, struct _type *elm) \
+{ \
+ return _rb_insert(_name##_RBT_TYPE, &head->rbh_root, elm); \
+} \
+ \
+__unused static inline struct _type * \
+_name##_RBT_REMOVE(struct _name *head, struct _type *elm) \
+{ \
+ return _rb_remove(_name##_RBT_TYPE, &head->rbh_root, elm); \
+} \
+ \
+__unused static inline struct _type * \
+_name##_RBT_FIND(struct _name *head, const struct _type *key) \
+{ \
+ return _rb_find(_name##_RBT_TYPE, &head->rbh_root, key); \
+} \
+ \
+__unused static inline struct _type * \
+_name##_RBT_NFIND(struct _name *head, const struct _type *key) \
+{ \
+ return _rb_nfind(_name##_RBT_TYPE, &head->rbh_root, key); \
+} \
+ \
+__unused static inline struct _type * \
+_name##_RBT_ROOT(struct _name *head) \
+{ \
+ return _rb_root(_name##_RBT_TYPE, &head->rbh_root); \
+} \
+ \
+__unused static inline int \
+_name##_RBT_EMPTY(struct _name *head) \
+{ \
+ return _rb_empty(&head->rbh_root); \
+} \
+ \
+__unused static inline struct _type * \
+_name##_RBT_MIN(struct _name *head) \
+{ \
+ return _rb_min(_name##_RBT_TYPE, &head->rbh_root); \
+} \
+ \
+__unused static inline struct _type * \
+_name##_RBT_MAX(struct _name *head) \
+{ \
+ return _rb_max(_name##_RBT_TYPE, &head->rbh_root); \
+} \
+ \
+__unused static inline struct _type * \
+_name##_RBT_NEXT(struct _type *elm) \
+{ \
+ return _rb_next(_name##_RBT_TYPE, elm); \
+} \
+ \
+__unused static inline struct _type * \
+_name##_RBT_PREV(struct _type *elm) \
+{ \
+ return _rb_prev(_name##_RBT_TYPE, elm); \
+} \
+ \
+__unused static inline struct _type * \
+_name##_RBT_LEFT(struct _type *elm) \
+{ \
+ return _rb_left(_name##_RBT_TYPE, elm); \
+} \
+ \
+__unused static inline struct _type * \
+_name##_RBT_RIGHT(struct _type *elm) \
+{ \
+ return _rb_right(_name##_RBT_TYPE, elm); \
+} \
+ \
+__unused static inline struct _type * \
+_name##_RBT_PARENT(struct _type *elm) \
+{ \
+ return _rb_parent(_name##_RBT_TYPE, elm); \
+} \
+ \
+__unused static inline void \
+_name##_RBT_SET_LEFT(struct _type *elm, struct _type *left) \
+{ \
+ return _rb_set_left(_name##_RBT_TYPE, elm, left); \
+} \
+ \
+__unused static inline void \
+_name##_RBT_SET_RIGHT(struct _type *elm, struct _type *right) \
+{ \
+ return _rb_set_right(_name##_RBT_TYPE, elm, right); \
+} \
+ \
+__unused static inline void \
+_name##_RBT_SET_PARENT(struct _type *elm, struct _type *parent) \
+{ \
+ return _rb_set_parent(_name##_RBT_TYPE, elm, parent); \
+} \
+ \
+__unused static inline void \
+_name##_RBT_POISON(struct _type *elm, unsigned long poison) \
+{ \
+ return _rb_poison(_name##_RBT_TYPE, elm, poison); \
+} \
+ \
+__unused static inline int \
+_name##_RBT_CHECK(struct _type *elm, unsigned long poison) \
+{ \
+ return _rb_check(_name##_RBT_TYPE, elm, poison); \
+}
+
+#define RBT_GENERATE_INTERNAL(_name, _type, _field, _cmp, _aug) \
+static int \
+_name##_RBT_COMPARE(const void *lptr, const void *rptr) \
+{ \
+ const struct _type *l = lptr, *r = rptr; \
+ return _cmp(l, r); \
+} \
+static const struct rb_type _name##_RBT_INFO = { \
+ _name##_RBT_COMPARE, \
+ _aug, \
+ offsetof(struct _type, _field), \
+}; \
+const struct rb_type *const _name##_RBT_TYPE = &_name##_RBT_INFO
+
+#define RBT_GENERATE_AUGMENT(_name, _type, _field, _cmp, _aug) \
+static void \
+_name##_RBT_AUGMENT(void *ptr) \
+{ \
+ struct _type *p = ptr; \
+ return _aug(p); \
+} \
+RBT_GENERATE_INTERNAL(_name, _type, _field, _cmp, _name##_RBT_AUGMENT)
+
+#define RBT_GENERATE(_name, _type, _field, _cmp) \
+ RBT_GENERATE_INTERNAL(_name, _type, _field, _cmp, NULL)
+
+#define RBT_INIT(_name, _head) _name##_RBT_INIT(_head)
+#define RBT_INSERT(_name, _head, _elm) _name##_RBT_INSERT(_head, _elm)
+#define RBT_REMOVE(_name, _head, _elm) _name##_RBT_REMOVE(_head, _elm)
+#define RBT_FIND(_name, _head, _key) _name##_RBT_FIND(_head, _key)
+#define RBT_NFIND(_name, _head, _key) _name##_RBT_NFIND(_head, _key)
+#define RBT_ROOT(_name, _head) _name##_RBT_ROOT(_head)
+#define RBT_EMPTY(_name, _head) _name##_RBT_EMPTY(_head)
+#define RBT_MIN(_name, _head) _name##_RBT_MIN(_head)
+#define RBT_MAX(_name, _head) _name##_RBT_MAX(_head)
+#define RBT_NEXT(_name, _elm) _name##_RBT_NEXT(_elm)
+#define RBT_PREV(_name, _elm) _name##_RBT_PREV(_elm)
+#define RBT_LEFT(_name, _elm) _name##_RBT_LEFT(_elm)
+#define RBT_RIGHT(_name, _elm) _name##_RBT_RIGHT(_elm)
+#define RBT_PARENT(_name, _elm) _name##_RBT_PARENT(_elm)
+#define RBT_SET_LEFT(_name, _elm, _l) _name##_RBT_SET_LEFT(_elm, _l)
+#define RBT_SET_RIGHT(_name, _elm, _r) _name##_RBT_SET_RIGHT(_elm, _r)
+#define RBT_SET_PARENT(_name, _elm, _p) _name##_RBT_SET_PARENT(_elm, _p)
+#define RBT_POISON(_name, _elm, _p) _name##_RBT_POISON(_elm, _p)
+#define RBT_CHECK(_name, _elm, _p) _name##_RBT_CHECK(_elm, _p)
+
+#define RBT_FOREACH(_e, _name, _head) \
+ for ((_e) = RBT_MIN(_name, (_head)); \
+ (_e) != NULL; \
+ (_e) = RBT_NEXT(_name, (_e)))
+
+#define RBT_FOREACH_SAFE(_e, _name, _head, _n) \
+ for ((_e) = RBT_MIN(_name, (_head)); \
+ (_e) != NULL && ((_n) = RBT_NEXT(_name, (_e)), 1); \
+ (_e) = (_n))
+
+#define RBT_FOREACH_REVERSE(_e, _name, _head) \
+ for ((_e) = RBT_MAX(_name, (_head)); \
+ (_e) != NULL; \
+ (_e) = RBT_PREV(_name, (_e)))
+
+#define RBT_FOREACH_REVERSE_SAFE(_e, _name, _head, _n) \
+ for ((_e) = RBT_MAX(_name, (_head)); \
+ (_e) != NULL && ((_n) = RBT_PREV(_name, (_e)), 1); \
+ (_e) = (_n))
+
+#endif /* _SYS_TREE_H_ */
diff --git a/sys/sys/tty.h b/sys/sys/tty.h
new file mode 100644
index 0000000..efe0bfb
--- /dev/null
+++ b/sys/sys/tty.h
@@ -0,0 +1,336 @@
+/* $OpenBSD: tty.h,v 1.38 2019/07/19 00:17:16 cheloha Exp $ */
+/* $NetBSD: tty.h,v 1.30.4.1 1996/06/02 09:08:13 mrg Exp $ */
+
+/*-
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)tty.h 8.6 (Berkeley) 1/21/94
+ */
+
+#include <sys/termios.h>
+#include <sys/queue.h>
+#include <sys/selinfo.h> /* For struct selinfo. */
+#include <sys/timeout.h>
+
+#define KERN_TTY_TKNIN 1 /* quad: input chars */
+#define KERN_TTY_TKNOUT 2 /* quad: output chars */
+#define KERN_TTY_TKRAWCC 3 /* quad: input chars, raw mode */
+#define KERN_TTY_TKCANCC 4 /* quad: input char, cooked mode */
+#define KERN_TTY_INFO 5 /* struct: tty stats */
+/* was KERN_TTY_MAXPTYS 6 */
+/* was KERN_TTY_NPTYS 7 */
+#define KERN_TTY_MAXID 8
+
+#define CTL_KERN_TTY_NAMES { \
+ { 0, 0 }, \
+ { "tk_nin", CTLTYPE_QUAD }, \
+ { "tk_nout", CTLTYPE_QUAD }, \
+ { "tk_rawcc", CTLTYPE_QUAD }, \
+ { "tk_cancc", CTLTYPE_QUAD }, \
+ { "ttyinfo", CTLTYPE_STRUCT }, \
+ { "gap", 0 }, \
+ { "gap", 0 }, \
+}
+
+/* ptmget, for /dev/ptm pty getting ioctl PTMGET */
+
+struct ptmget {
+ int cfd;
+ int sfd;
+ char cn[16];
+ char sn[16];
+};
+#define PTMGET _IOR('t', 1, struct ptmget) /* get ptys */
+#define PATH_PTMDEV "/dev/ptm"
+#define TTY_GID 4 /* XXX evil hardcoding of tty gid */
+
+/*
+ * Clists are actually ring buffers. The c_cc, c_cf, c_cl fields have
+ * exactly the same behaviour as in true clists.
+ * if c_cq is NULL, the ring buffer has no TTY_QUOTE functionality
+ * (but, saves memory and cpu time)
+ *
+ * *DON'T* play with c_cs, c_ce, c_cq, or c_cl outside tty_subr.c!!!
+ */
+struct clist {
+ int c_cc; /* count of characters in queue */
+ int c_cn; /* total ring buffer length */
+ u_char *c_cf; /* points to first character */
+ u_char *c_cl; /* points to next open character */
+ u_char *c_cs; /* start of ring buffer */
+ u_char *c_ce; /* c_ce + c_len */
+ u_char *c_cq; /* N bits/bytes long, see tty_subr.c */
+};
+
+/*
+ * Per-tty structure.
+ *
+ * Should be split in two, into device and tty drivers.
+ * Glue could be masks of what to echo and circular buffer
+ * (low, high, timeout).
+ */
+struct tty {
+ TAILQ_ENTRY(tty) tty_link; /* Link in global tty list. */
+ struct clist t_rawq; /* Device raw input queue. */
+ long t_rawcc; /* Raw input queue statistics. */
+ struct clist t_canq; /* Device canonical queue. */
+ long t_cancc; /* Canonical queue statistics. */
+ struct clist t_outq; /* Device output queue. */
+ long t_outcc; /* Output queue statistics. */
+ int t_qlen; /* Length of above queues */
+ u_char t_line; /* Interface to device drivers. */
+ dev_t t_dev; /* Device. */
+ int t_state; /* Device and driver (TS*) state. */
+ int t_flags; /* Tty flags. */
+ struct pgrp *t_pgrp; /* Foreground process group. */
+ struct session *t_session; /* Enclosing session. */
+ struct selinfo t_rsel; /* Tty read/oob select. */
+ struct selinfo t_wsel; /* Tty write select. */
+ struct termios t_termios; /* Termios state. */
+ struct winsize t_winsize; /* Window size. */
+ /* Start output. */
+ void (*t_oproc)(struct tty *);
+ /* Set hardware state. */
+ int (*t_param)(struct tty *, struct termios *);
+ /* Set hardware flow control. */
+ int (*t_hwiflow)(struct tty *tp, int flag);
+ void *t_sc; /* XXX: net/if_sl.c:sl_softc. */
+ short t_column; /* Tty output column. */
+ short t_rocount, t_rocol; /* Tty. */
+ short t_hiwat; /* High water mark. */
+ short t_lowat; /* Low water mark. */
+ short t_gen; /* Generation number. */
+ struct timeout t_rstrt_to; /* restart timeout */
+ struct timeval t_tv; /* timestamp */
+};
+
+/*
+ * Small version of struct tty exported via sysctl KERN_TTY_INFO
+ */
+struct itty {
+ dev_t t_dev;
+ int t_rawq_c_cc;
+ int t_canq_c_cc;
+ int t_outq_c_cc;
+ short t_hiwat;
+ short t_lowat;
+ short t_column;
+ int t_state;
+ struct session *t_session;
+ pid_t t_pgrp_pg_id;
+ u_char t_line;
+};
+
+#define t_cc t_termios.c_cc
+#define t_cflag t_termios.c_cflag
+#define t_iflag t_termios.c_iflag
+#define t_ispeed t_termios.c_ispeed
+#define t_lflag t_termios.c_lflag
+#define t_min t_termios.c_min
+#define t_oflag t_termios.c_oflag
+#define t_ospeed t_termios.c_ospeed
+#define t_time t_termios.c_time
+
+#define TTIPRI 25 /* Sleep priority for tty reads. */
+#define TTOPRI 26 /* Sleep priority for tty writes. */
+
+#define TTMASK 15
+#define OBUFSIZ 512
+#define TTYHOG(tp) (tp)->t_qlen
+
+#ifdef _KERNEL
+#define TTMAXLOWAT 256
+#define TTMINLOWAT 32
+#define TTMINHIWAT 100
+#define TTHIWATMINSPACE 200 /* Min space above hiwat */
+#endif
+
+/* These flags are kept in t_state. */
+#define TS_ASLEEP 0x00001 /* Process waiting for tty. */
+#define TS_ASYNC 0x00002 /* Tty in async I/O mode. */
+#define TS_BUSY 0x00004 /* Draining output. */
+#define TS_CARR_ON 0x00008 /* Carrier is present. */
+#define TS_FLUSH 0x00010 /* Outq has been flushed during DMA. */
+#define TS_ISOPEN 0x00020 /* Open has completed. */
+#define TS_TBLOCK 0x00040 /* Further input blocked. */
+#define TS_TIMEOUT 0x00080 /* Wait for output char processing. */
+#define TS_TTSTOP 0x00100 /* Output paused. */
+#define TS_WOPEN 0x00200 /* Open in progress. */
+#define TS_XCLUDE 0x00400 /* Tty requires exclusivity. */
+
+/* State for intra-line fancy editing work. */
+#define TS_BKSL 0x00800 /* State for lowercase \ work. */
+#define TS_CNTTB 0x01000 /* Counting tab width, ignore FLUSHO. */
+#define TS_ERASE 0x02000 /* Within a \.../ for PRTRUB. */
+#define TS_LNCH 0x04000 /* Next character is literal. */
+#define TS_TYPEN 0x08000 /* Retyping suspended input (PENDIN). */
+#define TS_LOCAL (TS_BKSL | TS_CNTTB | TS_ERASE | TS_LNCH | TS_TYPEN)
+
+#define TS_TSTAMPDCDSET 0x10000 /* update timestamp on DCD set */
+#define TS_TSTAMPDCDCLR 0x20000 /* update timestamp on DCD clr */
+#define TS_TSTAMPCTSSET 0x40000 /* update timestamp on CTS set */
+#define TS_TSTAMPCTSCLR 0x80000 /* update timestamp on CTS clr */
+
+/* Character type information. */
+#define ORDINARY 0
+#define CONTROL 1
+#define BACKSPACE 2
+#define NEWLINE 3
+#define TAB 4
+#define VTAB 5
+#define RETURN 6
+
+struct speedtab {
+ int sp_speed; /* Speed. */
+ int sp_code; /* Code. */
+};
+
+/* Modem control commands (driver). */
+#define DMSET 0
+#define DMBIS 1
+#define DMBIC 2
+#define DMGET 3
+
+/* Flags on a character passed to ttyinput. */
+#define TTY_CHARMASK 0x000000ff /* Character mask */
+#define TTY_QUOTE 0x00000100 /* Character quoted */
+#define TTY_ERRORMASK 0xff000000 /* Error mask */
+#define TTY_FE 0x01000000 /* Framing error or BREAK condition */
+#define TTY_PE 0x02000000 /* Parity error */
+
+/* Is tp controlling terminal for pr? */
+#define isctty(pr, tp) \
+ ((pr)->ps_session == (tp)->t_session && (pr)->ps_flags & PS_CONTROLT)
+
+/* Is pr in background of tp? */
+#define isbackground(pr, tp) \
+ (isctty((pr), (tp)) && (pr)->ps_pgrp != (tp)->t_pgrp)
+
+/*
+ * ttylist_head is defined here so that user-land has access to it.
+ */
+TAILQ_HEAD(ttylist_head, tty); /* the ttylist is a TAILQ */
+
+#ifdef _KERNEL
+
+extern int tty_count; /* number of ttys in global ttylist */
+extern struct ttychars ttydefaults;
+
+/* Symbolic sleep message strings. */
+extern char ttyin[], ttyout[], ttopen[], ttclos[], ttybg[], ttybuf[];
+
+extern int64_t tk_cancc, tk_nin, tk_nout, tk_rawcc;
+
+int sysctl_tty(int *, u_int, void *, size_t *, void *, size_t);
+int sysctl_pty(int *, u_int, void *, size_t *, void *, size_t);
+
+int b_to_q(u_char *cp, int cc, struct clist *q);
+void catq(struct clist *from, struct clist *to);
+void clist_init(void);
+int getc(struct clist *q);
+void ndflush(struct clist *q, int cc);
+int ndqb(struct clist *q, int flag);
+u_char *nextc(struct clist *q, u_char *cp, int *c);
+int putc(int c, struct clist *q);
+int q_to_b(struct clist *q, u_char *cp, int cc);
+int unputc(struct clist *q);
+
+int nullmodem(struct tty *tp, int flag);
+int tputchar(int c, struct tty *tp);
+int ttioctl(struct tty *tp, u_long com, caddr_t data, int flag,
+ struct proc *p);
+int ttread(struct tty *tp, struct uio *uio, int flag);
+void ttrstrt(void *tp);
+int ttpoll(dev_t device, int events, struct proc *p);
+int ttkqfilter(dev_t dev, struct knote *kn);
+void ttsetwater(struct tty *tp);
+int ttspeedtab(int speed, const struct speedtab *table);
+int ttstart(struct tty *tp);
+void ttwakeupwr(struct tty *tp);
+void ttwakeup(struct tty *tp);
+int ttwrite(struct tty *tp, struct uio *uio, int flag);
+void ttychars(struct tty *tp);
+int ttycheckoutq(struct tty *tp, int wait);
+int ttyclose(struct tty *tp);
+void ttyflush(struct tty *tp, int rw);
+void ttyinfo(struct tty *tp);
+int ttyinput(int c, struct tty *tp);
+int ttylclose(struct tty *tp, int flag, struct proc *p);
+int ttymodem(struct tty *tp, int flag);
+int ttyopen(dev_t device, struct tty *tp, struct proc *p);
+int ttyoutput(int c, struct tty *tp);
+void ttypend(struct tty *tp);
+void ttyretype(struct tty *tp);
+void ttyrub(int c, struct tty *tp);
+int ttysleep(struct tty *tp, void *chan, int pri, char *wmesg);
+int ttywait(struct tty *tp);
+int ttywflush(struct tty *tp);
+void ttytstamp(struct tty *tp, int octs, int ncts, int odcd, int ndcd);
+
+void tty_init(void);
+struct tty *ttymalloc(int);
+void ttyfree(struct tty *);
+u_char *firstc(struct clist *clp, int *c);
+
+int cttyopen(dev_t, int, int, struct proc *);
+int cttyread(dev_t, struct uio *, int);
+int cttywrite(dev_t, struct uio *, int);
+int cttyioctl(dev_t, u_long, caddr_t, int, struct proc *);
+int cttypoll(dev_t, int, struct proc *);
+
+void clalloc(struct clist *, int, int);
+void clfree(struct clist *);
+
+int nullioctl(struct tty *, u_long, caddr_t, int, struct proc *);
+
+int pppopen(dev_t dev, struct tty *, struct proc *);
+int pppclose(struct tty *, int, struct proc *);
+int ppptioctl(struct tty *, u_long, caddr_t, int, struct proc *);
+int pppinput(int c, struct tty *);
+int pppstart(struct tty *);
+int pppread(struct tty *, struct uio *, int);
+int pppwrite(struct tty *, struct uio *, int);
+
+int nmeaopen(dev_t, struct tty *, struct proc *);
+int nmeaclose(struct tty *, int, struct proc *);
+int nmeainput(int, struct tty *);
+
+int mstsopen(dev_t, struct tty *, struct proc *);
+int mstsclose(struct tty *, int, struct proc *);
+int mstsinput(int, struct tty *);
+
+int endrunopen(dev_t, struct tty *, struct proc *);
+int endrunclose(struct tty *, int, struct proc *);
+int endruninput(int, struct tty *);
+
+#endif /* _KERNEL */
diff --git a/sys/sys/ttycom.h b/sys/sys/ttycom.h
new file mode 100644
index 0000000..82af7e8
--- /dev/null
+++ b/sys/sys/ttycom.h
@@ -0,0 +1,151 @@
+/* $OpenBSD: ttycom.h,v 1.17 2018/06/16 13:55:03 deraadt Exp $ */
+/* $NetBSD: ttycom.h,v 1.4 1996/05/19 17:17:53 jonathan Exp $ */
+
+/*-
+ * Copyright (c) 1982, 1986, 1990, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)ttycom.h 8.1 (Berkeley) 3/28/94
+ */
+
+#ifndef _SYS_TTYCOM_H_
+#define _SYS_TTYCOM_H_
+
+#include <sys/ioccom.h>
+
+/* Tty ioctl's. */
+
+/*
+ * Window/terminal size structure. This information is stored by the kernel
+ * in order to provide a consistent interface, but is not used by the kernel.
+ */
+struct winsize {
+ unsigned short ws_row; /* rows, in characters */
+ unsigned short ws_col; /* columns, in characters */
+ unsigned short ws_xpixel; /* horizontal size, pixels */
+ unsigned short ws_ypixel; /* vertical size, pixels */
+};
+
+struct tstamps {
+ int ts_set; /* TIOCM_CAR and/or TIOCM_CTS */
+ int ts_clr;
+};
+
+#define TIOCM_LE 0001 /* line enable */
+#define TIOCM_DTR 0002 /* data terminal ready */
+#define TIOCM_RTS 0004 /* request to send */
+#define TIOCM_ST 0010 /* secondary transmit */
+#define TIOCM_SR 0020 /* secondary receive */
+#define TIOCM_CTS 0040 /* clear to send */
+#define TIOCM_CAR 0100 /* carrier detect */
+#define TIOCM_CD TIOCM_CAR
+#define TIOCM_RNG 0200 /* ring */
+#define TIOCM_RI TIOCM_RNG
+#define TIOCM_DSR 0400 /* data set ready */
+ /* 8-10 compat */
+#define TIOCEXCL _IO('t', 13) /* set exclusive use of tty */
+#define TIOCNXCL _IO('t', 14) /* reset exclusive use of tty */
+ /* 15 unused */
+#define TIOCFLUSH _IOW('t', 16, int) /* flush buffers */
+ /* 17-18 compat */
+#define TIOCGETA _IOR('t', 19, struct termios) /* get termios struct */
+#define TIOCSETA _IOW('t', 20, struct termios) /* set termios struct */
+#define TIOCSETAW _IOW('t', 21, struct termios) /* drain output, set */
+#define TIOCSETAF _IOW('t', 22, struct termios) /* drn out, fls in, set */
+#define TIOCGETD _IOR('t', 26, int) /* get line discipline */
+#define TIOCSETD _IOW('t', 27, int) /* set line discipline */
+#define TIOCSETVERAUTH _IOW('t', 28, int) /* set verified auth */
+#define TIOCCLRVERAUTH _IO('t', 29) /* clear verified auth */
+#define TIOCCHKVERAUTH _IO('t', 30) /* check verified auth */
+ /* 127-124 compat */
+#define TIOCSBRK _IO('t', 123) /* set break bit */
+#define TIOCCBRK _IO('t', 122) /* clear break bit */
+#define TIOCSDTR _IO('t', 121) /* set data terminal ready */
+#define TIOCCDTR _IO('t', 120) /* clear data terminal ready */
+#define TIOCGPGRP _IOR('t', 119, int) /* get pgrp of tty */
+#define TIOCSPGRP _IOW('t', 118, int) /* set pgrp of tty */
+ /* 117-116 compat */
+#define TIOCOUTQ _IOR('t', 115, int) /* output queue size */
+#define TIOCNOTTY _IO('t', 113) /* void tty association */
+#define TIOCPKT _IOW('t', 112, int) /* pty: set/clear packet mode */
+#define TIOCPKT_DATA 0x00 /* data packet */
+#define TIOCPKT_FLUSHREAD 0x01 /* flush packet */
+#define TIOCPKT_FLUSHWRITE 0x02 /* flush packet */
+#define TIOCPKT_STOP 0x04 /* stop output */
+#define TIOCPKT_START 0x08 /* start output */
+#define TIOCPKT_NOSTOP 0x10 /* no more ^S, ^Q */
+#define TIOCPKT_DOSTOP 0x20 /* now do ^S ^Q */
+#define TIOCPKT_IOCTL 0x40 /* state change of pty driver */
+#define TIOCSTOP _IO('t', 111) /* stop output, like ^S */
+#define TIOCSTART _IO('t', 110) /* start output, like ^Q */
+#define TIOCMSET _IOW('t', 109, int) /* set all modem bits */
+#define TIOCMBIS _IOW('t', 108, int) /* bis modem bits */
+#define TIOCMBIC _IOW('t', 107, int) /* bic modem bits */
+#define TIOCMGET _IOR('t', 106, int) /* get all modem bits */
+#define TIOCREMOTE _IOW('t', 105, int) /* remote input editing */
+#define TIOCGWINSZ _IOR('t', 104, struct winsize) /* get window size */
+#define TIOCSWINSZ _IOW('t', 103, struct winsize) /* set window size */
+#define TIOCUCNTL _IOW('t', 102, int) /* pty: set/clr usr cntl mode */
+#define UIOCCMD(n) _IO('u', n) /* usr cntl op "n" */
+#define TIOCUCNTL_SBRK (TIOCSBRK & 0xff)/* set break bit, usr ctnl */
+#define TIOCUCNTL_CBRK (TIOCCBRK & 0xff)/* clear break bit, usr ctnl */
+#define TIOCSTAT _IO('t', 101) /* generate status message */
+#define TIOCGSID _IOR('t', 99, int) /* get sid of tty */
+#define TIOCCONS _IOW('t', 98, int) /* become virtual console */
+#define TIOCSCTTY _IO('t', 97) /* become controlling tty */
+#define TIOCEXT _IOW('t', 96, int) /* pty: external processing */
+#define TIOCSIG _IOW('t', 95, int) /* pty: generate signal */
+#define TIOCDRAIN _IO('t', 94) /* wait till output drained */
+#define TIOCGFLAGS _IOR('t', 93, int) /* get device flags */
+#define TIOCSFLAGS _IOW('t', 92, int) /* set device flags */
+#define TIOCFLAG_SOFTCAR 0x01 /* ignore hardware carrier */
+#define TIOCFLAG_CLOCAL 0x02 /* set clocal on open */
+#define TIOCFLAG_CRTSCTS 0x04 /* set crtscts on open */
+#define TIOCFLAG_MDMBUF 0x08 /* set mdmbuf on open */
+#define TIOCFLAG_PPS 0x10 /* call hardpps on carrier up */
+#define TIOCGTSTAMP _IOR('t', 91, struct timeval) /* get timestamp */
+#define TIOCSTSTAMP _IOW('t', 90, struct tstamps) /* timestamp reasons */
+
+/* Backwards compatibility */
+#define TIOCMODG TIOCMGET
+#define TIOCMODS TIOCMSET
+
+#define TTYDISC 0 /* termios tty line discipline */
+#define TABLDISC 3 /* tablet discipline */
+#define SLIPDISC 4 /* serial IP discipline */
+#define PPPDISC 5 /* ppp discipline */
+#define STRIPDISC 6 /* metricom wireless IP discipline */
+#define NMEADISC 7 /* NMEA0183 discipline */
+#define MSTSDISC 8 /* Meinberg time string discipline */
+#define ENDRUNDISC 9 /* EndRun time format discipline */
+
+#endif /* !_SYS_TTYCOM_H_ */
diff --git a/sys/sys/ttydefaults.h b/sys/sys/ttydefaults.h
new file mode 100644
index 0000000..07ddac2
--- /dev/null
+++ b/sys/sys/ttydefaults.h
@@ -0,0 +1,95 @@
+/* $OpenBSD: ttydefaults.h,v 1.7 2019/03/12 11:01:25 nicm Exp $ */
+/* $NetBSD: ttydefaults.h,v 1.8 1996/04/09 20:55:45 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1982, 1986, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)ttydefaults.h 8.4 (Berkeley) 1/21/94
+ */
+
+/*
+ * System wide defaults for terminal state.
+ */
+#ifndef _SYS_TTYDEFAULTS_H_
+#define _SYS_TTYDEFAULTS_H_
+
+/*
+ * Defaults on "first" open.
+ */
+#define TTYDEF_IFLAG (BRKINT | ICRNL | IMAXBEL | IXON | IXANY)
+#define TTYDEF_OFLAG (OPOST | ONLCR)
+#define TTYDEF_LFLAG (ECHO | ICANON | ISIG | IEXTEN | ECHOE|ECHOKE|ECHOCTL)
+#define TTYDEF_CFLAG (CREAD | CS8 | HUPCL)
+#define TTYDEF_SPEED (B9600)
+
+/*
+ * Control Character Defaults
+ */
+#define CTRL(x) (x&037)
+#define CEOF CTRL('d')
+#define CEOL ((unsigned char)'\377') /* XXX avoid _POSIX_VDISABLE */
+#define CERASE 0177
+#define CINTR CTRL('c')
+#define CSTATUS ((unsigned char)'\377') /* XXX avoid _POSIX_VDISABLE */
+#define CKILL CTRL('u')
+#define CMIN 1
+#define CQUIT 034 /* FS, ^\ */
+#define CSUSP CTRL('z')
+#define CTIME 0
+#define CDSUSP CTRL('y')
+#define CSTART CTRL('q')
+#define CSTOP CTRL('s')
+#define CLNEXT CTRL('v')
+#define CDISCARD CTRL('o')
+#define CWERASE CTRL('w')
+#define CREPRINT CTRL('r')
+#define CEOT CEOF
+/* compat */
+#define CBRK CEOL
+#define CRPRNT CREPRINT
+#define CFLUSH CDISCARD
+
+/* PROTECTED INCLUSION ENDS HERE */
+#endif /* !_SYS_TTYDEFAULTS_H_ */
+
+/*
+ * #define TTYDEFCHARS to include an array of default control characters.
+ */
+#ifdef TTYDEFCHARS
+cc_t ttydefchars[NCCS] = {
+ CEOF, CEOL, CEOL, CERASE, CWERASE, CKILL, CREPRINT,
+ _POSIX_VDISABLE, CINTR, CQUIT, CSUSP, CDSUSP, CSTART, CSTOP, CLNEXT,
+ CDISCARD, CMIN, CTIME, CSTATUS, _POSIX_VDISABLE
+};
+#undef TTYDEFCHARS
+#endif
diff --git a/sys/sys/types.h b/sys/sys/types.h
new file mode 100644
index 0000000..dbbde58
--- /dev/null
+++ b/sys/sys/types.h
@@ -0,0 +1,261 @@
+/* $OpenBSD: types.h,v 1.48 2019/02/09 04:54:11 guenther Exp $ */
+/* $NetBSD: types.h,v 1.29 1996/11/15 22:48:25 jtc Exp $ */
+
+/*-
+ * Copyright (c) 1982, 1986, 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ *
+ * @(#)types.h 8.4 (Berkeley) 1/21/94
+ */
+
+#ifndef _SYS_TYPES_H_
+#define _SYS_TYPES_H_
+
+#include <sys/cdefs.h>
+#if __BSD_VISIBLE
+#include <sys/endian.h>
+#else
+#include <sys/_endian.h>
+#endif
+
+#if __BSD_VISIBLE
+typedef unsigned char u_char;
+typedef unsigned short u_short;
+typedef unsigned int u_int;
+typedef unsigned long u_long;
+
+typedef unsigned char unchar; /* Sys V compatibility */
+typedef unsigned short ushort; /* Sys V compatibility */
+typedef unsigned int uint; /* Sys V compatibility */
+typedef unsigned long ulong; /* Sys V compatibility */
+
+typedef __cpuid_t cpuid_t; /* CPU id */
+typedef __register_t register_t; /* register-sized type */
+#endif /* __BSD_VISIBLE */
+
+/*
+ * XXX The exact-width bit types should only be exposed if __BSD_VISIBLE
+ * but the rest of the includes are not ready for that yet.
+ */
+#ifndef __BIT_TYPES_DEFINED__
+#define __BIT_TYPES_DEFINED__
+#endif
+
+#ifndef _INT8_T_DEFINED_
+#define _INT8_T_DEFINED_
+typedef __int8_t int8_t;
+#endif
+
+#ifndef _UINT8_T_DEFINED_
+#define _UINT8_T_DEFINED_
+typedef __uint8_t uint8_t;
+#endif
+
+#ifndef _INT16_T_DEFINED_
+#define _INT16_T_DEFINED_
+typedef __int16_t int16_t;
+#endif
+
+#ifndef _UINT16_T_DEFINED_
+#define _UINT16_T_DEFINED_
+typedef __uint16_t uint16_t;
+#endif
+
+#ifndef _INT32_T_DEFINED_
+#define _INT32_T_DEFINED_
+typedef __int32_t int32_t;
+#endif
+
+#ifndef _UINT32_T_DEFINED_
+#define _UINT32_T_DEFINED_
+typedef __uint32_t uint32_t;
+#endif
+
+#ifndef _INT64_T_DEFINED_
+#define _INT64_T_DEFINED_
+typedef __int64_t int64_t;
+#endif
+
+#ifndef _UINT64_T_DEFINED_
+#define _UINT64_T_DEFINED_
+typedef __uint64_t uint64_t;
+#endif
+
+/* BSD-style unsigned bits types */
+typedef __uint8_t u_int8_t;
+typedef __uint16_t u_int16_t;
+typedef __uint32_t u_int32_t;
+typedef __uint64_t u_int64_t;
+
+/* quads, deprecated in favor of 64 bit int types */
+typedef __int64_t quad_t;
+typedef __uint64_t u_quad_t;
+
+#if __BSD_VISIBLE
+/* VM system types */
+typedef __vaddr_t vaddr_t;
+typedef __paddr_t paddr_t;
+typedef __vsize_t vsize_t;
+typedef __psize_t psize_t;
+#endif /* __BSD_VISIBLE */
+
+/* Standard system types */
+typedef __blkcnt_t blkcnt_t; /* blocks allocated for file */
+typedef __blksize_t blksize_t; /* optimal blocksize for I/O */
+typedef char * caddr_t; /* core address */
+typedef __int32_t daddr32_t; /* 32-bit disk address */
+typedef __int64_t daddr_t; /* 64-bit disk address */
+typedef __dev_t dev_t; /* device number */
+typedef __fixpt_t fixpt_t; /* fixed point number */
+typedef __gid_t gid_t; /* group id */
+typedef __id_t id_t; /* may contain pid, uid or gid */
+typedef __ino_t ino_t; /* inode number */
+typedef __key_t key_t; /* IPC key (for Sys V IPC) */
+typedef __mode_t mode_t; /* permissions */
+typedef __nlink_t nlink_t; /* link count */
+typedef __rlim_t rlim_t; /* resource limit */
+typedef __segsz_t segsz_t; /* segment size */
+typedef __swblk_t swblk_t; /* swap offset */
+typedef __uid_t uid_t; /* user id */
+typedef __useconds_t useconds_t; /* microseconds */
+typedef __suseconds_t suseconds_t; /* microseconds (signed) */
+typedef __fsblkcnt_t fsblkcnt_t; /* file system block count */
+typedef __fsfilcnt_t fsfilcnt_t; /* file system file count */
+
+/*
+ * The following types may be defined in multiple header files.
+ */
+#ifndef _CLOCK_T_DEFINED_
+#define _CLOCK_T_DEFINED_
+typedef __clock_t clock_t;
+#endif
+
+#ifndef _CLOCKID_T_DEFINED_
+#define _CLOCKID_T_DEFINED_
+typedef __clockid_t clockid_t;
+#endif
+
+#ifndef _PID_T_DEFINED_
+#define _PID_T_DEFINED_
+typedef __pid_t pid_t;
+#endif
+
+#ifndef _SIZE_T_DEFINED_
+#define _SIZE_T_DEFINED_
+typedef __size_t size_t;
+#endif
+
+#ifndef _SSIZE_T_DEFINED_
+#define _SSIZE_T_DEFINED_
+typedef __ssize_t ssize_t;
+#endif
+
+#ifndef _TIME_T_DEFINED_
+#define _TIME_T_DEFINED_
+typedef __time_t time_t;
+#endif
+
+#ifndef _TIMER_T_DEFINED_
+#define _TIMER_T_DEFINED_
+typedef __timer_t timer_t;
+#endif
+
+#ifndef _OFF_T_DEFINED_
+#define _OFF_T_DEFINED_
+typedef __off_t off_t;
+#endif
+
+/*
+ * These belong in unistd.h, but are placed here too to ensure that
+ * long arguments will be promoted to off_t if the program fails to
+ * include that header or explicitly cast them to off_t.
+ */
+#if __BSD_VISIBLE && !defined(_KERNEL)
+__BEGIN_DECLS
+off_t lseek(int, off_t, int);
+int ftruncate(int, off_t);
+int truncate(const char *, off_t);
+__END_DECLS
+#endif /* __BSD_VISIBLE && !_KERNEL */
+
+#if __BSD_VISIBLE
+/* Major, minor numbers, dev_t's. */
+#define major(x) (((unsigned)(x) >> 8) & 0xff)
+#define minor(x) ((unsigned)((x) & 0xff) | (((x) & 0xffff0000) >> 8))
+#define makedev(x,y) ((dev_t)((((x) & 0xff) << 8) | ((y) & 0xff) | (((y) & 0xffff00) << 8)))
+#endif
+
+#if defined(__STDC__) && defined(_KERNEL)
+/*
+ * Forward structure declarations for function prototypes. We include the
+ * common structures that cross subsystem boundaries here; others are mostly
+ * used in the same place that the structure is defined.
+ */
+struct proc;
+struct pgrp;
+struct ucred;
+struct rusage;
+struct file;
+struct buf;
+struct tty;
+struct uio;
+#endif
+
+#ifdef _KERNEL
+#if defined(__GNUC__) || \
+ (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901)
+/* Support for C99: type _Bool is already built-in. */
+#define false 0
+#define true 1
+
+#else
+/* `_Bool' type must promote to `int' or `unsigned int'. */
+typedef enum {
+ false = 0,
+ true = 1
+} _Bool;
+
+/* And those constants must also be available as macros. */
+#define false false
+#define true true
+
+#endif
+
+/* User visible type `bool' is provided as a macro which may be redefined */
+#define bool _Bool
+
+/* Inform that everything is fine */
+#define __bool_true_false_are_defined 1
+
+#endif /* _KERNEL */
+
+#endif /* !_SYS_TYPES_H_ */
diff --git a/sys/sys/ucred.h b/sys/sys/ucred.h
new file mode 100644
index 0000000..7ce0fd6
--- /dev/null
+++ b/sys/sys/ucred.h
@@ -0,0 +1,84 @@
+/* $OpenBSD: ucred.h,v 1.13 2018/06/21 13:58:21 visa Exp $ */
+/* $NetBSD: ucred.h,v 1.12 1995/06/01 22:44:50 jtc Exp $ */
+
+/*
+ * 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.
+ * 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.
+ *
+ * @(#)ucred.h 8.2 (Berkeley) 1/4/94
+ */
+
+#ifndef _SYS_UCRED_H_
+#define _SYS_UCRED_H_
+
+#include <sys/syslimits.h>
+
+/*
+ * Credentials.
+ */
+struct ucred {
+ u_int cr_ref; /* reference count */
+
+/* The following fields are all copied by crset() */
+#define cr_startcopy cr_uid
+ uid_t cr_uid; /* effective user id */
+ uid_t cr_ruid; /* Real user id. */
+ uid_t cr_svuid; /* Saved effective user id. */
+ gid_t cr_gid; /* effective group id */
+ gid_t cr_rgid; /* Real group id. */
+ gid_t cr_svgid; /* Saved effective group id. */
+ short cr_ngroups; /* number of groups */
+ gid_t cr_groups[NGROUPS_MAX]; /* groups */
+};
+#define NOCRED ((struct ucred *)-1) /* no credential available */
+#define FSCRED ((struct ucred *)-2) /* filesystem credential */
+
+/*
+ * Userspace version, for use in syscalls arguments
+ */
+struct xucred {
+ uid_t cr_uid; /* user id */
+ gid_t cr_gid; /* group id */
+ short cr_ngroups; /* number of groups */
+ gid_t cr_groups[NGROUPS_MAX]; /* groups */
+};
+
+#ifdef _KERNEL
+
+int crfromxucred(struct ucred *, const struct xucred *);
+void crset(struct ucred *, const struct ucred *);
+struct ucred *crcopy(struct ucred *cr);
+struct ucred *crdup(struct ucred *cr);
+void crfree(struct ucred *cr);
+struct ucred *crget(void);
+struct ucred *crhold(struct ucred *);
+int suser(struct proc *p);
+int suser_ucred(struct ucred *cred);
+
+#endif /* _KERNEL */
+
+#endif /* !_SYS_UCRED_H_ */
diff --git a/sys/sys/uio.h b/sys/sys/uio.h
new file mode 100644
index 0000000..fdc4690
--- /dev/null
+++ b/sys/sys/uio.h
@@ -0,0 +1,108 @@
+/* $OpenBSD: uio.h,v 1.19 2018/08/20 16:00:22 mpi Exp $ */
+/* $NetBSD: uio.h,v 1.12 1996/02/09 18:25:45 christos Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 1993, 1994
+ * 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.
+ *
+ * @(#)uio.h 8.5 (Berkeley) 2/22/94
+ */
+
+#ifndef _SYS_UIO_H_
+#define _SYS_UIO_H_
+
+#include <sys/cdefs.h>
+#include <sys/_types.h>
+
+#ifndef _SIZE_T_DEFINED_
+#define _SIZE_T_DEFINED_
+typedef __size_t size_t;
+#endif
+
+#ifndef _SSIZE_T_DEFINED_
+#define _SSIZE_T_DEFINED_
+typedef __ssize_t ssize_t;
+#endif
+
+struct iovec {
+ void *iov_base; /* Base address. */
+ size_t iov_len; /* Length. */
+};
+
+#if __BSD_VISIBLE /* needed by kdump */
+enum uio_rw { UIO_READ, UIO_WRITE };
+
+/* Segment flag values. */
+enum uio_seg {
+ UIO_USERSPACE, /* from user data space */
+ UIO_SYSSPACE /* from system space */
+};
+#endif /* __BSD_VISIBLE */
+
+#ifdef _KERNEL
+struct uio {
+ struct iovec *uio_iov; /* pointer to array of iovecs */
+ int uio_iovcnt; /* number of iovecs in array */
+ off_t uio_offset; /* offset into file this uio corresponds to */
+ size_t uio_resid; /* residual i/o count */
+ enum uio_seg uio_segflg; /* see above */
+ enum uio_rw uio_rw; /* see above */
+ struct proc *uio_procp;/* associated thread or NULL */
+};
+
+/*
+ * Limits
+ */
+#define UIO_SMALLIOV 8 /* 8 on stack, else malloc */
+#endif /* _KERNEL */
+
+#if __BSD_VISIBLE
+#define UIO_MAXIOV 1024 /* Deprecated, use IOV_MAX instead */
+#endif
+
+#ifndef _KERNEL
+__BEGIN_DECLS
+#if __BSD_VISIBLE
+ssize_t preadv(int, const struct iovec *, int, __off_t);
+ssize_t pwritev(int, const struct iovec *, int, __off_t);
+#endif /* __BSD_VISIBLE */
+ssize_t readv(int, const struct iovec *, int);
+ssize_t writev(int, const struct iovec *, int);
+__END_DECLS
+#else
+int ureadc(int c, struct uio *);
+
+struct file;
+int iovec_copyin(const struct iovec *, struct iovec **, struct iovec *,
+ unsigned int, size_t *);
+void iovec_free(struct iovec *, unsigned int );
+int dofilereadv(struct proc *, int, struct uio *, int, register_t *);
+int dofilewritev(struct proc *, int, struct uio *, int, register_t *);
+
+#endif /* !_KERNEL */
+
+#endif /* !_SYS_UIO_H_ */
diff --git a/sys/sys/un.h b/sys/sys/un.h
new file mode 100644
index 0000000..63619fa
--- /dev/null
+++ b/sys/sys/un.h
@@ -0,0 +1,65 @@
+/* $OpenBSD: un.h,v 1.14 2015/07/18 15:00:01 guenther Exp $ */
+/* $NetBSD: un.h,v 1.11 1996/02/04 02:12:47 christos 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.
+ * 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.
+ *
+ * @(#)un.h 8.1 (Berkeley) 6/2/93
+ */
+
+#ifndef _SYS_UN_H_
+#define _SYS_UN_H_
+
+#include <sys/cdefs.h>
+#include <sys/_types.h>
+
+#ifndef _SA_FAMILY_T_DEFINED_
+#define _SA_FAMILY_T_DEFINED_
+typedef __sa_family_t sa_family_t; /* sockaddr address family type */
+#endif
+
+/*
+ * Definitions for UNIX IPC domain.
+ */
+struct sockaddr_un {
+ unsigned char sun_len; /* sockaddr len excluding NUL */
+ sa_family_t sun_family; /* AF_UNIX */
+ char sun_path[104]; /* path name (gag) */
+};
+
+#ifndef _KERNEL
+#if __BSD_VISIBLE
+
+/* actual length of an initialized sockaddr_un */
+#define SUN_LEN(su) \
+ (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
+
+#endif /* __BSD_VISIBLE */
+
+#endif /* _KERNEL */
+#endif /* !_SYS_UN_H_ */
diff --git a/sys/sys/unistd.h b/sys/sys/unistd.h
new file mode 100644
index 0000000..1b90fb1
--- /dev/null
+++ b/sys/sys/unistd.h
@@ -0,0 +1,106 @@
+/* $OpenBSD: unistd.h,v 1.31 2015/07/20 00:56:10 guenther Exp $ */
+/* $NetBSD: unistd.h,v 1.10 1994/06/29 06:46:06 cgd Exp $ */
+
+/*
+ * 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.
+ * 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.
+ *
+ * @(#)unistd.h 8.2 (Berkeley) 1/7/94
+ */
+
+#ifndef _SYS_UNISTD_H_
+#define _SYS_UNISTD_H_
+
+#include <sys/cdefs.h>
+
+#define _POSIX_VDISABLE (0377)
+#define _POSIX_ASYNC_IO (-1)
+#define _POSIX_PRIO_IO (-1)
+#define _POSIX_SYNC_IO (-1)
+
+/* Define the POSIX.1 version we target for compliance. */
+#define _POSIX_VERSION 200809L
+
+/* access function */
+#define F_OK 0 /* test for existence of file */
+#define X_OK 0x01 /* test for execute or search permission */
+#define W_OK 0x02 /* test for write permission */
+#define R_OK 0x04 /* test for read permission */
+
+/* whence values for lseek(2) */
+#define SEEK_SET 0 /* set file offset to offset */
+#define SEEK_CUR 1 /* set file offset to current plus offset */
+#define SEEK_END 2 /* set file offset to EOF plus offset */
+
+#if __BSD_VISIBLE
+/* old BSD whence values for lseek(2); renamed by POSIX 1003.1 */
+#define L_SET SEEK_SET
+#define L_INCR SEEK_CUR
+#define L_XTND SEEK_END
+
+/* the parameters argument passed to the __tfork() syscall */
+struct __tfork {
+ void *tf_tcb;
+ pid_t *tf_tid;
+ void *tf_stack;
+};
+
+/* the parameters argument for the kbind() syscall */
+struct __kbind {
+ void *kb_addr;
+ size_t kb_size;
+};
+#define KBIND_BLOCK_MAX 2 /* powerpc, sparc, and sparc64 need 2 blocks */
+#define KBIND_DATA_MAX 24 /* sparc64 needs 6, four-byte words */
+#endif
+
+/* the pathconf(2) variable values are part of the ABI */
+
+/* configurable pathname variables */
+#define _PC_LINK_MAX 1
+#define _PC_MAX_CANON 2
+#define _PC_MAX_INPUT 3
+#define _PC_NAME_MAX 4
+#define _PC_PATH_MAX 5
+#define _PC_PIPE_BUF 6
+#define _PC_CHOWN_RESTRICTED 7
+#define _PC_NO_TRUNC 8
+#define _PC_VDISABLE 9
+#define _PC_2_SYMLINKS 10
+#define _PC_ALLOC_SIZE_MIN 11
+#define _PC_ASYNC_IO 12
+#define _PC_FILESIZEBITS 13
+#define _PC_PRIO_IO 14
+#define _PC_REC_INCR_XFER_SIZE 15
+#define _PC_REC_MAX_XFER_SIZE 16
+#define _PC_REC_MIN_XFER_SIZE 17
+#define _PC_REC_XFER_ALIGN 18
+#define _PC_SYMLINK_MAX 19
+#define _PC_SYNC_IO 20
+#define _PC_TIMESTAMP_RESOLUTION 21
+
+#endif /* !_SYS_UNISTD_H_ */
diff --git a/sys/sys/unpcb.h b/sys/sys/unpcb.h
new file mode 100644
index 0000000..daa22a1
--- /dev/null
+++ b/sys/sys/unpcb.h
@@ -0,0 +1,111 @@
+/* $OpenBSD: unpcb.h,v 1.17 2019/07/15 12:28:06 bluhm Exp $ */
+/* $NetBSD: unpcb.h,v 1.6 1994/06/29 06:46:08 cgd Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 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.
+ * 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.
+ *
+ * @(#)unpcb.h 8.1 (Berkeley) 6/2/93
+ */
+
+/*
+ * Protocol control block for an active
+ * instance of a UNIX internal protocol.
+ *
+ * A socket may be associated with an vnode in the
+ * file system. If so, the unp_vnode pointer holds
+ * a reference count to this vnode, which should be vrele'd
+ * when the socket goes away.
+ *
+ * A socket may be connected to another socket, in which
+ * case the control block of the socket to which it is connected
+ * is given by unp_conn.
+ *
+ * A socket may be referenced by a number of sockets (e.g. several
+ * sockets may be connected to a datagram socket.) These sockets
+ * are in a linked list starting with unp_refs, linked through
+ * unp_nextref and null-terminated. Note that a socket may be referenced
+ * by a number of other sockets and may also reference a socket (not
+ * necessarily one which is referencing it). This generates
+ * the need for unp_refs and unp_nextref to be separate fields.
+ *
+ * Stream sockets keep copies of receive sockbuf sb_cc and sb_mbcnt
+ * so that changes in the sockbuf may be computed to modify
+ * back pressure on the sender accordingly.
+ */
+
+struct unpcb {
+ struct socket *unp_socket; /* pointer back to socket */
+ struct vnode *unp_vnode; /* if associated with file */
+ struct file *unp_file; /* backpointer for unp_gc() */
+ struct unpcb *unp_conn; /* control block of connected socket */
+ ino_t unp_ino; /* fake inode number */
+ SLIST_HEAD(,unpcb) unp_refs; /* referencing socket linked list */
+ SLIST_ENTRY(unpcb) unp_nextref; /* link in unp_refs list */
+ struct mbuf *unp_addr; /* bound address of socket */
+ long unp_msgcount; /* references from socket rcv buf */
+ int unp_flags; /* this unpcb contains peer eids */
+ struct sockpeercred unp_connid;/* id of peer process */
+ struct timespec unp_ctime; /* holds creation time */
+ LIST_ENTRY(unpcb) unp_link; /* link in per-AF list of sockets */
+};
+
+/*
+ * flag bits in unp_flags
+ */
+#define UNP_FEIDS 0x01 /* unp_connid contains information */
+#define UNP_FEIDSBIND 0x02 /* unp_connid was set by a bind */
+#define UNP_GCMARK 0x04 /* mark during unp_gc() */
+#define UNP_GCDEFER 0x08 /* ref'd, but not marked in this pass */
+#define UNP_GCDEAD 0x10 /* unref'd in this pass */
+
+#define sotounpcb(so) ((struct unpcb *)((so)->so_pcb))
+
+#ifdef _KERNEL
+struct fdpass {
+ struct file *fp;
+ int flags;
+};
+
+int uipc_usrreq(struct socket *, int , struct mbuf *,
+ struct mbuf *, struct mbuf *, struct proc *);
+int uipc_attach(struct socket *, int);
+int uipc_detach(struct socket *);
+
+void unp_init(void);
+int unp_bind(struct unpcb *, struct mbuf *, struct proc *);
+int unp_connect(struct socket *, struct mbuf *, struct proc *);
+int unp_connect2(struct socket *, struct socket *);
+void unp_detach(struct unpcb *);
+void unp_disconnect(struct unpcb *);
+void unp_drop(struct unpcb *, int);
+void unp_gc(void *);
+void unp_shutdown(struct unpcb *);
+int unp_externalize(struct mbuf *, socklen_t, int);
+int unp_internalize(struct mbuf *, struct proc *);
+void unp_dispose(struct mbuf *);
+#endif /* _KERNEL */
diff --git a/sys/sys/user.h b/sys/sys/user.h
new file mode 100644
index 0000000..7ab7205
--- /dev/null
+++ b/sys/sys/user.h
@@ -0,0 +1,48 @@
+/* $OpenBSD: user.h,v 1.9 2014/07/08 23:31:22 deraadt Exp $ */
+/* $NetBSD: user.h,v 1.10 1996/04/09 20:55:49 cgd Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 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.
+ * 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.
+ *
+ * @(#)user.h 8.2 (Berkeley) 9/23/93
+ */
+
+#include <machine/pcb.h>
+#include <sys/resource.h>
+#include <sys/resourcevar.h>
+
+/*
+ * Per process structure containing data that isn't needed in core
+ * when the process isn't running (esp. when swapped out).
+ * This structure may or may not be at the same kernel address
+ * in all processes.
+ */
+
+struct user {
+ struct pcb u_pcb;
+};
diff --git a/sys/sys/utsname.h b/sys/sys/utsname.h
new file mode 100644
index 0000000..22bbd59
--- /dev/null
+++ b/sys/sys/utsname.h
@@ -0,0 +1,59 @@
+/* $OpenBSD: utsname.h,v 1.6 2013/03/24 17:45:50 deraadt Exp $ */
+/* $NetBSD: utsname.h,v 1.6 1994/06/29 06:46:11 cgd Exp $ */
+
+/*-
+ * Copyright (c) 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chuck Karish of Mindcraft, Inc.
+ *
+ * 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.
+ *
+ * @(#)utsname.h 8.1 (Berkeley) 1/4/94
+ */
+
+#ifndef _SYS_UTSNAME_H
+#define _SYS_UTSNAME_H
+
+#define SYS_NMLN 256
+
+struct utsname {
+ char sysname[SYS_NMLN]; /* Name of this OS. */
+ char nodename[SYS_NMLN]; /* Name of this network node. */
+ char release[SYS_NMLN]; /* Release level. */
+ char version[SYS_NMLN]; /* Version level. */
+ char machine[SYS_NMLN]; /* Hardware type. */
+};
+
+#include <sys/cdefs.h>
+
+#ifndef _KERNEL
+__BEGIN_DECLS
+int uname(struct utsname *);
+__END_DECLS
+#endif /* !_KERNEL */
+
+#endif /* !_SYS_UTSNAME_H */
diff --git a/sys/sys/uuid.h b/sys/sys/uuid.h
new file mode 100644
index 0000000..d7353af
--- /dev/null
+++ b/sys/sys/uuid.h
@@ -0,0 +1,75 @@
+/* $OpenBSD: uuid.h,v 1.3 2014/08/31 09:36:39 miod Exp $ */
+/* $NetBSD: uuid.h,v 1.5 2008/11/18 14:01:03 joerg Exp $ */
+
+/*
+ * Copyright (c) 2002 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.
+ *
+ * $FreeBSD: /repoman/r/ncvs/src/sys/sys/uuid.h,v 1.3 2003/05/31 16:47:07 phk Exp $
+ */
+
+#ifndef _SYS_UUID_H_
+#define _SYS_UUID_H_
+
+/* Length of a node address (an IEEE 802 address). */
+#define _UUID_NODE_LEN 6
+
+/* Length of a printed UUID. */
+#define _UUID_BUF_LEN 38
+
+/*
+ * See also:
+ * http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt
+ * http://www.opengroup.org/onlinepubs/009629399/apdxa.htm
+ *
+ * A DCE 1.1 compatible source representation of UUIDs.
+ */
+struct uuid {
+ uint32_t time_low;
+ uint16_t time_mid;
+ uint16_t time_hi_and_version;
+ uint8_t clock_seq_hi_and_reserved;
+ uint8_t clock_seq_low;
+ uint8_t node[_UUID_NODE_LEN];
+};
+
+#ifdef _KERNEL
+
+#define UUID_NODE_LEN _UUID_NODE_LEN
+#define UUID_BUF_LEN _UUID_BUF_LEN
+
+int uuid_snprintf(char *, size_t, const struct uuid *);
+int uuid_printf(const struct uuid *);
+void uuid_dec_be(const void *, struct uuid *);
+void uuid_dec_le(const void *, struct uuid *);
+void uuid_enc_be(void *, const struct uuid *);
+void uuid_enc_le(void *, const struct uuid *);
+
+#else /* _KERNEL */
+
+typedef struct uuid uuid_t;
+
+#endif /* _KERNEL */
+
+#endif /* _SYS_UUID_H_ */
diff --git a/sys/sys/varargs.h b/sys/sys/varargs.h
new file mode 100644
index 0000000..bdd161b
--- /dev/null
+++ b/sys/sys/varargs.h
@@ -0,0 +1,56 @@
+/* $OpenBSD: varargs.h,v 1.3 2019/12/07 06:55:20 visa Exp $ */
+/*
+ * Copyright (c) 2003, 2004 Marc espie <espie@openbsd.org>
+ *
+ * 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.
+ */
+
+#ifndef _VARARGS_H_
+#define _VARARGS_H_
+
+#if defined(__GNUC__) && __GNUC__ >= 3
+/* These macros implement traditional (non-ANSI) varargs
+ for GNU C. */
+
+#define va_alist __builtin_va_alist
+
+#define __va_ellipsis ...
+
+/* ??? We don't process attributes correctly in K&R argument context. */
+typedef int __builtin_va_alist_t __attribute__((__mode__(__word__)));
+
+/* ??? It would be nice to get rid of the ellipsis here. It causes
+ current_function_varargs to be set in cc1. */
+#define va_dcl __builtin_va_alist_t __builtin_va_alist; ...
+
+/* Define __gnuc_va_list, just as in stdarg.h. */
+
+#ifndef __GNUC_VA_LIST
+#define __GNUC_VA_LIST
+typedef __builtin_va_list __gnuc_va_list;
+#endif
+
+#define va_start(v) __builtin_varargs_start((v))
+#define va_end __builtin_va_end
+#define va_arg __builtin_va_arg
+#define __va_copy(d,s) __builtin_va_copy((d),(s))
+
+/* Define va_list from __gnuc_va_list. */
+
+typedef __gnuc_va_list va_list;
+
+#else
+#error "unsupported compiler"
+#endif
+
+#endif /* _VARARGS_H_ */
diff --git a/sys/sys/videoio.h b/sys/sys/videoio.h
new file mode 100644
index 0000000..d9533b3
--- /dev/null
+++ b/sys/sys/videoio.h
@@ -0,0 +1,3372 @@
+/* $OpenBSD: videoio.h,v 1.16 2017/02/17 06:48:33 feinerer Exp $ */
+/*
+ * Video for Linux Two header file
+ *
+ * Copyright (C) 1999-2012 the contributors
+ * Copyright (C) 2012 Nokia Corporation
+ * Contact: Sakari Ailus <sakari.ailus@iki.fi>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * Alternatively you can redistribute this file under the terms of the
+ * BSD license as stated below:
+ *
+ * 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 names of its contributors may not be used to endorse or promote
+ * products derived from this software without specific prior written
+ * permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
+ * OWNER 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.
+ *
+ * Header file for v4l or V4L2 drivers and applications
+ * with public API.
+ * All kernel-specific stuff were moved to media/v4l2-dev.h, so
+ * no #if __KERNEL tests are allowed here
+ *
+ * See https://linuxtv.org for more info
+ *
+ * Author: Bill Dirks <bill@thedirks.org>
+ * Justin Schoeman
+ * Hans Verkuil <hverkuil@xs4all.nl>
+ * et al.
+ */
+
+#ifndef _SYS_VIDEOIO_H_
+#define _SYS_VIDEOIO_H_
+#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/ioccom.h>
+/* Inline #include <linux/v4l2-common.h>
+ * (v4l2-common.h was split off from videodev2.h and has the same BSD license.)
+ *
+ * Begin of v4l2-common.h
+ */
+/*
+ *
+ * Selection interface definitions
+ *
+ */
+
+/* Current cropping area */
+#define V4L2_SEL_TGT_CROP 0x0000
+/* Default cropping area */
+#define V4L2_SEL_TGT_CROP_DEFAULT 0x0001
+/* Cropping bounds */
+#define V4L2_SEL_TGT_CROP_BOUNDS 0x0002
+/* Native frame size */
+#define V4L2_SEL_TGT_NATIVE_SIZE 0x0003
+/* Current composing area */
+#define V4L2_SEL_TGT_COMPOSE 0x0100
+/* Default composing area */
+#define V4L2_SEL_TGT_COMPOSE_DEFAULT 0x0101
+/* Composing bounds */
+#define V4L2_SEL_TGT_COMPOSE_BOUNDS 0x0102
+/* Current composing area plus all padding pixels */
+#define V4L2_SEL_TGT_COMPOSE_PADDED 0x0103
+
+/* Backward compatibility target definitions --- to be removed. */
+#define V4L2_SEL_TGT_CROP_ACTIVE V4L2_SEL_TGT_CROP
+#define V4L2_SEL_TGT_COMPOSE_ACTIVE V4L2_SEL_TGT_COMPOSE
+#define V4L2_SUBDEV_SEL_TGT_CROP_ACTUAL V4L2_SEL_TGT_CROP
+#define V4L2_SUBDEV_SEL_TGT_COMPOSE_ACTUAL V4L2_SEL_TGT_COMPOSE
+#define V4L2_SUBDEV_SEL_TGT_CROP_BOUNDS V4L2_SEL_TGT_CROP_BOUNDS
+#define V4L2_SUBDEV_SEL_TGT_COMPOSE_BOUNDS V4L2_SEL_TGT_COMPOSE_BOUNDS
+
+/* Selection flags */
+#define V4L2_SEL_FLAG_GE (1 << 0)
+#define V4L2_SEL_FLAG_LE (1 << 1)
+#define V4L2_SEL_FLAG_KEEP_CONFIG (1 << 2)
+
+/* Backward compatibility flag definitions --- to be removed. */
+#define V4L2_SUBDEV_SEL_FLAG_SIZE_GE V4L2_SEL_FLAG_GE
+#define V4L2_SUBDEV_SEL_FLAG_SIZE_LE V4L2_SEL_FLAG_LE
+#define V4L2_SUBDEV_SEL_FLAG_KEEP_CONFIG V4L2_SEL_FLAG_KEEP_CONFIG
+
+struct v4l2_edid {
+ u_int32_t pad;
+ u_int32_t start_block;
+ u_int32_t blocks;
+ u_int32_t reserved[5];
+ u_int8_t *edid;
+};
+/*
+ * End of v4l2-common.h
+ */
+/* Inline #include <linux/v4l2-controls.h>
+ * (v4l2-controls.h was split off from videodev2.h and has the same BSD license.)
+ *
+ * Begin of v4l2-controls.h
+ */
+/* Control classes */
+#define V4L2_CTRL_CLASS_USER 0x00980000 /* Old-style 'user' controls */
+#define V4L2_CTRL_CLASS_MPEG 0x00990000 /* MPEG-compression controls */
+#define V4L2_CTRL_CLASS_CAMERA 0x009a0000 /* Camera class controls */
+#define V4L2_CTRL_CLASS_FM_TX 0x009b0000 /* FM Modulator controls */
+#define V4L2_CTRL_CLASS_FLASH 0x009c0000 /* Camera flash controls */
+#define V4L2_CTRL_CLASS_JPEG 0x009d0000 /* JPEG-compression controls */
+#define V4L2_CTRL_CLASS_IMAGE_SOURCE 0x009e0000 /* Image source controls */
+#define V4L2_CTRL_CLASS_IMAGE_PROC 0x009f0000 /* Image processing controls */
+#define V4L2_CTRL_CLASS_DV 0x00a00000 /* Digital Video controls */
+#define V4L2_CTRL_CLASS_FM_RX 0x00a10000 /* FM Receiver controls */
+#define V4L2_CTRL_CLASS_RF_TUNER 0x00a20000 /* RF tuner controls */
+#define V4L2_CTRL_CLASS_DETECT 0x00a30000 /* Detection controls */
+
+/* User-class control IDs */
+
+#define V4L2_CID_BASE (V4L2_CTRL_CLASS_USER | 0x900)
+#define V4L2_CID_USER_BASE V4L2_CID_BASE
+#define V4L2_CID_USER_CLASS (V4L2_CTRL_CLASS_USER | 1)
+#define V4L2_CID_BRIGHTNESS (V4L2_CID_BASE+0)
+#define V4L2_CID_CONTRAST (V4L2_CID_BASE+1)
+#define V4L2_CID_SATURATION (V4L2_CID_BASE+2)
+#define V4L2_CID_HUE (V4L2_CID_BASE+3)
+#define V4L2_CID_AUDIO_VOLUME (V4L2_CID_BASE+5)
+#define V4L2_CID_AUDIO_BALANCE (V4L2_CID_BASE+6)
+#define V4L2_CID_AUDIO_BASS (V4L2_CID_BASE+7)
+#define V4L2_CID_AUDIO_TREBLE (V4L2_CID_BASE+8)
+#define V4L2_CID_AUDIO_MUTE (V4L2_CID_BASE+9)
+#define V4L2_CID_AUDIO_LOUDNESS (V4L2_CID_BASE+10)
+#define V4L2_CID_BLACK_LEVEL (V4L2_CID_BASE+11) /* Deprecated */
+#define V4L2_CID_AUTO_WHITE_BALANCE (V4L2_CID_BASE+12)
+#define V4L2_CID_DO_WHITE_BALANCE (V4L2_CID_BASE+13)
+#define V4L2_CID_RED_BALANCE (V4L2_CID_BASE+14)
+#define V4L2_CID_BLUE_BALANCE (V4L2_CID_BASE+15)
+#define V4L2_CID_GAMMA (V4L2_CID_BASE+16)
+#define V4L2_CID_WHITENESS (V4L2_CID_GAMMA) /* Deprecated */
+#define V4L2_CID_EXPOSURE (V4L2_CID_BASE+17)
+#define V4L2_CID_AUTOGAIN (V4L2_CID_BASE+18)
+#define V4L2_CID_GAIN (V4L2_CID_BASE+19)
+#define V4L2_CID_HFLIP (V4L2_CID_BASE+20)
+#define V4L2_CID_VFLIP (V4L2_CID_BASE+21)
+
+#define V4L2_CID_POWER_LINE_FREQUENCY (V4L2_CID_BASE+24)
+enum v4l2_power_line_frequency {
+ V4L2_CID_POWER_LINE_FREQUENCY_DISABLED = 0,
+ V4L2_CID_POWER_LINE_FREQUENCY_50HZ = 1,
+ V4L2_CID_POWER_LINE_FREQUENCY_60HZ = 2,
+ V4L2_CID_POWER_LINE_FREQUENCY_AUTO = 3,
+};
+#define V4L2_CID_HUE_AUTO (V4L2_CID_BASE+25)
+#define V4L2_CID_WHITE_BALANCE_TEMPERATURE (V4L2_CID_BASE+26)
+#define V4L2_CID_SHARPNESS (V4L2_CID_BASE+27)
+#define V4L2_CID_BACKLIGHT_COMPENSATION (V4L2_CID_BASE+28)
+#define V4L2_CID_CHROMA_AGC (V4L2_CID_BASE+29)
+#define V4L2_CID_COLOR_KILLER (V4L2_CID_BASE+30)
+#define V4L2_CID_COLORFX (V4L2_CID_BASE+31)
+enum v4l2_colorfx {
+ V4L2_COLORFX_NONE = 0,
+ V4L2_COLORFX_BW = 1,
+ V4L2_COLORFX_SEPIA = 2,
+ V4L2_COLORFX_NEGATIVE = 3,
+ V4L2_COLORFX_EMBOSS = 4,
+ V4L2_COLORFX_SKETCH = 5,
+ V4L2_COLORFX_SKY_BLUE = 6,
+ V4L2_COLORFX_GRASS_GREEN = 7,
+ V4L2_COLORFX_SKIN_WHITEN = 8,
+ V4L2_COLORFX_VIVID = 9,
+ V4L2_COLORFX_AQUA = 10,
+ V4L2_COLORFX_ART_FREEZE = 11,
+ V4L2_COLORFX_SILHOUETTE = 12,
+ V4L2_COLORFX_SOLARIZATION = 13,
+ V4L2_COLORFX_ANTIQUE = 14,
+ V4L2_COLORFX_SET_CBCR = 15,
+};
+#define V4L2_CID_AUTOBRIGHTNESS (V4L2_CID_BASE+32)
+#define V4L2_CID_BAND_STOP_FILTER (V4L2_CID_BASE+33)
+
+#define V4L2_CID_ROTATE (V4L2_CID_BASE+34)
+#define V4L2_CID_BG_COLOR (V4L2_CID_BASE+35)
+
+#define V4L2_CID_CHROMA_GAIN (V4L2_CID_BASE+36)
+
+#define V4L2_CID_ILLUMINATORS_1 (V4L2_CID_BASE+37)
+#define V4L2_CID_ILLUMINATORS_2 (V4L2_CID_BASE+38)
+
+#define V4L2_CID_MIN_BUFFERS_FOR_CAPTURE (V4L2_CID_BASE+39)
+#define V4L2_CID_MIN_BUFFERS_FOR_OUTPUT (V4L2_CID_BASE+40)
+
+#define V4L2_CID_ALPHA_COMPONENT (V4L2_CID_BASE+41)
+#define V4L2_CID_COLORFX_CBCR (V4L2_CID_BASE+42)
+
+/* last CID + 1 */
+#define V4L2_CID_LASTP1 (V4L2_CID_BASE+43)
+
+/* USER-class private control IDs */
+
+/* The base for the meye driver controls. See linux/meye.h for the list
+ * of controls. We reserve 16 controls for this driver. */
+#define V4L2_CID_USER_MEYE_BASE (V4L2_CID_USER_BASE + 0x1000)
+
+/* The base for the bttv driver controls.
+ * We reserve 32 controls for this driver. */
+#define V4L2_CID_USER_BTTV_BASE (V4L2_CID_USER_BASE + 0x1010)
+
+
+/* The base for the s2255 driver controls.
+ * We reserve 16 controls for this driver. */
+#define V4L2_CID_USER_S2255_BASE (V4L2_CID_USER_BASE + 0x1030)
+
+/*
+ * The base for the si476x driver controls. See include/media/drv-intf/si476x.h
+ * for the list of controls. Total of 16 controls is reserved for this driver
+ */
+#define V4L2_CID_USER_SI476X_BASE (V4L2_CID_USER_BASE + 0x1040)
+
+/* The base for the TI VPE driver controls. Total of 16 controls is reserved for
+ * this driver */
+#define V4L2_CID_USER_TI_VPE_BASE (V4L2_CID_USER_BASE + 0x1050)
+
+/* The base for the saa7134 driver controls.
+ * We reserve 16 controls for this driver. */
+#define V4L2_CID_USER_SAA7134_BASE (V4L2_CID_USER_BASE + 0x1060)
+
+/* The base for the adv7180 driver controls.
+ * We reserve 16 controls for this driver. */
+#define V4L2_CID_USER_ADV7180_BASE (V4L2_CID_USER_BASE + 0x1070)
+
+/* The base for the tc358743 driver controls.
+ * We reserve 16 controls for this driver. */
+#define V4L2_CID_USER_TC358743_BASE (V4L2_CID_USER_BASE + 0x1080)
+
+/* MPEG-class control IDs */
+/* The MPEG controls are applicable to all codec controls
+ * and the 'MPEG' part of the define is historical */
+
+#define V4L2_CID_MPEG_BASE (V4L2_CTRL_CLASS_MPEG | 0x900)
+#define V4L2_CID_MPEG_CLASS (V4L2_CTRL_CLASS_MPEG | 1)
+
+/* MPEG streams, specific to multiplexed streams */
+#define V4L2_CID_MPEG_STREAM_TYPE (V4L2_CID_MPEG_BASE+0)
+enum v4l2_mpeg_stream_type {
+ V4L2_MPEG_STREAM_TYPE_MPEG2_PS = 0, /* MPEG-2 program stream */
+ V4L2_MPEG_STREAM_TYPE_MPEG2_TS = 1, /* MPEG-2 transport stream */
+ V4L2_MPEG_STREAM_TYPE_MPEG1_SS = 2, /* MPEG-1 system stream */
+ V4L2_MPEG_STREAM_TYPE_MPEG2_DVD = 3, /* MPEG-2 DVD-compatible stream */
+ V4L2_MPEG_STREAM_TYPE_MPEG1_VCD = 4, /* MPEG-1 VCD-compatible stream */
+ V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD = 5, /* MPEG-2 SVCD-compatible stream */
+};
+#define V4L2_CID_MPEG_STREAM_PID_PMT (V4L2_CID_MPEG_BASE+1)
+#define V4L2_CID_MPEG_STREAM_PID_AUDIO (V4L2_CID_MPEG_BASE+2)
+#define V4L2_CID_MPEG_STREAM_PID_VIDEO (V4L2_CID_MPEG_BASE+3)
+#define V4L2_CID_MPEG_STREAM_PID_PCR (V4L2_CID_MPEG_BASE+4)
+#define V4L2_CID_MPEG_STREAM_PES_ID_AUDIO (V4L2_CID_MPEG_BASE+5)
+#define V4L2_CID_MPEG_STREAM_PES_ID_VIDEO (V4L2_CID_MPEG_BASE+6)
+#define V4L2_CID_MPEG_STREAM_VBI_FMT (V4L2_CID_MPEG_BASE+7)
+enum v4l2_mpeg_stream_vbi_fmt {
+ V4L2_MPEG_STREAM_VBI_FMT_NONE = 0, /* No VBI in the MPEG stream */
+ V4L2_MPEG_STREAM_VBI_FMT_IVTV = 1, /* VBI in private packets, IVTV format */
+};
+
+/* MPEG audio controls specific to multiplexed streams */
+#define V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ (V4L2_CID_MPEG_BASE+100)
+enum v4l2_mpeg_audio_sampling_freq {
+ V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100 = 0,
+ V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000 = 1,
+ V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000 = 2,
+};
+#define V4L2_CID_MPEG_AUDIO_ENCODING (V4L2_CID_MPEG_BASE+101)
+enum v4l2_mpeg_audio_encoding {
+ V4L2_MPEG_AUDIO_ENCODING_LAYER_1 = 0,
+ V4L2_MPEG_AUDIO_ENCODING_LAYER_2 = 1,
+ V4L2_MPEG_AUDIO_ENCODING_LAYER_3 = 2,
+ V4L2_MPEG_AUDIO_ENCODING_AAC = 3,
+ V4L2_MPEG_AUDIO_ENCODING_AC3 = 4,
+};
+#define V4L2_CID_MPEG_AUDIO_L1_BITRATE (V4L2_CID_MPEG_BASE+102)
+enum v4l2_mpeg_audio_l1_bitrate {
+ V4L2_MPEG_AUDIO_L1_BITRATE_32K = 0,
+ V4L2_MPEG_AUDIO_L1_BITRATE_64K = 1,
+ V4L2_MPEG_AUDIO_L1_BITRATE_96K = 2,
+ V4L2_MPEG_AUDIO_L1_BITRATE_128K = 3,
+ V4L2_MPEG_AUDIO_L1_BITRATE_160K = 4,
+ V4L2_MPEG_AUDIO_L1_BITRATE_192K = 5,
+ V4L2_MPEG_AUDIO_L1_BITRATE_224K = 6,
+ V4L2_MPEG_AUDIO_L1_BITRATE_256K = 7,
+ V4L2_MPEG_AUDIO_L1_BITRATE_288K = 8,
+ V4L2_MPEG_AUDIO_L1_BITRATE_320K = 9,
+ V4L2_MPEG_AUDIO_L1_BITRATE_352K = 10,
+ V4L2_MPEG_AUDIO_L1_BITRATE_384K = 11,
+ V4L2_MPEG_AUDIO_L1_BITRATE_416K = 12,
+ V4L2_MPEG_AUDIO_L1_BITRATE_448K = 13,
+};
+#define V4L2_CID_MPEG_AUDIO_L2_BITRATE (V4L2_CID_MPEG_BASE+103)
+enum v4l2_mpeg_audio_l2_bitrate {
+ V4L2_MPEG_AUDIO_L2_BITRATE_32K = 0,
+ V4L2_MPEG_AUDIO_L2_BITRATE_48K = 1,
+ V4L2_MPEG_AUDIO_L2_BITRATE_56K = 2,
+ V4L2_MPEG_AUDIO_L2_BITRATE_64K = 3,
+ V4L2_MPEG_AUDIO_L2_BITRATE_80K = 4,
+ V4L2_MPEG_AUDIO_L2_BITRATE_96K = 5,
+ V4L2_MPEG_AUDIO_L2_BITRATE_112K = 6,
+ V4L2_MPEG_AUDIO_L2_BITRATE_128K = 7,
+ V4L2_MPEG_AUDIO_L2_BITRATE_160K = 8,
+ V4L2_MPEG_AUDIO_L2_BITRATE_192K = 9,
+ V4L2_MPEG_AUDIO_L2_BITRATE_224K = 10,
+ V4L2_MPEG_AUDIO_L2_BITRATE_256K = 11,
+ V4L2_MPEG_AUDIO_L2_BITRATE_320K = 12,
+ V4L2_MPEG_AUDIO_L2_BITRATE_384K = 13,
+};
+#define V4L2_CID_MPEG_AUDIO_L3_BITRATE (V4L2_CID_MPEG_BASE+104)
+enum v4l2_mpeg_audio_l3_bitrate {
+ V4L2_MPEG_AUDIO_L3_BITRATE_32K = 0,
+ V4L2_MPEG_AUDIO_L3_BITRATE_40K = 1,
+ V4L2_MPEG_AUDIO_L3_BITRATE_48K = 2,
+ V4L2_MPEG_AUDIO_L3_BITRATE_56K = 3,
+ V4L2_MPEG_AUDIO_L3_BITRATE_64K = 4,
+ V4L2_MPEG_AUDIO_L3_BITRATE_80K = 5,
+ V4L2_MPEG_AUDIO_L3_BITRATE_96K = 6,
+ V4L2_MPEG_AUDIO_L3_BITRATE_112K = 7,
+ V4L2_MPEG_AUDIO_L3_BITRATE_128K = 8,
+ V4L2_MPEG_AUDIO_L3_BITRATE_160K = 9,
+ V4L2_MPEG_AUDIO_L3_BITRATE_192K = 10,
+ V4L2_MPEG_AUDIO_L3_BITRATE_224K = 11,
+ V4L2_MPEG_AUDIO_L3_BITRATE_256K = 12,
+ V4L2_MPEG_AUDIO_L3_BITRATE_320K = 13,
+};
+#define V4L2_CID_MPEG_AUDIO_MODE (V4L2_CID_MPEG_BASE+105)
+enum v4l2_mpeg_audio_mode {
+ V4L2_MPEG_AUDIO_MODE_STEREO = 0,
+ V4L2_MPEG_AUDIO_MODE_JOINT_STEREO = 1,
+ V4L2_MPEG_AUDIO_MODE_DUAL = 2,
+ V4L2_MPEG_AUDIO_MODE_MONO = 3,
+};
+#define V4L2_CID_MPEG_AUDIO_MODE_EXTENSION (V4L2_CID_MPEG_BASE+106)
+enum v4l2_mpeg_audio_mode_extension {
+ V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4 = 0,
+ V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_8 = 1,
+ V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_12 = 2,
+ V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_16 = 3,
+};
+#define V4L2_CID_MPEG_AUDIO_EMPHASIS (V4L2_CID_MPEG_BASE+107)
+enum v4l2_mpeg_audio_emphasis {
+ V4L2_MPEG_AUDIO_EMPHASIS_NONE = 0,
+ V4L2_MPEG_AUDIO_EMPHASIS_50_DIV_15_uS = 1,
+ V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17 = 2,
+};
+#define V4L2_CID_MPEG_AUDIO_CRC (V4L2_CID_MPEG_BASE+108)
+enum v4l2_mpeg_audio_crc {
+ V4L2_MPEG_AUDIO_CRC_NONE = 0,
+ V4L2_MPEG_AUDIO_CRC_CRC16 = 1,
+};
+#define V4L2_CID_MPEG_AUDIO_MUTE (V4L2_CID_MPEG_BASE+109)
+#define V4L2_CID_MPEG_AUDIO_AAC_BITRATE (V4L2_CID_MPEG_BASE+110)
+#define V4L2_CID_MPEG_AUDIO_AC3_BITRATE (V4L2_CID_MPEG_BASE+111)
+enum v4l2_mpeg_audio_ac3_bitrate {
+ V4L2_MPEG_AUDIO_AC3_BITRATE_32K = 0,
+ V4L2_MPEG_AUDIO_AC3_BITRATE_40K = 1,
+ V4L2_MPEG_AUDIO_AC3_BITRATE_48K = 2,
+ V4L2_MPEG_AUDIO_AC3_BITRATE_56K = 3,
+ V4L2_MPEG_AUDIO_AC3_BITRATE_64K = 4,
+ V4L2_MPEG_AUDIO_AC3_BITRATE_80K = 5,
+ V4L2_MPEG_AUDIO_AC3_BITRATE_96K = 6,
+ V4L2_MPEG_AUDIO_AC3_BITRATE_112K = 7,
+ V4L2_MPEG_AUDIO_AC3_BITRATE_128K = 8,
+ V4L2_MPEG_AUDIO_AC3_BITRATE_160K = 9,
+ V4L2_MPEG_AUDIO_AC3_BITRATE_192K = 10,
+ V4L2_MPEG_AUDIO_AC3_BITRATE_224K = 11,
+ V4L2_MPEG_AUDIO_AC3_BITRATE_256K = 12,
+ V4L2_MPEG_AUDIO_AC3_BITRATE_320K = 13,
+ V4L2_MPEG_AUDIO_AC3_BITRATE_384K = 14,
+ V4L2_MPEG_AUDIO_AC3_BITRATE_448K = 15,
+ V4L2_MPEG_AUDIO_AC3_BITRATE_512K = 16,
+ V4L2_MPEG_AUDIO_AC3_BITRATE_576K = 17,
+ V4L2_MPEG_AUDIO_AC3_BITRATE_640K = 18,
+};
+#define V4L2_CID_MPEG_AUDIO_DEC_PLAYBACK (V4L2_CID_MPEG_BASE+112)
+enum v4l2_mpeg_audio_dec_playback {
+ V4L2_MPEG_AUDIO_DEC_PLAYBACK_AUTO = 0,
+ V4L2_MPEG_AUDIO_DEC_PLAYBACK_STEREO = 1,
+ V4L2_MPEG_AUDIO_DEC_PLAYBACK_LEFT = 2,
+ V4L2_MPEG_AUDIO_DEC_PLAYBACK_RIGHT = 3,
+ V4L2_MPEG_AUDIO_DEC_PLAYBACK_MONO = 4,
+ V4L2_MPEG_AUDIO_DEC_PLAYBACK_SWAPPED_STEREO = 5,
+};
+#define V4L2_CID_MPEG_AUDIO_DEC_MULTILINGUAL_PLAYBACK (V4L2_CID_MPEG_BASE+113)
+
+/* MPEG video controls specific to multiplexed streams */
+#define V4L2_CID_MPEG_VIDEO_ENCODING (V4L2_CID_MPEG_BASE+200)
+enum v4l2_mpeg_video_encoding {
+ V4L2_MPEG_VIDEO_ENCODING_MPEG_1 = 0,
+ V4L2_MPEG_VIDEO_ENCODING_MPEG_2 = 1,
+ V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC = 2,
+};
+#define V4L2_CID_MPEG_VIDEO_ASPECT (V4L2_CID_MPEG_BASE+201)
+enum v4l2_mpeg_video_aspect {
+ V4L2_MPEG_VIDEO_ASPECT_1x1 = 0,
+ V4L2_MPEG_VIDEO_ASPECT_4x3 = 1,
+ V4L2_MPEG_VIDEO_ASPECT_16x9 = 2,
+ V4L2_MPEG_VIDEO_ASPECT_221x100 = 3,
+};
+#define V4L2_CID_MPEG_VIDEO_B_FRAMES (V4L2_CID_MPEG_BASE+202)
+#define V4L2_CID_MPEG_VIDEO_GOP_SIZE (V4L2_CID_MPEG_BASE+203)
+#define V4L2_CID_MPEG_VIDEO_GOP_CLOSURE (V4L2_CID_MPEG_BASE+204)
+#define V4L2_CID_MPEG_VIDEO_PULLDOWN (V4L2_CID_MPEG_BASE+205)
+#define V4L2_CID_MPEG_VIDEO_BITRATE_MODE (V4L2_CID_MPEG_BASE+206)
+enum v4l2_mpeg_video_bitrate_mode {
+ V4L2_MPEG_VIDEO_BITRATE_MODE_VBR = 0,
+ V4L2_MPEG_VIDEO_BITRATE_MODE_CBR = 1,
+};
+#define V4L2_CID_MPEG_VIDEO_BITRATE (V4L2_CID_MPEG_BASE+207)
+#define V4L2_CID_MPEG_VIDEO_BITRATE_PEAK (V4L2_CID_MPEG_BASE+208)
+#define V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION (V4L2_CID_MPEG_BASE+209)
+#define V4L2_CID_MPEG_VIDEO_MUTE (V4L2_CID_MPEG_BASE+210)
+#define V4L2_CID_MPEG_VIDEO_MUTE_YUV (V4L2_CID_MPEG_BASE+211)
+#define V4L2_CID_MPEG_VIDEO_DECODER_SLICE_INTERFACE (V4L2_CID_MPEG_BASE+212)
+#define V4L2_CID_MPEG_VIDEO_DECODER_MPEG4_DEBLOCK_FILTER (V4L2_CID_MPEG_BASE+213)
+#define V4L2_CID_MPEG_VIDEO_CYCLIC_INTRA_REFRESH_MB (V4L2_CID_MPEG_BASE+214)
+#define V4L2_CID_MPEG_VIDEO_FRAME_RC_ENABLE (V4L2_CID_MPEG_BASE+215)
+#define V4L2_CID_MPEG_VIDEO_HEADER_MODE (V4L2_CID_MPEG_BASE+216)
+enum v4l2_mpeg_video_header_mode {
+ V4L2_MPEG_VIDEO_HEADER_MODE_SEPARATE = 0,
+ V4L2_MPEG_VIDEO_HEADER_MODE_JOINED_WITH_1ST_FRAME = 1,
+
+};
+#define V4L2_CID_MPEG_VIDEO_MAX_REF_PIC (V4L2_CID_MPEG_BASE+217)
+#define V4L2_CID_MPEG_VIDEO_MB_RC_ENABLE (V4L2_CID_MPEG_BASE+218)
+#define V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_BYTES (V4L2_CID_MPEG_BASE+219)
+#define V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MAX_MB (V4L2_CID_MPEG_BASE+220)
+#define V4L2_CID_MPEG_VIDEO_MULTI_SLICE_MODE (V4L2_CID_MPEG_BASE+221)
+enum v4l2_mpeg_video_multi_slice_mode {
+ V4L2_MPEG_VIDEO_MULTI_SLICE_MODE_SINGLE = 0,
+ V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_MB = 1,
+ V4L2_MPEG_VIDEO_MULTI_SICE_MODE_MAX_BYTES = 2,
+};
+#define V4L2_CID_MPEG_VIDEO_VBV_SIZE (V4L2_CID_MPEG_BASE+222)
+#define V4L2_CID_MPEG_VIDEO_DEC_PTS (V4L2_CID_MPEG_BASE+223)
+#define V4L2_CID_MPEG_VIDEO_DEC_FRAME (V4L2_CID_MPEG_BASE+224)
+#define V4L2_CID_MPEG_VIDEO_VBV_DELAY (V4L2_CID_MPEG_BASE+225)
+#define V4L2_CID_MPEG_VIDEO_REPEAT_SEQ_HEADER (V4L2_CID_MPEG_BASE+226)
+#define V4L2_CID_MPEG_VIDEO_MV_H_SEARCH_RANGE (V4L2_CID_MPEG_BASE+227)
+#define V4L2_CID_MPEG_VIDEO_MV_V_SEARCH_RANGE (V4L2_CID_MPEG_BASE+228)
+#define V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME (V4L2_CID_MPEG_BASE+229)
+
+#define V4L2_CID_MPEG_VIDEO_H263_I_FRAME_QP (V4L2_CID_MPEG_BASE+300)
+#define V4L2_CID_MPEG_VIDEO_H263_P_FRAME_QP (V4L2_CID_MPEG_BASE+301)
+#define V4L2_CID_MPEG_VIDEO_H263_B_FRAME_QP (V4L2_CID_MPEG_BASE+302)
+#define V4L2_CID_MPEG_VIDEO_H263_MIN_QP (V4L2_CID_MPEG_BASE+303)
+#define V4L2_CID_MPEG_VIDEO_H263_MAX_QP (V4L2_CID_MPEG_BASE+304)
+#define V4L2_CID_MPEG_VIDEO_H264_I_FRAME_QP (V4L2_CID_MPEG_BASE+350)
+#define V4L2_CID_MPEG_VIDEO_H264_P_FRAME_QP (V4L2_CID_MPEG_BASE+351)
+#define V4L2_CID_MPEG_VIDEO_H264_B_FRAME_QP (V4L2_CID_MPEG_BASE+352)
+#define V4L2_CID_MPEG_VIDEO_H264_MIN_QP (V4L2_CID_MPEG_BASE+353)
+#define V4L2_CID_MPEG_VIDEO_H264_MAX_QP (V4L2_CID_MPEG_BASE+354)
+#define V4L2_CID_MPEG_VIDEO_H264_8X8_TRANSFORM (V4L2_CID_MPEG_BASE+355)
+#define V4L2_CID_MPEG_VIDEO_H264_CPB_SIZE (V4L2_CID_MPEG_BASE+356)
+#define V4L2_CID_MPEG_VIDEO_H264_ENTROPY_MODE (V4L2_CID_MPEG_BASE+357)
+enum v4l2_mpeg_video_h264_entropy_mode {
+ V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CAVLC = 0,
+ V4L2_MPEG_VIDEO_H264_ENTROPY_MODE_CABAC = 1,
+};
+#define V4L2_CID_MPEG_VIDEO_H264_I_PERIOD (V4L2_CID_MPEG_BASE+358)
+#define V4L2_CID_MPEG_VIDEO_H264_LEVEL (V4L2_CID_MPEG_BASE+359)
+enum v4l2_mpeg_video_h264_level {
+ V4L2_MPEG_VIDEO_H264_LEVEL_1_0 = 0,
+ V4L2_MPEG_VIDEO_H264_LEVEL_1B = 1,
+ V4L2_MPEG_VIDEO_H264_LEVEL_1_1 = 2,
+ V4L2_MPEG_VIDEO_H264_LEVEL_1_2 = 3,
+ V4L2_MPEG_VIDEO_H264_LEVEL_1_3 = 4,
+ V4L2_MPEG_VIDEO_H264_LEVEL_2_0 = 5,
+ V4L2_MPEG_VIDEO_H264_LEVEL_2_1 = 6,
+ V4L2_MPEG_VIDEO_H264_LEVEL_2_2 = 7,
+ V4L2_MPEG_VIDEO_H264_LEVEL_3_0 = 8,
+ V4L2_MPEG_VIDEO_H264_LEVEL_3_1 = 9,
+ V4L2_MPEG_VIDEO_H264_LEVEL_3_2 = 10,
+ V4L2_MPEG_VIDEO_H264_LEVEL_4_0 = 11,
+ V4L2_MPEG_VIDEO_H264_LEVEL_4_1 = 12,
+ V4L2_MPEG_VIDEO_H264_LEVEL_4_2 = 13,
+ V4L2_MPEG_VIDEO_H264_LEVEL_5_0 = 14,
+ V4L2_MPEG_VIDEO_H264_LEVEL_5_1 = 15,
+};
+#define V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_ALPHA (V4L2_CID_MPEG_BASE+360)
+#define V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_BETA (V4L2_CID_MPEG_BASE+361)
+#define V4L2_CID_MPEG_VIDEO_H264_LOOP_FILTER_MODE (V4L2_CID_MPEG_BASE+362)
+enum v4l2_mpeg_video_h264_loop_filter_mode {
+ V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_ENABLED = 0,
+ V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED = 1,
+ V4L2_MPEG_VIDEO_H264_LOOP_FILTER_MODE_DISABLED_AT_SLICE_BOUNDARY = 2,
+};
+#define V4L2_CID_MPEG_VIDEO_H264_PROFILE (V4L2_CID_MPEG_BASE+363)
+enum v4l2_mpeg_video_h264_profile {
+ V4L2_MPEG_VIDEO_H264_PROFILE_BASELINE = 0,
+ V4L2_MPEG_VIDEO_H264_PROFILE_CONSTRAINED_BASELINE = 1,
+ V4L2_MPEG_VIDEO_H264_PROFILE_MAIN = 2,
+ V4L2_MPEG_VIDEO_H264_PROFILE_EXTENDED = 3,
+ V4L2_MPEG_VIDEO_H264_PROFILE_HIGH = 4,
+ V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_10 = 5,
+ V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_422 = 6,
+ V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_444_PREDICTIVE = 7,
+ V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_10_INTRA = 8,
+ V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_422_INTRA = 9,
+ V4L2_MPEG_VIDEO_H264_PROFILE_HIGH_444_INTRA = 10,
+ V4L2_MPEG_VIDEO_H264_PROFILE_CAVLC_444_INTRA = 11,
+ V4L2_MPEG_VIDEO_H264_PROFILE_SCALABLE_BASELINE = 12,
+ V4L2_MPEG_VIDEO_H264_PROFILE_SCALABLE_HIGH = 13,
+ V4L2_MPEG_VIDEO_H264_PROFILE_SCALABLE_HIGH_INTRA = 14,
+ V4L2_MPEG_VIDEO_H264_PROFILE_STEREO_HIGH = 15,
+ V4L2_MPEG_VIDEO_H264_PROFILE_MULTIVIEW_HIGH = 16,
+};
+#define V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_HEIGHT (V4L2_CID_MPEG_BASE+364)
+#define V4L2_CID_MPEG_VIDEO_H264_VUI_EXT_SAR_WIDTH (V4L2_CID_MPEG_BASE+365)
+#define V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_ENABLE (V4L2_CID_MPEG_BASE+366)
+#define V4L2_CID_MPEG_VIDEO_H264_VUI_SAR_IDC (V4L2_CID_MPEG_BASE+367)
+enum v4l2_mpeg_video_h264_vui_sar_idc {
+ V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_UNSPECIFIED = 0,
+ V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_1x1 = 1,
+ V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_12x11 = 2,
+ V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_10x11 = 3,
+ V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_16x11 = 4,
+ V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_40x33 = 5,
+ V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_24x11 = 6,
+ V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_20x11 = 7,
+ V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_32x11 = 8,
+ V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_80x33 = 9,
+ V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_18x11 = 10,
+ V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_15x11 = 11,
+ V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_64x33 = 12,
+ V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_160x99 = 13,
+ V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_4x3 = 14,
+ V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_3x2 = 15,
+ V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_2x1 = 16,
+ V4L2_MPEG_VIDEO_H264_VUI_SAR_IDC_EXTENDED = 17,
+};
+#define V4L2_CID_MPEG_VIDEO_H264_SEI_FRAME_PACKING (V4L2_CID_MPEG_BASE+368)
+#define V4L2_CID_MPEG_VIDEO_H264_SEI_FP_CURRENT_FRAME_0 (V4L2_CID_MPEG_BASE+369)
+#define V4L2_CID_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE (V4L2_CID_MPEG_BASE+370)
+enum v4l2_mpeg_video_h264_sei_fp_arrangement_type {
+ V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_CHECKERBOARD = 0,
+ V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_COLUMN = 1,
+ V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_ROW = 2,
+ V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_SIDE_BY_SIDE = 3,
+ V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_TOP_BOTTOM = 4,
+ V4L2_MPEG_VIDEO_H264_SEI_FP_ARRANGEMENT_TYPE_TEMPORAL = 5,
+};
+#define V4L2_CID_MPEG_VIDEO_H264_FMO (V4L2_CID_MPEG_BASE+371)
+#define V4L2_CID_MPEG_VIDEO_H264_FMO_MAP_TYPE (V4L2_CID_MPEG_BASE+372)
+enum v4l2_mpeg_video_h264_fmo_map_type {
+ V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_INTERLEAVED_SLICES = 0,
+ V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_SCATTERED_SLICES = 1,
+ V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_FOREGROUND_WITH_LEFT_OVER = 2,
+ V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_BOX_OUT = 3,
+ V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_RASTER_SCAN = 4,
+ V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_WIPE_SCAN = 5,
+ V4L2_MPEG_VIDEO_H264_FMO_MAP_TYPE_EXPLICIT = 6,
+};
+#define V4L2_CID_MPEG_VIDEO_H264_FMO_SLICE_GROUP (V4L2_CID_MPEG_BASE+373)
+#define V4L2_CID_MPEG_VIDEO_H264_FMO_CHANGE_DIRECTION (V4L2_CID_MPEG_BASE+374)
+enum v4l2_mpeg_video_h264_fmo_change_dir {
+ V4L2_MPEG_VIDEO_H264_FMO_CHANGE_DIR_RIGHT = 0,
+ V4L2_MPEG_VIDEO_H264_FMO_CHANGE_DIR_LEFT = 1,
+};
+#define V4L2_CID_MPEG_VIDEO_H264_FMO_CHANGE_RATE (V4L2_CID_MPEG_BASE+375)
+#define V4L2_CID_MPEG_VIDEO_H264_FMO_RUN_LENGTH (V4L2_CID_MPEG_BASE+376)
+#define V4L2_CID_MPEG_VIDEO_H264_ASO (V4L2_CID_MPEG_BASE+377)
+#define V4L2_CID_MPEG_VIDEO_H264_ASO_SLICE_ORDER (V4L2_CID_MPEG_BASE+378)
+#define V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING (V4L2_CID_MPEG_BASE+379)
+#define V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_TYPE (V4L2_CID_MPEG_BASE+380)
+enum v4l2_mpeg_video_h264_hierarchical_coding_type {
+ V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_B = 0,
+ V4L2_MPEG_VIDEO_H264_HIERARCHICAL_CODING_P = 1,
+};
+#define V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER (V4L2_CID_MPEG_BASE+381)
+#define V4L2_CID_MPEG_VIDEO_H264_HIERARCHICAL_CODING_LAYER_QP (V4L2_CID_MPEG_BASE+382)
+#define V4L2_CID_MPEG_VIDEO_MPEG4_I_FRAME_QP (V4L2_CID_MPEG_BASE+400)
+#define V4L2_CID_MPEG_VIDEO_MPEG4_P_FRAME_QP (V4L2_CID_MPEG_BASE+401)
+#define V4L2_CID_MPEG_VIDEO_MPEG4_B_FRAME_QP (V4L2_CID_MPEG_BASE+402)
+#define V4L2_CID_MPEG_VIDEO_MPEG4_MIN_QP (V4L2_CID_MPEG_BASE+403)
+#define V4L2_CID_MPEG_VIDEO_MPEG4_MAX_QP (V4L2_CID_MPEG_BASE+404)
+#define V4L2_CID_MPEG_VIDEO_MPEG4_LEVEL (V4L2_CID_MPEG_BASE+405)
+enum v4l2_mpeg_video_mpeg4_level {
+ V4L2_MPEG_VIDEO_MPEG4_LEVEL_0 = 0,
+ V4L2_MPEG_VIDEO_MPEG4_LEVEL_0B = 1,
+ V4L2_MPEG_VIDEO_MPEG4_LEVEL_1 = 2,
+ V4L2_MPEG_VIDEO_MPEG4_LEVEL_2 = 3,
+ V4L2_MPEG_VIDEO_MPEG4_LEVEL_3 = 4,
+ V4L2_MPEG_VIDEO_MPEG4_LEVEL_3B = 5,
+ V4L2_MPEG_VIDEO_MPEG4_LEVEL_4 = 6,
+ V4L2_MPEG_VIDEO_MPEG4_LEVEL_5 = 7,
+};
+#define V4L2_CID_MPEG_VIDEO_MPEG4_PROFILE (V4L2_CID_MPEG_BASE+406)
+enum v4l2_mpeg_video_mpeg4_profile {
+ V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE = 0,
+ V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_SIMPLE = 1,
+ V4L2_MPEG_VIDEO_MPEG4_PROFILE_CORE = 2,
+ V4L2_MPEG_VIDEO_MPEG4_PROFILE_SIMPLE_SCALABLE = 3,
+ V4L2_MPEG_VIDEO_MPEG4_PROFILE_ADVANCED_CODING_EFFICIENCY = 4,
+};
+#define V4L2_CID_MPEG_VIDEO_MPEG4_QPEL (V4L2_CID_MPEG_BASE+407)
+
+/* Control IDs for VP8 streams
+ * Although VP8 is not part of MPEG we add these controls to the MPEG class
+ * as that class is already handling other video compression standards
+ */
+#define V4L2_CID_MPEG_VIDEO_VPX_NUM_PARTITIONS (V4L2_CID_MPEG_BASE+500)
+enum v4l2_vp8_num_partitions {
+ V4L2_CID_MPEG_VIDEO_VPX_1_PARTITION = 0,
+ V4L2_CID_MPEG_VIDEO_VPX_2_PARTITIONS = 1,
+ V4L2_CID_MPEG_VIDEO_VPX_4_PARTITIONS = 2,
+ V4L2_CID_MPEG_VIDEO_VPX_8_PARTITIONS = 3,
+};
+#define V4L2_CID_MPEG_VIDEO_VPX_IMD_DISABLE_4X4 (V4L2_CID_MPEG_BASE+501)
+#define V4L2_CID_MPEG_VIDEO_VPX_NUM_REF_FRAMES (V4L2_CID_MPEG_BASE+502)
+enum v4l2_vp8_num_ref_frames {
+ V4L2_CID_MPEG_VIDEO_VPX_1_REF_FRAME = 0,
+ V4L2_CID_MPEG_VIDEO_VPX_2_REF_FRAME = 1,
+ V4L2_CID_MPEG_VIDEO_VPX_3_REF_FRAME = 2,
+};
+#define V4L2_CID_MPEG_VIDEO_VPX_FILTER_LEVEL (V4L2_CID_MPEG_BASE+503)
+#define V4L2_CID_MPEG_VIDEO_VPX_FILTER_SHARPNESS (V4L2_CID_MPEG_BASE+504)
+#define V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_REF_PERIOD (V4L2_CID_MPEG_BASE+505)
+#define V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_SEL (V4L2_CID_MPEG_BASE+506)
+enum v4l2_vp8_golden_frame_sel {
+ V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_USE_PREV = 0,
+ V4L2_CID_MPEG_VIDEO_VPX_GOLDEN_FRAME_USE_REF_PERIOD = 1,
+};
+#define V4L2_CID_MPEG_VIDEO_VPX_MIN_QP (V4L2_CID_MPEG_BASE+507)
+#define V4L2_CID_MPEG_VIDEO_VPX_MAX_QP (V4L2_CID_MPEG_BASE+508)
+#define V4L2_CID_MPEG_VIDEO_VPX_I_FRAME_QP (V4L2_CID_MPEG_BASE+509)
+#define V4L2_CID_MPEG_VIDEO_VPX_P_FRAME_QP (V4L2_CID_MPEG_BASE+510)
+#define V4L2_CID_MPEG_VIDEO_VPX_PROFILE (V4L2_CID_MPEG_BASE+511)
+
+/* MPEG-class control IDs specific to the CX2341x driver as defined by V4L2 */
+#define V4L2_CID_MPEG_CX2341X_BASE (V4L2_CTRL_CLASS_MPEG | 0x1000)
+#define V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE (V4L2_CID_MPEG_CX2341X_BASE+0)
+enum v4l2_mpeg_cx2341x_video_spatial_filter_mode {
+ V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL = 0,
+ V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO = 1,
+};
+#define V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER (V4L2_CID_MPEG_CX2341X_BASE+1)
+#define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE (V4L2_CID_MPEG_CX2341X_BASE+2)
+enum v4l2_mpeg_cx2341x_video_luma_spatial_filter_type {
+ V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_OFF = 0,
+ V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_HOR = 1,
+ V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_VERT = 2,
+ V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_HV_SEPARABLE = 3,
+ V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_SYM_NON_SEPARABLE = 4,
+};
+#define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE (V4L2_CID_MPEG_CX2341X_BASE+3)
+enum v4l2_mpeg_cx2341x_video_chroma_spatial_filter_type {
+ V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_OFF = 0,
+ V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_1D_HOR = 1,
+};
+#define V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE (V4L2_CID_MPEG_CX2341X_BASE+4)
+enum v4l2_mpeg_cx2341x_video_temporal_filter_mode {
+ V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL = 0,
+ V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_AUTO = 1,
+};
+#define V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER (V4L2_CID_MPEG_CX2341X_BASE+5)
+#define V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE (V4L2_CID_MPEG_CX2341X_BASE+6)
+enum v4l2_mpeg_cx2341x_video_median_filter_type {
+ V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF = 0,
+ V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_HOR = 1,
+ V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_VERT = 2,
+ V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_HOR_VERT = 3,
+ V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_DIAG = 4,
+};
+#define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM (V4L2_CID_MPEG_CX2341X_BASE+7)
+#define V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP (V4L2_CID_MPEG_CX2341X_BASE+8)
+#define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM (V4L2_CID_MPEG_CX2341X_BASE+9)
+#define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP (V4L2_CID_MPEG_CX2341X_BASE+10)
+#define V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS (V4L2_CID_MPEG_CX2341X_BASE+11)
+
+/* MPEG-class control IDs specific to the Samsung MFC 5.1 driver as defined by V4L2 */
+#define V4L2_CID_MPEG_MFC51_BASE (V4L2_CTRL_CLASS_MPEG | 0x1100)
+
+#define V4L2_CID_MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY (V4L2_CID_MPEG_MFC51_BASE+0)
+#define V4L2_CID_MPEG_MFC51_VIDEO_DECODER_H264_DISPLAY_DELAY_ENABLE (V4L2_CID_MPEG_MFC51_BASE+1)
+#define V4L2_CID_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE (V4L2_CID_MPEG_MFC51_BASE+2)
+enum v4l2_mpeg_mfc51_video_frame_skip_mode {
+ V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_DISABLED = 0,
+ V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_LEVEL_LIMIT = 1,
+ V4L2_MPEG_MFC51_VIDEO_FRAME_SKIP_MODE_BUF_LIMIT = 2,
+};
+#define V4L2_CID_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE (V4L2_CID_MPEG_MFC51_BASE+3)
+enum v4l2_mpeg_mfc51_video_force_frame_type {
+ V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_DISABLED = 0,
+ V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_I_FRAME = 1,
+ V4L2_MPEG_MFC51_VIDEO_FORCE_FRAME_TYPE_NOT_CODED = 2,
+};
+#define V4L2_CID_MPEG_MFC51_VIDEO_PADDING (V4L2_CID_MPEG_MFC51_BASE+4)
+#define V4L2_CID_MPEG_MFC51_VIDEO_PADDING_YUV (V4L2_CID_MPEG_MFC51_BASE+5)
+#define V4L2_CID_MPEG_MFC51_VIDEO_RC_FIXED_TARGET_BIT (V4L2_CID_MPEG_MFC51_BASE+6)
+#define V4L2_CID_MPEG_MFC51_VIDEO_RC_REACTION_COEFF (V4L2_CID_MPEG_MFC51_BASE+7)
+#define V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_ACTIVITY (V4L2_CID_MPEG_MFC51_BASE+50)
+#define V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_DARK (V4L2_CID_MPEG_MFC51_BASE+51)
+#define V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_SMOOTH (V4L2_CID_MPEG_MFC51_BASE+52)
+#define V4L2_CID_MPEG_MFC51_VIDEO_H264_ADAPTIVE_RC_STATIC (V4L2_CID_MPEG_MFC51_BASE+53)
+#define V4L2_CID_MPEG_MFC51_VIDEO_H264_NUM_REF_PIC_FOR_P (V4L2_CID_MPEG_MFC51_BASE+54)
+
+
+/* Camera class control IDs */
+
+#define V4L2_CID_CAMERA_CLASS_BASE (V4L2_CTRL_CLASS_CAMERA | 0x900)
+#define V4L2_CID_CAMERA_CLASS (V4L2_CTRL_CLASS_CAMERA | 1)
+
+#define V4L2_CID_EXPOSURE_AUTO (V4L2_CID_CAMERA_CLASS_BASE+1)
+enum v4l2_exposure_auto_type {
+ V4L2_EXPOSURE_AUTO = 0,
+ V4L2_EXPOSURE_MANUAL = 1,
+ V4L2_EXPOSURE_SHUTTER_PRIORITY = 2,
+ V4L2_EXPOSURE_APERTURE_PRIORITY = 3
+};
+#define V4L2_CID_EXPOSURE_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+2)
+#define V4L2_CID_EXPOSURE_AUTO_PRIORITY (V4L2_CID_CAMERA_CLASS_BASE+3)
+
+#define V4L2_CID_PAN_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+4)
+#define V4L2_CID_TILT_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+5)
+#define V4L2_CID_PAN_RESET (V4L2_CID_CAMERA_CLASS_BASE+6)
+#define V4L2_CID_TILT_RESET (V4L2_CID_CAMERA_CLASS_BASE+7)
+
+#define V4L2_CID_PAN_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+8)
+#define V4L2_CID_TILT_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+9)
+
+#define V4L2_CID_FOCUS_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+10)
+#define V4L2_CID_FOCUS_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+11)
+#define V4L2_CID_FOCUS_AUTO (V4L2_CID_CAMERA_CLASS_BASE+12)
+
+#define V4L2_CID_ZOOM_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+13)
+#define V4L2_CID_ZOOM_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+14)
+#define V4L2_CID_ZOOM_CONTINUOUS (V4L2_CID_CAMERA_CLASS_BASE+15)
+
+#define V4L2_CID_PRIVACY (V4L2_CID_CAMERA_CLASS_BASE+16)
+
+#define V4L2_CID_IRIS_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+17)
+#define V4L2_CID_IRIS_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+18)
+
+#define V4L2_CID_AUTO_EXPOSURE_BIAS (V4L2_CID_CAMERA_CLASS_BASE+19)
+
+#define V4L2_CID_AUTO_N_PRESET_WHITE_BALANCE (V4L2_CID_CAMERA_CLASS_BASE+20)
+enum v4l2_auto_n_preset_white_balance {
+ V4L2_WHITE_BALANCE_MANUAL = 0,
+ V4L2_WHITE_BALANCE_AUTO = 1,
+ V4L2_WHITE_BALANCE_INCANDESCENT = 2,
+ V4L2_WHITE_BALANCE_FLUORESCENT = 3,
+ V4L2_WHITE_BALANCE_FLUORESCENT_H = 4,
+ V4L2_WHITE_BALANCE_HORIZON = 5,
+ V4L2_WHITE_BALANCE_DAYLIGHT = 6,
+ V4L2_WHITE_BALANCE_FLASH = 7,
+ V4L2_WHITE_BALANCE_CLOUDY = 8,
+ V4L2_WHITE_BALANCE_SHADE = 9,
+};
+
+#define V4L2_CID_WIDE_DYNAMIC_RANGE (V4L2_CID_CAMERA_CLASS_BASE+21)
+#define V4L2_CID_IMAGE_STABILIZATION (V4L2_CID_CAMERA_CLASS_BASE+22)
+
+#define V4L2_CID_ISO_SENSITIVITY (V4L2_CID_CAMERA_CLASS_BASE+23)
+#define V4L2_CID_ISO_SENSITIVITY_AUTO (V4L2_CID_CAMERA_CLASS_BASE+24)
+enum v4l2_iso_sensitivity_auto_type {
+ V4L2_ISO_SENSITIVITY_MANUAL = 0,
+ V4L2_ISO_SENSITIVITY_AUTO = 1,
+};
+
+#define V4L2_CID_EXPOSURE_METERING (V4L2_CID_CAMERA_CLASS_BASE+25)
+enum v4l2_exposure_metering {
+ V4L2_EXPOSURE_METERING_AVERAGE = 0,
+ V4L2_EXPOSURE_METERING_CENTER_WEIGHTED = 1,
+ V4L2_EXPOSURE_METERING_SPOT = 2,
+ V4L2_EXPOSURE_METERING_MATRIX = 3,
+};
+
+#define V4L2_CID_SCENE_MODE (V4L2_CID_CAMERA_CLASS_BASE+26)
+enum v4l2_scene_mode {
+ V4L2_SCENE_MODE_NONE = 0,
+ V4L2_SCENE_MODE_BACKLIGHT = 1,
+ V4L2_SCENE_MODE_BEACH_SNOW = 2,
+ V4L2_SCENE_MODE_CANDLE_LIGHT = 3,
+ V4L2_SCENE_MODE_DAWN_DUSK = 4,
+ V4L2_SCENE_MODE_FALL_COLORS = 5,
+ V4L2_SCENE_MODE_FIREWORKS = 6,
+ V4L2_SCENE_MODE_LANDSCAPE = 7,
+ V4L2_SCENE_MODE_NIGHT = 8,
+ V4L2_SCENE_MODE_PARTY_INDOOR = 9,
+ V4L2_SCENE_MODE_PORTRAIT = 10,
+ V4L2_SCENE_MODE_SPORTS = 11,
+ V4L2_SCENE_MODE_SUNSET = 12,
+ V4L2_SCENE_MODE_TEXT = 13,
+};
+
+#define V4L2_CID_3A_LOCK (V4L2_CID_CAMERA_CLASS_BASE+27)
+#define V4L2_LOCK_EXPOSURE (1 << 0)
+#define V4L2_LOCK_WHITE_BALANCE (1 << 1)
+#define V4L2_LOCK_FOCUS (1 << 2)
+
+#define V4L2_CID_AUTO_FOCUS_START (V4L2_CID_CAMERA_CLASS_BASE+28)
+#define V4L2_CID_AUTO_FOCUS_STOP (V4L2_CID_CAMERA_CLASS_BASE+29)
+#define V4L2_CID_AUTO_FOCUS_STATUS (V4L2_CID_CAMERA_CLASS_BASE+30)
+#define V4L2_AUTO_FOCUS_STATUS_IDLE (0 << 0)
+#define V4L2_AUTO_FOCUS_STATUS_BUSY (1 << 0)
+#define V4L2_AUTO_FOCUS_STATUS_REACHED (1 << 1)
+#define V4L2_AUTO_FOCUS_STATUS_FAILED (1 << 2)
+
+#define V4L2_CID_AUTO_FOCUS_RANGE (V4L2_CID_CAMERA_CLASS_BASE+31)
+enum v4l2_auto_focus_range {
+ V4L2_AUTO_FOCUS_RANGE_AUTO = 0,
+ V4L2_AUTO_FOCUS_RANGE_NORMAL = 1,
+ V4L2_AUTO_FOCUS_RANGE_MACRO = 2,
+ V4L2_AUTO_FOCUS_RANGE_INFINITY = 3,
+};
+
+#define V4L2_CID_PAN_SPEED (V4L2_CID_CAMERA_CLASS_BASE+32)
+#define V4L2_CID_TILT_SPEED (V4L2_CID_CAMERA_CLASS_BASE+33)
+
+/* FM Modulator class control IDs */
+
+#define V4L2_CID_FM_TX_CLASS_BASE (V4L2_CTRL_CLASS_FM_TX | 0x900)
+#define V4L2_CID_FM_TX_CLASS (V4L2_CTRL_CLASS_FM_TX | 1)
+
+#define V4L2_CID_RDS_TX_DEVIATION (V4L2_CID_FM_TX_CLASS_BASE + 1)
+#define V4L2_CID_RDS_TX_PI (V4L2_CID_FM_TX_CLASS_BASE + 2)
+#define V4L2_CID_RDS_TX_PTY (V4L2_CID_FM_TX_CLASS_BASE + 3)
+#define V4L2_CID_RDS_TX_PS_NAME (V4L2_CID_FM_TX_CLASS_BASE + 5)
+#define V4L2_CID_RDS_TX_RADIO_TEXT (V4L2_CID_FM_TX_CLASS_BASE + 6)
+#define V4L2_CID_RDS_TX_MONO_STEREO (V4L2_CID_FM_TX_CLASS_BASE + 7)
+#define V4L2_CID_RDS_TX_ARTIFICIAL_HEAD (V4L2_CID_FM_TX_CLASS_BASE + 8)
+#define V4L2_CID_RDS_TX_COMPRESSED (V4L2_CID_FM_TX_CLASS_BASE + 9)
+#define V4L2_CID_RDS_TX_DYNAMIC_PTY (V4L2_CID_FM_TX_CLASS_BASE + 10)
+#define V4L2_CID_RDS_TX_TRAFFIC_ANNOUNCEMENT (V4L2_CID_FM_TX_CLASS_BASE + 11)
+#define V4L2_CID_RDS_TX_TRAFFIC_PROGRAM (V4L2_CID_FM_TX_CLASS_BASE + 12)
+#define V4L2_CID_RDS_TX_MUSIC_SPEECH (V4L2_CID_FM_TX_CLASS_BASE + 13)
+#define V4L2_CID_RDS_TX_ALT_FREQS_ENABLE (V4L2_CID_FM_TX_CLASS_BASE + 14)
+#define V4L2_CID_RDS_TX_ALT_FREQS (V4L2_CID_FM_TX_CLASS_BASE + 15)
+
+#define V4L2_CID_AUDIO_LIMITER_ENABLED (V4L2_CID_FM_TX_CLASS_BASE + 64)
+#define V4L2_CID_AUDIO_LIMITER_RELEASE_TIME (V4L2_CID_FM_TX_CLASS_BASE + 65)
+#define V4L2_CID_AUDIO_LIMITER_DEVIATION (V4L2_CID_FM_TX_CLASS_BASE + 66)
+
+#define V4L2_CID_AUDIO_COMPRESSION_ENABLED (V4L2_CID_FM_TX_CLASS_BASE + 80)
+#define V4L2_CID_AUDIO_COMPRESSION_GAIN (V4L2_CID_FM_TX_CLASS_BASE + 81)
+#define V4L2_CID_AUDIO_COMPRESSION_THRESHOLD (V4L2_CID_FM_TX_CLASS_BASE + 82)
+#define V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME (V4L2_CID_FM_TX_CLASS_BASE + 83)
+#define V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME (V4L2_CID_FM_TX_CLASS_BASE + 84)
+
+#define V4L2_CID_PILOT_TONE_ENABLED (V4L2_CID_FM_TX_CLASS_BASE + 96)
+#define V4L2_CID_PILOT_TONE_DEVIATION (V4L2_CID_FM_TX_CLASS_BASE + 97)
+#define V4L2_CID_PILOT_TONE_FREQUENCY (V4L2_CID_FM_TX_CLASS_BASE + 98)
+
+#define V4L2_CID_TUNE_PREEMPHASIS (V4L2_CID_FM_TX_CLASS_BASE + 112)
+enum v4l2_preemphasis {
+ V4L2_PREEMPHASIS_DISABLED = 0,
+ V4L2_PREEMPHASIS_50_uS = 1,
+ V4L2_PREEMPHASIS_75_uS = 2,
+};
+#define V4L2_CID_TUNE_POWER_LEVEL (V4L2_CID_FM_TX_CLASS_BASE + 113)
+#define V4L2_CID_TUNE_ANTENNA_CAPACITOR (V4L2_CID_FM_TX_CLASS_BASE + 114)
+
+
+/* Flash and privacy (indicator) light controls */
+
+#define V4L2_CID_FLASH_CLASS_BASE (V4L2_CTRL_CLASS_FLASH | 0x900)
+#define V4L2_CID_FLASH_CLASS (V4L2_CTRL_CLASS_FLASH | 1)
+
+#define V4L2_CID_FLASH_LED_MODE (V4L2_CID_FLASH_CLASS_BASE + 1)
+enum v4l2_flash_led_mode {
+ V4L2_FLASH_LED_MODE_NONE,
+ V4L2_FLASH_LED_MODE_FLASH,
+ V4L2_FLASH_LED_MODE_TORCH,
+};
+
+#define V4L2_CID_FLASH_STROBE_SOURCE (V4L2_CID_FLASH_CLASS_BASE + 2)
+enum v4l2_flash_strobe_source {
+ V4L2_FLASH_STROBE_SOURCE_SOFTWARE,
+ V4L2_FLASH_STROBE_SOURCE_EXTERNAL,
+};
+
+#define V4L2_CID_FLASH_STROBE (V4L2_CID_FLASH_CLASS_BASE + 3)
+#define V4L2_CID_FLASH_STROBE_STOP (V4L2_CID_FLASH_CLASS_BASE + 4)
+#define V4L2_CID_FLASH_STROBE_STATUS (V4L2_CID_FLASH_CLASS_BASE + 5)
+
+#define V4L2_CID_FLASH_TIMEOUT (V4L2_CID_FLASH_CLASS_BASE + 6)
+#define V4L2_CID_FLASH_INTENSITY (V4L2_CID_FLASH_CLASS_BASE + 7)
+#define V4L2_CID_FLASH_TORCH_INTENSITY (V4L2_CID_FLASH_CLASS_BASE + 8)
+#define V4L2_CID_FLASH_INDICATOR_INTENSITY (V4L2_CID_FLASH_CLASS_BASE + 9)
+
+#define V4L2_CID_FLASH_FAULT (V4L2_CID_FLASH_CLASS_BASE + 10)
+#define V4L2_FLASH_FAULT_OVER_VOLTAGE (1 << 0)
+#define V4L2_FLASH_FAULT_TIMEOUT (1 << 1)
+#define V4L2_FLASH_FAULT_OVER_TEMPERATURE (1 << 2)
+#define V4L2_FLASH_FAULT_SHORT_CIRCUIT (1 << 3)
+#define V4L2_FLASH_FAULT_OVER_CURRENT (1 << 4)
+#define V4L2_FLASH_FAULT_INDICATOR (1 << 5)
+#define V4L2_FLASH_FAULT_UNDER_VOLTAGE (1 << 6)
+#define V4L2_FLASH_FAULT_INPUT_VOLTAGE (1 << 7)
+#define V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE (1 << 8)
+
+#define V4L2_CID_FLASH_CHARGE (V4L2_CID_FLASH_CLASS_BASE + 11)
+#define V4L2_CID_FLASH_READY (V4L2_CID_FLASH_CLASS_BASE + 12)
+
+
+/* JPEG-class control IDs */
+
+#define V4L2_CID_JPEG_CLASS_BASE (V4L2_CTRL_CLASS_JPEG | 0x900)
+#define V4L2_CID_JPEG_CLASS (V4L2_CTRL_CLASS_JPEG | 1)
+
+#define V4L2_CID_JPEG_CHROMA_SUBSAMPLING (V4L2_CID_JPEG_CLASS_BASE + 1)
+enum v4l2_jpeg_chroma_subsampling {
+ V4L2_JPEG_CHROMA_SUBSAMPLING_444 = 0,
+ V4L2_JPEG_CHROMA_SUBSAMPLING_422 = 1,
+ V4L2_JPEG_CHROMA_SUBSAMPLING_420 = 2,
+ V4L2_JPEG_CHROMA_SUBSAMPLING_411 = 3,
+ V4L2_JPEG_CHROMA_SUBSAMPLING_410 = 4,
+ V4L2_JPEG_CHROMA_SUBSAMPLING_GRAY = 5,
+};
+#define V4L2_CID_JPEG_RESTART_INTERVAL (V4L2_CID_JPEG_CLASS_BASE + 2)
+#define V4L2_CID_JPEG_COMPRESSION_QUALITY (V4L2_CID_JPEG_CLASS_BASE + 3)
+
+#define V4L2_CID_JPEG_ACTIVE_MARKER (V4L2_CID_JPEG_CLASS_BASE + 4)
+#define V4L2_JPEG_ACTIVE_MARKER_APP0 (1 << 0)
+#define V4L2_JPEG_ACTIVE_MARKER_APP1 (1 << 1)
+#define V4L2_JPEG_ACTIVE_MARKER_COM (1 << 16)
+#define V4L2_JPEG_ACTIVE_MARKER_DQT (1 << 17)
+#define V4L2_JPEG_ACTIVE_MARKER_DHT (1 << 18)
+
+
+/* Image source controls */
+#define V4L2_CID_IMAGE_SOURCE_CLASS_BASE (V4L2_CTRL_CLASS_IMAGE_SOURCE | 0x900)
+#define V4L2_CID_IMAGE_SOURCE_CLASS (V4L2_CTRL_CLASS_IMAGE_SOURCE | 1)
+
+#define V4L2_CID_VBLANK (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 1)
+#define V4L2_CID_HBLANK (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 2)
+#define V4L2_CID_ANALOGUE_GAIN (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 3)
+#define V4L2_CID_TEST_PATTERN_RED (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 4)
+#define V4L2_CID_TEST_PATTERN_GREENR (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 5)
+#define V4L2_CID_TEST_PATTERN_BLUE (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 6)
+#define V4L2_CID_TEST_PATTERN_GREENB (V4L2_CID_IMAGE_SOURCE_CLASS_BASE + 7)
+
+
+/* Image processing controls */
+
+#define V4L2_CID_IMAGE_PROC_CLASS_BASE (V4L2_CTRL_CLASS_IMAGE_PROC | 0x900)
+#define V4L2_CID_IMAGE_PROC_CLASS (V4L2_CTRL_CLASS_IMAGE_PROC | 1)
+
+#define V4L2_CID_LINK_FREQ (V4L2_CID_IMAGE_PROC_CLASS_BASE + 1)
+#define V4L2_CID_PIXEL_RATE (V4L2_CID_IMAGE_PROC_CLASS_BASE + 2)
+#define V4L2_CID_TEST_PATTERN (V4L2_CID_IMAGE_PROC_CLASS_BASE + 3)
+#define V4L2_CID_DEINTERLACING_MODE (V4L2_CID_IMAGE_PROC_CLASS_BASE + 4)
+
+
+/* DV-class control IDs defined by V4L2 */
+#define V4L2_CID_DV_CLASS_BASE (V4L2_CTRL_CLASS_DV | 0x900)
+#define V4L2_CID_DV_CLASS (V4L2_CTRL_CLASS_DV | 1)
+
+#define V4L2_CID_DV_TX_HOTPLUG (V4L2_CID_DV_CLASS_BASE + 1)
+#define V4L2_CID_DV_TX_RXSENSE (V4L2_CID_DV_CLASS_BASE + 2)
+#define V4L2_CID_DV_TX_EDID_PRESENT (V4L2_CID_DV_CLASS_BASE + 3)
+#define V4L2_CID_DV_TX_MODE (V4L2_CID_DV_CLASS_BASE + 4)
+enum v4l2_dv_tx_mode {
+ V4L2_DV_TX_MODE_DVI_D = 0,
+ V4L2_DV_TX_MODE_HDMI = 1,
+};
+#define V4L2_CID_DV_TX_RGB_RANGE (V4L2_CID_DV_CLASS_BASE + 5)
+enum v4l2_dv_rgb_range {
+ V4L2_DV_RGB_RANGE_AUTO = 0,
+ V4L2_DV_RGB_RANGE_LIMITED = 1,
+ V4L2_DV_RGB_RANGE_FULL = 2,
+};
+
+#define V4L2_CID_DV_TX_IT_CONTENT_TYPE (V4L2_CID_DV_CLASS_BASE + 6)
+enum v4l2_dv_it_content_type {
+ V4L2_DV_IT_CONTENT_TYPE_GRAPHICS = 0,
+ V4L2_DV_IT_CONTENT_TYPE_PHOTO = 1,
+ V4L2_DV_IT_CONTENT_TYPE_CINEMA = 2,
+ V4L2_DV_IT_CONTENT_TYPE_GAME = 3,
+ V4L2_DV_IT_CONTENT_TYPE_NO_ITC = 4,
+};
+
+#define V4L2_CID_DV_RX_POWER_PRESENT (V4L2_CID_DV_CLASS_BASE + 100)
+#define V4L2_CID_DV_RX_RGB_RANGE (V4L2_CID_DV_CLASS_BASE + 101)
+#define V4L2_CID_DV_RX_IT_CONTENT_TYPE (V4L2_CID_DV_CLASS_BASE + 102)
+
+#define V4L2_CID_FM_RX_CLASS_BASE (V4L2_CTRL_CLASS_FM_RX | 0x900)
+#define V4L2_CID_FM_RX_CLASS (V4L2_CTRL_CLASS_FM_RX | 1)
+
+#define V4L2_CID_TUNE_DEEMPHASIS (V4L2_CID_FM_RX_CLASS_BASE + 1)
+enum v4l2_deemphasis {
+ V4L2_DEEMPHASIS_DISABLED = V4L2_PREEMPHASIS_DISABLED,
+ V4L2_DEEMPHASIS_50_uS = V4L2_PREEMPHASIS_50_uS,
+ V4L2_DEEMPHASIS_75_uS = V4L2_PREEMPHASIS_75_uS,
+};
+
+#define V4L2_CID_RDS_RECEPTION (V4L2_CID_FM_RX_CLASS_BASE + 2)
+#define V4L2_CID_RDS_RX_PTY (V4L2_CID_FM_RX_CLASS_BASE + 3)
+#define V4L2_CID_RDS_RX_PS_NAME (V4L2_CID_FM_RX_CLASS_BASE + 4)
+#define V4L2_CID_RDS_RX_RADIO_TEXT (V4L2_CID_FM_RX_CLASS_BASE + 5)
+#define V4L2_CID_RDS_RX_TRAFFIC_ANNOUNCEMENT (V4L2_CID_FM_RX_CLASS_BASE + 6)
+#define V4L2_CID_RDS_RX_TRAFFIC_PROGRAM (V4L2_CID_FM_RX_CLASS_BASE + 7)
+#define V4L2_CID_RDS_RX_MUSIC_SPEECH (V4L2_CID_FM_RX_CLASS_BASE + 8)
+
+#define V4L2_CID_RF_TUNER_CLASS_BASE (V4L2_CTRL_CLASS_RF_TUNER | 0x900)
+#define V4L2_CID_RF_TUNER_CLASS (V4L2_CTRL_CLASS_RF_TUNER | 1)
+
+#define V4L2_CID_RF_TUNER_BANDWIDTH_AUTO (V4L2_CID_RF_TUNER_CLASS_BASE + 11)
+#define V4L2_CID_RF_TUNER_BANDWIDTH (V4L2_CID_RF_TUNER_CLASS_BASE + 12)
+#define V4L2_CID_RF_TUNER_RF_GAIN (V4L2_CID_RF_TUNER_CLASS_BASE + 32)
+#define V4L2_CID_RF_TUNER_LNA_GAIN_AUTO (V4L2_CID_RF_TUNER_CLASS_BASE + 41)
+#define V4L2_CID_RF_TUNER_LNA_GAIN (V4L2_CID_RF_TUNER_CLASS_BASE + 42)
+#define V4L2_CID_RF_TUNER_MIXER_GAIN_AUTO (V4L2_CID_RF_TUNER_CLASS_BASE + 51)
+#define V4L2_CID_RF_TUNER_MIXER_GAIN (V4L2_CID_RF_TUNER_CLASS_BASE + 52)
+#define V4L2_CID_RF_TUNER_IF_GAIN_AUTO (V4L2_CID_RF_TUNER_CLASS_BASE + 61)
+#define V4L2_CID_RF_TUNER_IF_GAIN (V4L2_CID_RF_TUNER_CLASS_BASE + 62)
+#define V4L2_CID_RF_TUNER_PLL_LOCK (V4L2_CID_RF_TUNER_CLASS_BASE + 91)
+
+
+/* Detection-class control IDs defined by V4L2 */
+#define V4L2_CID_DETECT_CLASS_BASE (V4L2_CTRL_CLASS_DETECT | 0x900)
+#define V4L2_CID_DETECT_CLASS (V4L2_CTRL_CLASS_DETECT | 1)
+
+#define V4L2_CID_DETECT_MD_MODE (V4L2_CID_DETECT_CLASS_BASE + 1)
+enum v4l2_detect_md_mode {
+ V4L2_DETECT_MD_MODE_DISABLED = 0,
+ V4L2_DETECT_MD_MODE_GLOBAL = 1,
+ V4L2_DETECT_MD_MODE_THRESHOLD_GRID = 2,
+ V4L2_DETECT_MD_MODE_REGION_GRID = 3,
+};
+#define V4L2_CID_DETECT_MD_GLOBAL_THRESHOLD (V4L2_CID_DETECT_CLASS_BASE + 2)
+#define V4L2_CID_DETECT_MD_THRESHOLD_GRID (V4L2_CID_DETECT_CLASS_BASE + 3)
+#define V4L2_CID_DETECT_MD_REGION_GRID (V4L2_CID_DETECT_CLASS_BASE + 4)
+/*
+ * End of v4l2-controls.h
+ */
+
+#ifndef __user
+#define __user
+#endif
+
+/*
+ * Common stuff for both V4L1 and V4L2
+ * Moved from videodev.h
+ */
+#define VIDEO_MAX_FRAME 32
+#define VIDEO_MAX_PLANES 8
+
+/*
+ * M I S C E L L A N E O U S
+ */
+
+/* Four-character-code (FOURCC) */
+#define v4l2_fourcc(a, b, c, d)\
+ ((u_int32_t)(a) | ((u_int32_t)(b) << 8) | ((u_int32_t)(c) << 16) | ((u_int32_t)(d) << 24))
+#define v4l2_fourcc_be(a, b, c, d) (v4l2_fourcc(a, b, c, d) | (1 << 31))
+
+/*
+ * E N U M S
+ */
+enum v4l2_field {
+ V4L2_FIELD_ANY = 0, /* driver can choose from none,
+ top, bottom, interlaced
+ depending on whatever it thinks
+ is approximate ... */
+ V4L2_FIELD_NONE = 1, /* this device has no fields ... */
+ V4L2_FIELD_TOP = 2, /* top field only */
+ V4L2_FIELD_BOTTOM = 3, /* bottom field only */
+ V4L2_FIELD_INTERLACED = 4, /* both fields interlaced */
+ V4L2_FIELD_SEQ_TB = 5, /* both fields sequential into one
+ buffer, top-bottom order */
+ V4L2_FIELD_SEQ_BT = 6, /* same as above + bottom-top order */
+ V4L2_FIELD_ALTERNATE = 7, /* both fields alternating into
+ separate buffers */
+ V4L2_FIELD_INTERLACED_TB = 8, /* both fields interlaced, top field
+ first and the top field is
+ transmitted first */
+ V4L2_FIELD_INTERLACED_BT = 9, /* both fields interlaced, top field
+ first and the bottom field is
+ transmitted first */
+};
+#define V4L2_FIELD_HAS_TOP(field) \
+ ((field) == V4L2_FIELD_TOP ||\
+ (field) == V4L2_FIELD_INTERLACED ||\
+ (field) == V4L2_FIELD_INTERLACED_TB ||\
+ (field) == V4L2_FIELD_INTERLACED_BT ||\
+ (field) == V4L2_FIELD_SEQ_TB ||\
+ (field) == V4L2_FIELD_SEQ_BT)
+#define V4L2_FIELD_HAS_BOTTOM(field) \
+ ((field) == V4L2_FIELD_BOTTOM ||\
+ (field) == V4L2_FIELD_INTERLACED ||\
+ (field) == V4L2_FIELD_INTERLACED_TB ||\
+ (field) == V4L2_FIELD_INTERLACED_BT ||\
+ (field) == V4L2_FIELD_SEQ_TB ||\
+ (field) == V4L2_FIELD_SEQ_BT)
+#define V4L2_FIELD_HAS_BOTH(field) \
+ ((field) == V4L2_FIELD_INTERLACED ||\
+ (field) == V4L2_FIELD_INTERLACED_TB ||\
+ (field) == V4L2_FIELD_INTERLACED_BT ||\
+ (field) == V4L2_FIELD_SEQ_TB ||\
+ (field) == V4L2_FIELD_SEQ_BT)
+#define V4L2_FIELD_HAS_T_OR_B(field) \
+ ((field) == V4L2_FIELD_BOTTOM ||\
+ (field) == V4L2_FIELD_TOP ||\
+ (field) == V4L2_FIELD_ALTERNATE)
+
+enum v4l2_buf_type {
+ V4L2_BUF_TYPE_VIDEO_CAPTURE = 1,
+ V4L2_BUF_TYPE_VIDEO_OUTPUT = 2,
+ V4L2_BUF_TYPE_VIDEO_OVERLAY = 3,
+ V4L2_BUF_TYPE_VBI_CAPTURE = 4,
+ V4L2_BUF_TYPE_VBI_OUTPUT = 5,
+ V4L2_BUF_TYPE_SLICED_VBI_CAPTURE = 6,
+ V4L2_BUF_TYPE_SLICED_VBI_OUTPUT = 7,
+ V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY = 8,
+ V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE = 9,
+ V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE = 10,
+ V4L2_BUF_TYPE_SDR_CAPTURE = 11,
+ V4L2_BUF_TYPE_SDR_OUTPUT = 12,
+ /* Deprecated, do not use */
+ V4L2_BUF_TYPE_PRIVATE = 0x80,
+};
+
+#define V4L2_TYPE_IS_MULTIPLANAR(type) \
+ ((type) == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE \
+ || (type) == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE)
+
+#define V4L2_TYPE_IS_OUTPUT(type) \
+ ((type) == V4L2_BUF_TYPE_VIDEO_OUTPUT \
+ || (type) == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE \
+ || (type) == V4L2_BUF_TYPE_VIDEO_OVERLAY \
+ || (type) == V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY \
+ || (type) == V4L2_BUF_TYPE_VBI_OUTPUT \
+ || (type) == V4L2_BUF_TYPE_SLICED_VBI_OUTPUT \
+ || (type) == V4L2_BUF_TYPE_SDR_OUTPUT)
+
+enum v4l2_tuner_type {
+ V4L2_TUNER_RADIO = 1,
+ V4L2_TUNER_ANALOG_TV = 2,
+ V4L2_TUNER_DIGITAL_TV = 3,
+ V4L2_TUNER_SDR = 4,
+ V4L2_TUNER_RF = 5,
+};
+
+/* Deprecated, do not use */
+#define V4L2_TUNER_ADC V4L2_TUNER_SDR
+
+enum v4l2_memory {
+ V4L2_MEMORY_MMAP = 1,
+ V4L2_MEMORY_USERPTR = 2,
+ V4L2_MEMORY_OVERLAY = 3,
+ V4L2_MEMORY_DMABUF = 4,
+};
+
+/* see also http://vektor.theorem.ca/graphics/ycbcr/ */
+enum v4l2_colorspace {
+ /*
+ * Default colorspace, i.e. let the driver figure it out.
+ * Can only be used with video capture.
+ */
+ V4L2_COLORSPACE_DEFAULT = 0,
+
+ /* SMPTE 170M: used for broadcast NTSC/PAL SDTV */
+ V4L2_COLORSPACE_SMPTE170M = 1,
+
+ /* Obsolete pre-1998 SMPTE 240M HDTV standard, superseded by Rec 709 */
+ V4L2_COLORSPACE_SMPTE240M = 2,
+
+ /* Rec.709: used for HDTV */
+ V4L2_COLORSPACE_REC709 = 3,
+
+ /*
+ * Deprecated, do not use. No driver will ever return this. This was
+ * based on a misunderstanding of the bt878 datasheet.
+ */
+ V4L2_COLORSPACE_BT878 = 4,
+
+ /*
+ * NTSC 1953 colorspace. This only makes sense when dealing with
+ * really, really old NTSC recordings. Superseded by SMPTE 170M.
+ */
+ V4L2_COLORSPACE_470_SYSTEM_M = 5,
+
+ /*
+ * EBU Tech 3213 PAL/SECAM colorspace. This only makes sense when
+ * dealing with really old PAL/SECAM recordings. Superseded by
+ * SMPTE 170M.
+ */
+ V4L2_COLORSPACE_470_SYSTEM_BG = 6,
+
+ /*
+ * Effectively shorthand for V4L2_COLORSPACE_SRGB, V4L2_YCBCR_ENC_601
+ * and V4L2_QUANTIZATION_FULL_RANGE. To be used for (Motion-)JPEG.
+ */
+ V4L2_COLORSPACE_JPEG = 7,
+
+ /* For RGB colorspaces such as produces by most webcams. */
+ V4L2_COLORSPACE_SRGB = 8,
+
+ /* AdobeRGB colorspace */
+ V4L2_COLORSPACE_ADOBERGB = 9,
+
+ /* BT.2020 colorspace, used for UHDTV. */
+ V4L2_COLORSPACE_BT2020 = 10,
+
+ /* Raw colorspace: for RAW unprocessed images */
+ V4L2_COLORSPACE_RAW = 11,
+
+ /* DCI-P3 colorspace, used by cinema projectors */
+ V4L2_COLORSPACE_DCI_P3 = 12,
+};
+
+/*
+ * Determine how COLORSPACE_DEFAULT should map to a proper colorspace.
+ * This depends on whether this is a SDTV image (use SMPTE 170M), an
+ * HDTV image (use Rec. 709), or something else (use sRGB).
+ */
+#define V4L2_MAP_COLORSPACE_DEFAULT(is_sdtv, is_hdtv) \
+ ((is_sdtv) ? V4L2_COLORSPACE_SMPTE170M : \
+ ((is_hdtv) ? V4L2_COLORSPACE_REC709 : V4L2_COLORSPACE_SRGB))
+
+enum v4l2_xfer_func {
+ /*
+ * Mapping of V4L2_XFER_FUNC_DEFAULT to actual transfer functions
+ * for the various colorspaces:
+ *
+ * V4L2_COLORSPACE_SMPTE170M, V4L2_COLORSPACE_470_SYSTEM_M,
+ * V4L2_COLORSPACE_470_SYSTEM_BG, V4L2_COLORSPACE_REC709 and
+ * V4L2_COLORSPACE_BT2020: V4L2_XFER_FUNC_709
+ *
+ * V4L2_COLORSPACE_SRGB, V4L2_COLORSPACE_JPEG: V4L2_XFER_FUNC_SRGB
+ *
+ * V4L2_COLORSPACE_ADOBERGB: V4L2_XFER_FUNC_ADOBERGB
+ *
+ * V4L2_COLORSPACE_SMPTE240M: V4L2_XFER_FUNC_SMPTE240M
+ *
+ * V4L2_COLORSPACE_RAW: V4L2_XFER_FUNC_NONE
+ *
+ * V4L2_COLORSPACE_DCI_P3: V4L2_XFER_FUNC_DCI_P3
+ */
+ V4L2_XFER_FUNC_DEFAULT = 0,
+ V4L2_XFER_FUNC_709 = 1,
+ V4L2_XFER_FUNC_SRGB = 2,
+ V4L2_XFER_FUNC_ADOBERGB = 3,
+ V4L2_XFER_FUNC_SMPTE240M = 4,
+ V4L2_XFER_FUNC_NONE = 5,
+ V4L2_XFER_FUNC_DCI_P3 = 6,
+ V4L2_XFER_FUNC_SMPTE2084 = 7,
+};
+
+/*
+ * Determine how XFER_FUNC_DEFAULT should map to a proper transfer function.
+ * This depends on the colorspace.
+ */
+#define V4L2_MAP_XFER_FUNC_DEFAULT(colsp) \
+ ((colsp) == V4L2_COLORSPACE_ADOBERGB ? V4L2_XFER_FUNC_ADOBERGB : \
+ ((colsp) == V4L2_COLORSPACE_SMPTE240M ? V4L2_XFER_FUNC_SMPTE240M : \
+ ((colsp) == V4L2_COLORSPACE_DCI_P3 ? V4L2_XFER_FUNC_DCI_P3 : \
+ ((colsp) == V4L2_COLORSPACE_RAW ? V4L2_XFER_FUNC_NONE : \
+ ((colsp) == V4L2_COLORSPACE_SRGB || (colsp) == V4L2_COLORSPACE_JPEG ? \
+ V4L2_XFER_FUNC_SRGB : V4L2_XFER_FUNC_709)))))
+
+enum v4l2_ycbcr_encoding {
+ /*
+ * Mapping of V4L2_YCBCR_ENC_DEFAULT to actual encodings for the
+ * various colorspaces:
+ *
+ * V4L2_COLORSPACE_SMPTE170M, V4L2_COLORSPACE_470_SYSTEM_M,
+ * V4L2_COLORSPACE_470_SYSTEM_BG, V4L2_COLORSPACE_SRGB,
+ * V4L2_COLORSPACE_ADOBERGB and V4L2_COLORSPACE_JPEG: V4L2_YCBCR_ENC_601
+ *
+ * V4L2_COLORSPACE_REC709 and V4L2_COLORSPACE_DCI_P3: V4L2_YCBCR_ENC_709
+ *
+ * V4L2_COLORSPACE_BT2020: V4L2_YCBCR_ENC_BT2020
+ *
+ * V4L2_COLORSPACE_SMPTE240M: V4L2_YCBCR_ENC_SMPTE240M
+ */
+ V4L2_YCBCR_ENC_DEFAULT = 0,
+
+ /* ITU-R 601 -- SDTV */
+ V4L2_YCBCR_ENC_601 = 1,
+
+ /* Rec. 709 -- HDTV */
+ V4L2_YCBCR_ENC_709 = 2,
+
+ /* ITU-R 601/EN 61966-2-4 Extended Gamut -- SDTV */
+ V4L2_YCBCR_ENC_XV601 = 3,
+
+ /* Rec. 709/EN 61966-2-4 Extended Gamut -- HDTV */
+ V4L2_YCBCR_ENC_XV709 = 4,
+
+#ifndef __KERNEL__
+ /*
+ * sYCC (Y'CbCr encoding of sRGB), identical to ENC_601. It was added
+ * originally due to a misunderstanding of the sYCC standard. It should
+ * not be used, instead use V4L2_YCBCR_ENC_601.
+ */
+ V4L2_YCBCR_ENC_SYCC = 5,
+#endif
+
+ /* BT.2020 Non-constant Luminance Y'CbCr */
+ V4L2_YCBCR_ENC_BT2020 = 6,
+
+ /* BT.2020 Constant Luminance Y'CbcCrc */
+ V4L2_YCBCR_ENC_BT2020_CONST_LUM = 7,
+
+ /* SMPTE 240M -- Obsolete HDTV */
+ V4L2_YCBCR_ENC_SMPTE240M = 8,
+};
+
+/*
+ * enum v4l2_hsv_encoding values should not collide with the ones from
+ * enum v4l2_ycbcr_encoding.
+ */
+enum v4l2_hsv_encoding {
+
+ /* Hue mapped to 0 - 179 */
+ V4L2_HSV_ENC_180 = 128,
+
+ /* Hue mapped to 0-255 */
+ V4L2_HSV_ENC_256 = 129,
+};
+
+/*
+ * Determine how YCBCR_ENC_DEFAULT should map to a proper Y'CbCr encoding.
+ * This depends on the colorspace.
+ */
+#define V4L2_MAP_YCBCR_ENC_DEFAULT(colsp) \
+ (((colsp) == V4L2_COLORSPACE_REC709 || \
+ (colsp) == V4L2_COLORSPACE_DCI_P3) ? V4L2_YCBCR_ENC_709 : \
+ ((colsp) == V4L2_COLORSPACE_BT2020 ? V4L2_YCBCR_ENC_BT2020 : \
+ ((colsp) == V4L2_COLORSPACE_SMPTE240M ? V4L2_YCBCR_ENC_SMPTE240M : \
+ V4L2_YCBCR_ENC_601)))
+
+enum v4l2_quantization {
+ /*
+ * The default for R'G'B' quantization is always full range, except
+ * for the BT2020 colorspace. For Y'CbCr the quantization is always
+ * limited range, except for COLORSPACE_JPEG, SRGB, ADOBERGB,
+ * XV601 or XV709: those are full range.
+ */
+ V4L2_QUANTIZATION_DEFAULT = 0,
+ V4L2_QUANTIZATION_FULL_RANGE = 1,
+ V4L2_QUANTIZATION_LIM_RANGE = 2,
+};
+
+/*
+ * Determine how QUANTIZATION_DEFAULT should map to a proper quantization.
+ * This depends on whether the image is RGB or not, the colorspace and the
+ * Y'CbCr encoding.
+ */
+#define V4L2_MAP_QUANTIZATION_DEFAULT(is_rgb_or_hsv, colsp, ycbcr_enc) \
+ (((is_rgb_or_hsv) && (colsp) == V4L2_COLORSPACE_BT2020) ? \
+ V4L2_QUANTIZATION_LIM_RANGE : \
+ (((is_rgb_or_hsv) || (ycbcr_enc) == V4L2_YCBCR_ENC_XV601 || \
+ (ycbcr_enc) == V4L2_YCBCR_ENC_XV709 || (colsp) == V4L2_COLORSPACE_JPEG) || \
+ (colsp) == V4L2_COLORSPACE_ADOBERGB || (colsp) == V4L2_COLORSPACE_SRGB ? \
+ V4L2_QUANTIZATION_FULL_RANGE : V4L2_QUANTIZATION_LIM_RANGE))
+
+enum v4l2_priority {
+ V4L2_PRIORITY_UNSET = 0, /* not initialized */
+ V4L2_PRIORITY_BACKGROUND = 1,
+ V4L2_PRIORITY_INTERACTIVE = 2,
+ V4L2_PRIORITY_RECORD = 3,
+ V4L2_PRIORITY_DEFAULT = V4L2_PRIORITY_INTERACTIVE,
+};
+
+struct v4l2_rect {
+ int32_t left;
+ int32_t top;
+ u_int32_t width;
+ u_int32_t height;
+};
+
+struct v4l2_fract {
+ u_int32_t numerator;
+ u_int32_t denominator;
+};
+
+/**
+ * struct v4l2_capability - Describes V4L2 device caps returned by VIDIOC_QUERYCAP
+ *
+ * @driver: name of the driver module (e.g. "bttv")
+ * @card: name of the card (e.g. "Hauppauge WinTV")
+ * @bus_info: name of the bus (e.g. "PCI:" + pci_name(pci_dev) )
+ * @version: KERNEL_VERSION
+ * @capabilities: capabilities of the physical device as a whole
+ * @device_caps: capabilities accessed via this particular device (node)
+ * @reserved: reserved fields for future extensions
+ */
+struct v4l2_capability {
+ u_int8_t driver[16];
+ u_int8_t card[32];
+ u_int8_t bus_info[32];
+ u_int32_t version;
+ u_int32_t capabilities;
+ u_int32_t device_caps;
+ u_int32_t reserved[3];
+};
+
+/* Values for 'capabilities' field */
+#define V4L2_CAP_VIDEO_CAPTURE 0x00000001 /* Is a video capture device */
+#define V4L2_CAP_VIDEO_OUTPUT 0x00000002 /* Is a video output device */
+#define V4L2_CAP_VIDEO_OVERLAY 0x00000004 /* Can do video overlay */
+#define V4L2_CAP_VBI_CAPTURE 0x00000010 /* Is a raw VBI capture device */
+#define V4L2_CAP_VBI_OUTPUT 0x00000020 /* Is a raw VBI output device */
+#define V4L2_CAP_SLICED_VBI_CAPTURE 0x00000040 /* Is a sliced VBI capture device */
+#define V4L2_CAP_SLICED_VBI_OUTPUT 0x00000080 /* Is a sliced VBI output device */
+#define V4L2_CAP_RDS_CAPTURE 0x00000100 /* RDS data capture */
+#define V4L2_CAP_VIDEO_OUTPUT_OVERLAY 0x00000200 /* Can do video output overlay */
+#define V4L2_CAP_HW_FREQ_SEEK 0x00000400 /* Can do hardware frequency seek */
+#define V4L2_CAP_RDS_OUTPUT 0x00000800 /* Is an RDS encoder */
+
+/* Is a video capture device that supports multiplanar formats */
+#define V4L2_CAP_VIDEO_CAPTURE_MPLANE 0x00001000
+/* Is a video output device that supports multiplanar formats */
+#define V4L2_CAP_VIDEO_OUTPUT_MPLANE 0x00002000
+/* Is a video mem-to-mem device that supports multiplanar formats */
+#define V4L2_CAP_VIDEO_M2M_MPLANE 0x00004000
+/* Is a video mem-to-mem device */
+#define V4L2_CAP_VIDEO_M2M 0x00008000
+
+#define V4L2_CAP_TUNER 0x00010000 /* has a tuner */
+#define V4L2_CAP_AUDIO 0x00020000 /* has audio support */
+#define V4L2_CAP_RADIO 0x00040000 /* is a radio device */
+#define V4L2_CAP_MODULATOR 0x00080000 /* has a modulator */
+
+#define V4L2_CAP_SDR_CAPTURE 0x00100000 /* Is a SDR capture device */
+#define V4L2_CAP_EXT_PIX_FORMAT 0x00200000 /* Supports the extended pixel format */
+#define V4L2_CAP_SDR_OUTPUT 0x00400000 /* Is a SDR output device */
+
+#define V4L2_CAP_READWRITE 0x01000000 /* read/write systemcalls */
+#define V4L2_CAP_ASYNCIO 0x02000000 /* async I/O */
+#define V4L2_CAP_STREAMING 0x04000000 /* streaming I/O ioctls */
+
+#define V4L2_CAP_TOUCH 0x10000000 /* Is a touch device */
+
+#define V4L2_CAP_DEVICE_CAPS 0x80000000 /* sets device capabilities field */
+
+/*
+ * V I D E O I M A G E F O R M A T
+ */
+struct v4l2_pix_format {
+ u_int32_t width;
+ u_int32_t height;
+ u_int32_t pixelformat;
+ u_int32_t field; /* enum v4l2_field */
+ u_int32_t bytesperline; /* for padding, zero if unused */
+ u_int32_t sizeimage;
+ u_int32_t colorspace; /* enum v4l2_colorspace */
+ u_int32_t priv; /* private data, depends on pixelformat */
+ u_int32_t flags; /* format flags (V4L2_PIX_FMT_FLAG_*) */
+ union {
+ /* enum v4l2_ycbcr_encoding */
+ u_int32_t ycbcr_enc;
+ /* enum v4l2_hsv_encoding */
+ u_int32_t hsv_enc;
+ };
+ u_int32_t quantization; /* enum v4l2_quantization */
+ u_int32_t xfer_func; /* enum v4l2_xfer_func */
+};
+
+/* Pixel format FOURCC depth Description */
+
+/* RGB formats */
+#define V4L2_PIX_FMT_RGB332 v4l2_fourcc('R', 'G', 'B', '1') /* 8 RGB-3-3-2 */
+#define V4L2_PIX_FMT_RGB444 v4l2_fourcc('R', '4', '4', '4') /* 16 xxxxrrrr ggggbbbb */
+#define V4L2_PIX_FMT_ARGB444 v4l2_fourcc('A', 'R', '1', '2') /* 16 aaaarrrr ggggbbbb */
+#define V4L2_PIX_FMT_XRGB444 v4l2_fourcc('X', 'R', '1', '2') /* 16 xxxxrrrr ggggbbbb */
+#define V4L2_PIX_FMT_RGB555 v4l2_fourcc('R', 'G', 'B', 'O') /* 16 RGB-5-5-5 */
+#define V4L2_PIX_FMT_ARGB555 v4l2_fourcc('A', 'R', '1', '5') /* 16 ARGB-1-5-5-5 */
+#define V4L2_PIX_FMT_XRGB555 v4l2_fourcc('X', 'R', '1', '5') /* 16 XRGB-1-5-5-5 */
+#define V4L2_PIX_FMT_RGB565 v4l2_fourcc('R', 'G', 'B', 'P') /* 16 RGB-5-6-5 */
+#define V4L2_PIX_FMT_RGB555X v4l2_fourcc('R', 'G', 'B', 'Q') /* 16 RGB-5-5-5 BE */
+#define V4L2_PIX_FMT_ARGB555X v4l2_fourcc_be('A', 'R', '1', '5') /* 16 ARGB-5-5-5 BE */
+#define V4L2_PIX_FMT_XRGB555X v4l2_fourcc_be('X', 'R', '1', '5') /* 16 XRGB-5-5-5 BE */
+#define V4L2_PIX_FMT_RGB565X v4l2_fourcc('R', 'G', 'B', 'R') /* 16 RGB-5-6-5 BE */
+#define V4L2_PIX_FMT_BGR666 v4l2_fourcc('B', 'G', 'R', 'H') /* 18 BGR-6-6-6 */
+#define V4L2_PIX_FMT_BGR24 v4l2_fourcc('B', 'G', 'R', '3') /* 24 BGR-8-8-8 */
+#define V4L2_PIX_FMT_RGB24 v4l2_fourcc('R', 'G', 'B', '3') /* 24 RGB-8-8-8 */
+#define V4L2_PIX_FMT_BGR32 v4l2_fourcc('B', 'G', 'R', '4') /* 32 BGR-8-8-8-8 */
+#define V4L2_PIX_FMT_ABGR32 v4l2_fourcc('A', 'R', '2', '4') /* 32 BGRA-8-8-8-8 */
+#define V4L2_PIX_FMT_XBGR32 v4l2_fourcc('X', 'R', '2', '4') /* 32 BGRX-8-8-8-8 */
+#define V4L2_PIX_FMT_RGB32 v4l2_fourcc('R', 'G', 'B', '4') /* 32 RGB-8-8-8-8 */
+#define V4L2_PIX_FMT_ARGB32 v4l2_fourcc('B', 'A', '2', '4') /* 32 ARGB-8-8-8-8 */
+#define V4L2_PIX_FMT_XRGB32 v4l2_fourcc('B', 'X', '2', '4') /* 32 XRGB-8-8-8-8 */
+
+/* Grey formats */
+#define V4L2_PIX_FMT_GREY v4l2_fourcc('G', 'R', 'E', 'Y') /* 8 Greyscale */
+#define V4L2_PIX_FMT_Y4 v4l2_fourcc('Y', '0', '4', ' ') /* 4 Greyscale */
+#define V4L2_PIX_FMT_Y6 v4l2_fourcc('Y', '0', '6', ' ') /* 6 Greyscale */
+#define V4L2_PIX_FMT_Y10 v4l2_fourcc('Y', '1', '0', ' ') /* 10 Greyscale */
+#define V4L2_PIX_FMT_Y12 v4l2_fourcc('Y', '1', '2', ' ') /* 12 Greyscale */
+#define V4L2_PIX_FMT_Y16 v4l2_fourcc('Y', '1', '6', ' ') /* 16 Greyscale */
+#define V4L2_PIX_FMT_Y16_BE v4l2_fourcc_be('Y', '1', '6', ' ') /* 16 Greyscale BE */
+
+/* Grey bit-packed formats */
+#define V4L2_PIX_FMT_Y10BPACK v4l2_fourcc('Y', '1', '0', 'B') /* 10 Greyscale bit-packed */
+
+/* Palette formats */
+#define V4L2_PIX_FMT_PAL8 v4l2_fourcc('P', 'A', 'L', '8') /* 8 8-bit palette */
+
+/* Chrominance formats */
+#define V4L2_PIX_FMT_UV8 v4l2_fourcc('U', 'V', '8', ' ') /* 8 UV 4:4 */
+
+/* Luminance+Chrominance formats */
+#define V4L2_PIX_FMT_YUYV v4l2_fourcc('Y', 'U', 'Y', 'V') /* 16 YUV 4:2:2 */
+#define V4L2_PIX_FMT_YYUV v4l2_fourcc('Y', 'Y', 'U', 'V') /* 16 YUV 4:2:2 */
+#define V4L2_PIX_FMT_YVYU v4l2_fourcc('Y', 'V', 'Y', 'U') /* 16 YVU 4:2:2 */
+#define V4L2_PIX_FMT_UYVY v4l2_fourcc('U', 'Y', 'V', 'Y') /* 16 YUV 4:2:2 */
+#define V4L2_PIX_FMT_VYUY v4l2_fourcc('V', 'Y', 'U', 'Y') /* 16 YUV 4:2:2 */
+#define V4L2_PIX_FMT_Y41P v4l2_fourcc('Y', '4', '1', 'P') /* 12 YUV 4:1:1 */
+#define V4L2_PIX_FMT_YUV444 v4l2_fourcc('Y', '4', '4', '4') /* 16 xxxxyyyy uuuuvvvv */
+#define V4L2_PIX_FMT_YUV555 v4l2_fourcc('Y', 'U', 'V', 'O') /* 16 YUV-5-5-5 */
+#define V4L2_PIX_FMT_YUV565 v4l2_fourcc('Y', 'U', 'V', 'P') /* 16 YUV-5-6-5 */
+#define V4L2_PIX_FMT_YUV32 v4l2_fourcc('Y', 'U', 'V', '4') /* 32 YUV-8-8-8-8 */
+#define V4L2_PIX_FMT_HI240 v4l2_fourcc('H', 'I', '2', '4') /* 8 8-bit color */
+#define V4L2_PIX_FMT_HM12 v4l2_fourcc('H', 'M', '1', '2') /* 8 YUV 4:2:0 16x16 macroblocks */
+#define V4L2_PIX_FMT_M420 v4l2_fourcc('M', '4', '2', '0') /* 12 YUV 4:2:0 2 lines y, 1 line uv interleaved */
+
+/* two planes -- one Y, one Cr + Cb interleaved */
+#define V4L2_PIX_FMT_NV12 v4l2_fourcc('N', 'V', '1', '2') /* 12 Y/CbCr 4:2:0 */
+#define V4L2_PIX_FMT_NV21 v4l2_fourcc('N', 'V', '2', '1') /* 12 Y/CrCb 4:2:0 */
+#define V4L2_PIX_FMT_NV16 v4l2_fourcc('N', 'V', '1', '6') /* 16 Y/CbCr 4:2:2 */
+#define V4L2_PIX_FMT_NV61 v4l2_fourcc('N', 'V', '6', '1') /* 16 Y/CrCb 4:2:2 */
+#define V4L2_PIX_FMT_NV24 v4l2_fourcc('N', 'V', '2', '4') /* 24 Y/CbCr 4:4:4 */
+#define V4L2_PIX_FMT_NV42 v4l2_fourcc('N', 'V', '4', '2') /* 24 Y/CrCb 4:4:4 */
+
+/* two non contiguous planes - one Y, one Cr + Cb interleaved */
+#define V4L2_PIX_FMT_NV12M v4l2_fourcc('N', 'M', '1', '2') /* 12 Y/CbCr 4:2:0 */
+#define V4L2_PIX_FMT_NV21M v4l2_fourcc('N', 'M', '2', '1') /* 21 Y/CrCb 4:2:0 */
+#define V4L2_PIX_FMT_NV16M v4l2_fourcc('N', 'M', '1', '6') /* 16 Y/CbCr 4:2:2 */
+#define V4L2_PIX_FMT_NV61M v4l2_fourcc('N', 'M', '6', '1') /* 16 Y/CrCb 4:2:2 */
+#define V4L2_PIX_FMT_NV12MT v4l2_fourcc('T', 'M', '1', '2') /* 12 Y/CbCr 4:2:0 64x32 macroblocks */
+#define V4L2_PIX_FMT_NV12MT_16X16 v4l2_fourcc('V', 'M', '1', '2') /* 12 Y/CbCr 4:2:0 16x16 macroblocks */
+
+/* three planes - Y Cb, Cr */
+#define V4L2_PIX_FMT_YUV410 v4l2_fourcc('Y', 'U', 'V', '9') /* 9 YUV 4:1:0 */
+#define V4L2_PIX_FMT_YVU410 v4l2_fourcc('Y', 'V', 'U', '9') /* 9 YVU 4:1:0 */
+#define V4L2_PIX_FMT_YUV411P v4l2_fourcc('4', '1', '1', 'P') /* 12 YVU411 planar */
+#define V4L2_PIX_FMT_YUV420 v4l2_fourcc('Y', 'U', '1', '2') /* 12 YUV 4:2:0 */
+#define V4L2_PIX_FMT_YVU420 v4l2_fourcc('Y', 'V', '1', '2') /* 12 YVU 4:2:0 */
+#define V4L2_PIX_FMT_YUV422P v4l2_fourcc('4', '2', '2', 'P') /* 16 YVU422 planar */
+
+/* three non contiguous planes - Y, Cb, Cr */
+#define V4L2_PIX_FMT_YUV420M v4l2_fourcc('Y', 'M', '1', '2') /* 12 YUV420 planar */
+#define V4L2_PIX_FMT_YVU420M v4l2_fourcc('Y', 'M', '2', '1') /* 12 YVU420 planar */
+#define V4L2_PIX_FMT_YUV422M v4l2_fourcc('Y', 'M', '1', '6') /* 16 YUV422 planar */
+#define V4L2_PIX_FMT_YVU422M v4l2_fourcc('Y', 'M', '6', '1') /* 16 YVU422 planar */
+#define V4L2_PIX_FMT_YUV444M v4l2_fourcc('Y', 'M', '2', '4') /* 24 YUV444 planar */
+#define V4L2_PIX_FMT_YVU444M v4l2_fourcc('Y', 'M', '4', '2') /* 24 YVU444 planar */
+
+/* Bayer formats - see http://www.siliconimaging.com/RGB%20Bayer.htm */
+#define V4L2_PIX_FMT_SBGGR8 v4l2_fourcc('B', 'A', '8', '1') /* 8 BGBG.. GRGR.. */
+#define V4L2_PIX_FMT_SGBRG8 v4l2_fourcc('G', 'B', 'R', 'G') /* 8 GBGB.. RGRG.. */
+#define V4L2_PIX_FMT_SGRBG8 v4l2_fourcc('G', 'R', 'B', 'G') /* 8 GRGR.. BGBG.. */
+#define V4L2_PIX_FMT_SRGGB8 v4l2_fourcc('R', 'G', 'G', 'B') /* 8 RGRG.. GBGB.. */
+#define V4L2_PIX_FMT_SBGGR10 v4l2_fourcc('B', 'G', '1', '0') /* 10 BGBG.. GRGR.. */
+#define V4L2_PIX_FMT_SGBRG10 v4l2_fourcc('G', 'B', '1', '0') /* 10 GBGB.. RGRG.. */
+#define V4L2_PIX_FMT_SGRBG10 v4l2_fourcc('B', 'A', '1', '0') /* 10 GRGR.. BGBG.. */
+#define V4L2_PIX_FMT_SRGGB10 v4l2_fourcc('R', 'G', '1', '0') /* 10 RGRG.. GBGB.. */
+ /* 10bit raw bayer packed, 5 bytes for every 4 pixels */
+#define V4L2_PIX_FMT_SBGGR10P v4l2_fourcc('p', 'B', 'A', 'A')
+#define V4L2_PIX_FMT_SGBRG10P v4l2_fourcc('p', 'G', 'A', 'A')
+#define V4L2_PIX_FMT_SGRBG10P v4l2_fourcc('p', 'g', 'A', 'A')
+#define V4L2_PIX_FMT_SRGGB10P v4l2_fourcc('p', 'R', 'A', 'A')
+ /* 10bit raw bayer a-law compressed to 8 bits */
+#define V4L2_PIX_FMT_SBGGR10ALAW8 v4l2_fourcc('a', 'B', 'A', '8')
+#define V4L2_PIX_FMT_SGBRG10ALAW8 v4l2_fourcc('a', 'G', 'A', '8')
+#define V4L2_PIX_FMT_SGRBG10ALAW8 v4l2_fourcc('a', 'g', 'A', '8')
+#define V4L2_PIX_FMT_SRGGB10ALAW8 v4l2_fourcc('a', 'R', 'A', '8')
+ /* 10bit raw bayer DPCM compressed to 8 bits */
+#define V4L2_PIX_FMT_SBGGR10DPCM8 v4l2_fourcc('b', 'B', 'A', '8')
+#define V4L2_PIX_FMT_SGBRG10DPCM8 v4l2_fourcc('b', 'G', 'A', '8')
+#define V4L2_PIX_FMT_SGRBG10DPCM8 v4l2_fourcc('B', 'D', '1', '0')
+#define V4L2_PIX_FMT_SRGGB10DPCM8 v4l2_fourcc('b', 'R', 'A', '8')
+#define V4L2_PIX_FMT_SBGGR12 v4l2_fourcc('B', 'G', '1', '2') /* 12 BGBG.. GRGR.. */
+#define V4L2_PIX_FMT_SGBRG12 v4l2_fourcc('G', 'B', '1', '2') /* 12 GBGB.. RGRG.. */
+#define V4L2_PIX_FMT_SGRBG12 v4l2_fourcc('B', 'A', '1', '2') /* 12 GRGR.. BGBG.. */
+#define V4L2_PIX_FMT_SRGGB12 v4l2_fourcc('R', 'G', '1', '2') /* 12 RGRG.. GBGB.. */
+#define V4L2_PIX_FMT_SBGGR16 v4l2_fourcc('B', 'Y', 'R', '2') /* 16 BGBG.. GRGR.. */
+#define V4L2_PIX_FMT_SGBRG16 v4l2_fourcc('G', 'B', '1', '6') /* 16 GBGB.. RGRG.. */
+#define V4L2_PIX_FMT_SGRBG16 v4l2_fourcc('G', 'R', '1', '6') /* 16 GRGR.. BGBG.. */
+#define V4L2_PIX_FMT_SRGGB16 v4l2_fourcc('R', 'G', '1', '6') /* 16 RGRG.. GBGB.. */
+
+/* HSV formats */
+#define V4L2_PIX_FMT_HSV24 v4l2_fourcc('H', 'S', 'V', '3')
+#define V4L2_PIX_FMT_HSV32 v4l2_fourcc('H', 'S', 'V', '4')
+
+/* compressed formats */
+#define V4L2_PIX_FMT_MJPEG v4l2_fourcc('M', 'J', 'P', 'G') /* Motion-JPEG */
+#define V4L2_PIX_FMT_JPEG v4l2_fourcc('J', 'P', 'E', 'G') /* JFIF JPEG */
+#define V4L2_PIX_FMT_DV v4l2_fourcc('d', 'v', 's', 'd') /* 1394 */
+#define V4L2_PIX_FMT_MPEG v4l2_fourcc('M', 'P', 'E', 'G') /* MPEG-1/2/4 Multiplexed */
+#define V4L2_PIX_FMT_H264 v4l2_fourcc('H', '2', '6', '4') /* H264 with start codes */
+#define V4L2_PIX_FMT_H264_NO_SC v4l2_fourcc('A', 'V', 'C', '1') /* H264 without start codes */
+#define V4L2_PIX_FMT_H264_MVC v4l2_fourcc('M', '2', '6', '4') /* H264 MVC */
+#define V4L2_PIX_FMT_H263 v4l2_fourcc('H', '2', '6', '3') /* H263 */
+#define V4L2_PIX_FMT_MPEG1 v4l2_fourcc('M', 'P', 'G', '1') /* MPEG-1 ES */
+#define V4L2_PIX_FMT_MPEG2 v4l2_fourcc('M', 'P', 'G', '2') /* MPEG-2 ES */
+#define V4L2_PIX_FMT_MPEG4 v4l2_fourcc('M', 'P', 'G', '4') /* MPEG-4 part 2 ES */
+#define V4L2_PIX_FMT_XVID v4l2_fourcc('X', 'V', 'I', 'D') /* Xvid */
+#define V4L2_PIX_FMT_VC1_ANNEX_G v4l2_fourcc('V', 'C', '1', 'G') /* SMPTE 421M Annex G compliant stream */
+#define V4L2_PIX_FMT_VC1_ANNEX_L v4l2_fourcc('V', 'C', '1', 'L') /* SMPTE 421M Annex L compliant stream */
+#define V4L2_PIX_FMT_VP8 v4l2_fourcc('V', 'P', '8', '0') /* VP8 */
+#define V4L2_PIX_FMT_VP9 v4l2_fourcc('V', 'P', '9', '0') /* VP9 */
+
+/* Vendor-specific formats */
+#define V4L2_PIX_FMT_CPIA1 v4l2_fourcc('C', 'P', 'I', 'A') /* cpia1 YUV */
+#define V4L2_PIX_FMT_WNVA v4l2_fourcc('W', 'N', 'V', 'A') /* Winnov hw compress */
+#define V4L2_PIX_FMT_SN9C10X v4l2_fourcc('S', '9', '1', '0') /* SN9C10x compression */
+#define V4L2_PIX_FMT_SN9C20X_I420 v4l2_fourcc('S', '9', '2', '0') /* SN9C20x YUV 4:2:0 */
+#define V4L2_PIX_FMT_PWC1 v4l2_fourcc('P', 'W', 'C', '1') /* pwc older webcam */
+#define V4L2_PIX_FMT_PWC2 v4l2_fourcc('P', 'W', 'C', '2') /* pwc newer webcam */
+#define V4L2_PIX_FMT_ET61X251 v4l2_fourcc('E', '6', '2', '5') /* ET61X251 compression */
+#define V4L2_PIX_FMT_SPCA501 v4l2_fourcc('S', '5', '0', '1') /* YUYV per line */
+#define V4L2_PIX_FMT_SPCA505 v4l2_fourcc('S', '5', '0', '5') /* YYUV per line */
+#define V4L2_PIX_FMT_SPCA508 v4l2_fourcc('S', '5', '0', '8') /* YUVY per line */
+#define V4L2_PIX_FMT_SPCA561 v4l2_fourcc('S', '5', '6', '1') /* compressed GBRG bayer */
+#define V4L2_PIX_FMT_PAC207 v4l2_fourcc('P', '2', '0', '7') /* compressed BGGR bayer */
+#define V4L2_PIX_FMT_MR97310A v4l2_fourcc('M', '3', '1', '0') /* compressed BGGR bayer */
+#define V4L2_PIX_FMT_JL2005BCD v4l2_fourcc('J', 'L', '2', '0') /* compressed RGGB bayer */
+#define V4L2_PIX_FMT_SN9C2028 v4l2_fourcc('S', 'O', 'N', 'X') /* compressed GBRG bayer */
+#define V4L2_PIX_FMT_SQ905C v4l2_fourcc('9', '0', '5', 'C') /* compressed RGGB bayer */
+#define V4L2_PIX_FMT_PJPG v4l2_fourcc('P', 'J', 'P', 'G') /* Pixart 73xx JPEG */
+#define V4L2_PIX_FMT_OV511 v4l2_fourcc('O', '5', '1', '1') /* ov511 JPEG */
+#define V4L2_PIX_FMT_OV518 v4l2_fourcc('O', '5', '1', '8') /* ov518 JPEG */
+#define V4L2_PIX_FMT_STV0680 v4l2_fourcc('S', '6', '8', '0') /* stv0680 bayer */
+#define V4L2_PIX_FMT_TM6000 v4l2_fourcc('T', 'M', '6', '0') /* tm5600/tm60x0 */
+#define V4L2_PIX_FMT_CIT_YYVYUY v4l2_fourcc('C', 'I', 'T', 'V') /* one line of Y then 1 line of VYUY */
+#define V4L2_PIX_FMT_KONICA420 v4l2_fourcc('K', 'O', 'N', 'I') /* YUV420 planar in blocks of 256 pixels */
+#define V4L2_PIX_FMT_JPGL v4l2_fourcc('J', 'P', 'G', 'L') /* JPEG-Lite */
+#define V4L2_PIX_FMT_SE401 v4l2_fourcc('S', '4', '0', '1') /* se401 janggu compressed rgb */
+#define V4L2_PIX_FMT_S5C_UYVY_JPG v4l2_fourcc('S', '5', 'C', 'I') /* S5C73M3 interleaved UYVY/JPEG */
+#define V4L2_PIX_FMT_Y8I v4l2_fourcc('Y', '8', 'I', ' ') /* Greyscale 8-bit L/R interleaved */
+#define V4L2_PIX_FMT_Y12I v4l2_fourcc('Y', '1', '2', 'I') /* Greyscale 12-bit L/R interleaved */
+#define V4L2_PIX_FMT_Z16 v4l2_fourcc('Z', '1', '6', ' ') /* Depth data 16-bit */
+#define V4L2_PIX_FMT_MT21C v4l2_fourcc('M', 'T', '2', '1') /* Mediatek compressed block mode */
+
+/* SDR formats - used only for Software Defined Radio devices */
+#define V4L2_SDR_FMT_CU8 v4l2_fourcc('C', 'U', '0', '8') /* IQ u8 */
+#define V4L2_SDR_FMT_CU16LE v4l2_fourcc('C', 'U', '1', '6') /* IQ u16le */
+#define V4L2_SDR_FMT_CS8 v4l2_fourcc('C', 'S', '0', '8') /* complex s8 */
+#define V4L2_SDR_FMT_CS14LE v4l2_fourcc('C', 'S', '1', '4') /* complex s14le */
+#define V4L2_SDR_FMT_RU12LE v4l2_fourcc('R', 'U', '1', '2') /* real u12le */
+
+/* Touch formats - used for Touch devices */
+#define V4L2_TCH_FMT_DELTA_TD16 v4l2_fourcc('T', 'D', '1', '6') /* 16-bit signed deltas */
+#define V4L2_TCH_FMT_DELTA_TD08 v4l2_fourcc('T', 'D', '0', '8') /* 8-bit signed deltas */
+#define V4L2_TCH_FMT_TU16 v4l2_fourcc('T', 'U', '1', '6') /* 16-bit unsigned touch data */
+#define V4L2_TCH_FMT_TU08 v4l2_fourcc('T', 'U', '0', '8') /* 8-bit unsigned touch data */
+
+/* priv field value to indicates that subsequent fields are valid. */
+#define V4L2_PIX_FMT_PRIV_MAGIC 0xfeedcafe
+
+/* Flags */
+#define V4L2_PIX_FMT_FLAG_PREMUL_ALPHA 0x00000001
+
+/*
+ * F O R M A T E N U M E R A T I O N
+ */
+struct v4l2_fmtdesc {
+ u_int32_t index; /* Format number */
+ u_int32_t type; /* enum v4l2_buf_type */
+ u_int32_t flags;
+ u_int8_t description[32]; /* Description string */
+ u_int32_t pixelformat; /* Format fourcc */
+ u_int32_t reserved[4];
+};
+
+#define V4L2_FMT_FLAG_COMPRESSED 0x0001
+#define V4L2_FMT_FLAG_EMULATED 0x0002
+
+ /* Frame Size and frame rate enumeration */
+/*
+ * F R A M E S I Z E E N U M E R A T I O N
+ */
+enum v4l2_frmsizetypes {
+ V4L2_FRMSIZE_TYPE_DISCRETE = 1,
+ V4L2_FRMSIZE_TYPE_CONTINUOUS = 2,
+ V4L2_FRMSIZE_TYPE_STEPWISE = 3,
+};
+
+struct v4l2_frmsize_discrete {
+ u_int32_t width; /* Frame width [pixel] */
+ u_int32_t height; /* Frame height [pixel] */
+};
+
+struct v4l2_frmsize_stepwise {
+ u_int32_t min_width; /* Minimum frame width [pixel] */
+ u_int32_t max_width; /* Maximum frame width [pixel] */
+ u_int32_t step_width; /* Frame width step size [pixel] */
+ u_int32_t min_height; /* Minimum frame height [pixel] */
+ u_int32_t max_height; /* Maximum frame height [pixel] */
+ u_int32_t step_height; /* Frame height step size [pixel] */
+};
+
+struct v4l2_frmsizeenum {
+ u_int32_t index; /* Frame size number */
+ u_int32_t pixel_format; /* Pixel format */
+ u_int32_t type; /* Frame size type the device supports. */
+
+ union { /* Frame size */
+ struct v4l2_frmsize_discrete discrete;
+ struct v4l2_frmsize_stepwise stepwise;
+ };
+
+ u_int32_t reserved[2]; /* Reserved space for future use */
+};
+
+/*
+ * F R A M E R A T E E N U M E R A T I O N
+ */
+enum v4l2_frmivaltypes {
+ V4L2_FRMIVAL_TYPE_DISCRETE = 1,
+ V4L2_FRMIVAL_TYPE_CONTINUOUS = 2,
+ V4L2_FRMIVAL_TYPE_STEPWISE = 3,
+};
+
+struct v4l2_frmival_stepwise {
+ struct v4l2_fract min; /* Minimum frame interval [s] */
+ struct v4l2_fract max; /* Maximum frame interval [s] */
+ struct v4l2_fract step; /* Frame interval step size [s] */
+};
+
+struct v4l2_frmivalenum {
+ u_int32_t index; /* Frame format index */
+ u_int32_t pixel_format; /* Pixel format */
+ u_int32_t width; /* Frame width */
+ u_int32_t height; /* Frame height */
+ u_int32_t type; /* Frame interval type the device supports. */
+
+ union { /* Frame interval */
+ struct v4l2_fract discrete;
+ struct v4l2_frmival_stepwise stepwise;
+ };
+
+ u_int32_t reserved[2]; /* Reserved space for future use */
+};
+
+/*
+ * T I M E C O D E
+ */
+struct v4l2_timecode {
+ u_int32_t type;
+ u_int32_t flags;
+ u_int8_t frames;
+ u_int8_t seconds;
+ u_int8_t minutes;
+ u_int8_t hours;
+ u_int8_t userbits[4];
+};
+
+/* Type */
+#define V4L2_TC_TYPE_24FPS 1
+#define V4L2_TC_TYPE_25FPS 2
+#define V4L2_TC_TYPE_30FPS 3
+#define V4L2_TC_TYPE_50FPS 4
+#define V4L2_TC_TYPE_60FPS 5
+
+/* Flags */
+#define V4L2_TC_FLAG_DROPFRAME 0x0001 /* "drop-frame" mode */
+#define V4L2_TC_FLAG_COLORFRAME 0x0002
+#define V4L2_TC_USERBITS_field 0x000C
+#define V4L2_TC_USERBITS_USERDEFINED 0x0000
+#define V4L2_TC_USERBITS_8BITCHARS 0x0008
+/* The above is based on SMPTE timecodes */
+
+struct v4l2_jpegcompression {
+ int quality;
+
+ int APPn; /* Number of APP segment to be written,
+ * must be 0..15 */
+ int APP_len; /* Length of data in JPEG APPn segment */
+ char APP_data[60]; /* Data in the JPEG APPn segment. */
+
+ int COM_len; /* Length of data in JPEG COM segment */
+ char COM_data[60]; /* Data in JPEG COM segment */
+
+ u_int32_t jpeg_markers; /* Which markers should go into the JPEG
+ * output. Unless you exactly know what
+ * you do, leave them untouched.
+ * Including less markers will make the
+ * resulting code smaller, but there will
+ * be fewer applications which can read it.
+ * The presence of the APP and COM marker
+ * is influenced by APP_len and COM_len
+ * ONLY, not by this property! */
+
+#define V4L2_JPEG_MARKER_DHT (1<<3) /* Define Huffman Tables */
+#define V4L2_JPEG_MARKER_DQT (1<<4) /* Define Quantization Tables */
+#define V4L2_JPEG_MARKER_DRI (1<<5) /* Define Restart Interval */
+#define V4L2_JPEG_MARKER_COM (1<<6) /* Comment segment */
+#define V4L2_JPEG_MARKER_APP (1<<7) /* App segment, driver will
+ * always use APP0 */
+};
+
+/*
+ * M E M O R Y - M A P P I N G B U F F E R S
+ */
+struct v4l2_requestbuffers {
+ u_int32_t count;
+ u_int32_t type; /* enum v4l2_buf_type */
+ u_int32_t memory; /* enum v4l2_memory */
+ u_int32_t reserved[2];
+};
+
+/**
+ * struct v4l2_plane - plane info for multi-planar buffers
+ * @bytesused: number of bytes occupied by data in the plane (payload)
+ * @length: size of this plane (NOT the payload) in bytes
+ * @mem_offset: when memory in the associated struct v4l2_buffer is
+ * V4L2_MEMORY_MMAP, equals the offset from the start of
+ * the device memory for this plane (or is a "cookie" that
+ * should be passed to mmap() called on the video node)
+ * @userptr: when memory is V4L2_MEMORY_USERPTR, a userspace pointer
+ * pointing to this plane
+ * @fd: when memory is V4L2_MEMORY_DMABUF, a userspace file
+ * descriptor associated with this plane
+ * @data_offset: offset in the plane to the start of data; usually 0,
+ * unless there is a header in front of the data
+ *
+ * Multi-planar buffers consist of one or more planes, e.g. an YCbCr buffer
+ * with two planes can have one plane for Y, and another for interleaved CbCr
+ * components. Each plane can reside in a separate memory buffer, or even in
+ * a completely separate memory node (e.g. in embedded devices).
+ */
+struct v4l2_plane {
+ u_int32_t bytesused;
+ u_int32_t length;
+ union {
+ u_int32_t mem_offset;
+ unsigned long userptr;
+ int32_t fd;
+ } m;
+ u_int32_t data_offset;
+ u_int32_t reserved[11];
+};
+
+/**
+ * struct v4l2_buffer - video buffer info
+ * @index: id number of the buffer
+ * @type: enum v4l2_buf_type; buffer type (type == *_MPLANE for
+ * multiplanar buffers);
+ * @bytesused: number of bytes occupied by data in the buffer (payload);
+ * unused (set to 0) for multiplanar buffers
+ * @flags: buffer informational flags
+ * @field: enum v4l2_field; field order of the image in the buffer
+ * @timestamp: frame timestamp
+ * @timecode: frame timecode
+ * @sequence: sequence count of this frame
+ * @memory: enum v4l2_memory; the method, in which the actual video data is
+ * passed
+ * @offset: for non-multiplanar buffers with memory == V4L2_MEMORY_MMAP;
+ * offset from the start of the device memory for this plane,
+ * (or a "cookie" that should be passed to mmap() as offset)
+ * @userptr: for non-multiplanar buffers with memory == V4L2_MEMORY_USERPTR;
+ * a userspace pointer pointing to this buffer
+ * @fd: for non-multiplanar buffers with memory == V4L2_MEMORY_DMABUF;
+ * a userspace file descriptor associated with this buffer
+ * @planes: for multiplanar buffers; userspace pointer to the array of plane
+ * info structs for this buffer
+ * @length: size in bytes of the buffer (NOT its payload) for single-plane
+ * buffers (when type != *_MPLANE); number of elements in the
+ * planes array for multi-plane buffers
+ *
+ * Contains data exchanged by application and driver using one of the Streaming
+ * I/O methods.
+ */
+struct v4l2_buffer {
+ u_int32_t index;
+ u_int32_t type;
+ u_int32_t bytesused;
+ u_int32_t flags;
+ u_int32_t field;
+ struct timeval timestamp;
+ struct v4l2_timecode timecode;
+ u_int32_t sequence;
+
+ /* memory location */
+ u_int32_t memory;
+ union {
+ u_int32_t offset;
+ unsigned long userptr;
+ struct v4l2_plane *planes;
+ int32_t fd;
+ } m;
+ u_int32_t length;
+ u_int32_t reserved2;
+ u_int32_t reserved;
+};
+
+/* Flags for 'flags' field */
+/* Buffer is mapped (flag) */
+#define V4L2_BUF_FLAG_MAPPED 0x00000001
+/* Buffer is queued for processing */
+#define V4L2_BUF_FLAG_QUEUED 0x00000002
+/* Buffer is ready */
+#define V4L2_BUF_FLAG_DONE 0x00000004
+/* Image is a keyframe (I-frame) */
+#define V4L2_BUF_FLAG_KEYFRAME 0x00000008
+/* Image is a P-frame */
+#define V4L2_BUF_FLAG_PFRAME 0x00000010
+/* Image is a B-frame */
+#define V4L2_BUF_FLAG_BFRAME 0x00000020
+/* Buffer is ready, but the data contained within is corrupted. */
+#define V4L2_BUF_FLAG_ERROR 0x00000040
+/* timecode field is valid */
+#define V4L2_BUF_FLAG_TIMECODE 0x00000100
+/* Buffer is prepared for queuing */
+#define V4L2_BUF_FLAG_PREPARED 0x00000400
+/* Cache handling flags */
+#define V4L2_BUF_FLAG_NO_CACHE_INVALIDATE 0x00000800
+#define V4L2_BUF_FLAG_NO_CACHE_CLEAN 0x00001000
+/* Timestamp type */
+#define V4L2_BUF_FLAG_TIMESTAMP_MASK 0x0000e000
+#define V4L2_BUF_FLAG_TIMESTAMP_UNKNOWN 0x00000000
+#define V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC 0x00002000
+#define V4L2_BUF_FLAG_TIMESTAMP_COPY 0x00004000
+/* Timestamp sources. */
+#define V4L2_BUF_FLAG_TSTAMP_SRC_MASK 0x00070000
+#define V4L2_BUF_FLAG_TSTAMP_SRC_EOF 0x00000000
+#define V4L2_BUF_FLAG_TSTAMP_SRC_SOE 0x00010000
+/* mem2mem encoder/decoder */
+#define V4L2_BUF_FLAG_LAST 0x00100000
+
+/**
+ * struct v4l2_exportbuffer - export of video buffer as DMABUF file descriptor
+ *
+ * @index: id number of the buffer
+ * @type: enum v4l2_buf_type; buffer type (type == *_MPLANE for
+ * multiplanar buffers);
+ * @plane: index of the plane to be exported, 0 for single plane queues
+ * @flags: flags for newly created file, currently only O_CLOEXEC is
+ * supported, refer to manual of open syscall for more details
+ * @fd: file descriptor associated with DMABUF (set by driver)
+ *
+ * Contains data used for exporting a video buffer as DMABUF file descriptor.
+ * The buffer is identified by a 'cookie' returned by VIDIOC_QUERYBUF
+ * (identical to the cookie used to mmap() the buffer to userspace). All
+ * reserved fields must be set to zero. The field reserved0 is expected to
+ * become a structure 'type' allowing an alternative layout of the structure
+ * content. Therefore this field should not be used for any other extensions.
+ */
+struct v4l2_exportbuffer {
+ u_int32_t type; /* enum v4l2_buf_type */
+ u_int32_t index;
+ u_int32_t plane;
+ u_int32_t flags;
+ int32_t fd;
+ u_int32_t reserved[11];
+};
+
+/*
+ * O V E R L A Y P R E V I E W
+ */
+struct v4l2_framebuffer {
+ u_int32_t capability;
+ u_int32_t flags;
+/* FIXME: in theory we should pass something like PCI device + memory
+ * region + offset instead of some physical address */
+ void *base;
+ struct {
+ u_int32_t width;
+ u_int32_t height;
+ u_int32_t pixelformat;
+ u_int32_t field; /* enum v4l2_field */
+ u_int32_t bytesperline; /* for padding, zero if unused */
+ u_int32_t sizeimage;
+ u_int32_t colorspace; /* enum v4l2_colorspace */
+ u_int32_t priv; /* reserved field, set to 0 */
+ } fmt;
+};
+/* Flags for the 'capability' field. Read only */
+#define V4L2_FBUF_CAP_EXTERNOVERLAY 0x0001
+#define V4L2_FBUF_CAP_CHROMAKEY 0x0002
+#define V4L2_FBUF_CAP_LIST_CLIPPING 0x0004
+#define V4L2_FBUF_CAP_BITMAP_CLIPPING 0x0008
+#define V4L2_FBUF_CAP_LOCAL_ALPHA 0x0010
+#define V4L2_FBUF_CAP_GLOBAL_ALPHA 0x0020
+#define V4L2_FBUF_CAP_LOCAL_INV_ALPHA 0x0040
+#define V4L2_FBUF_CAP_SRC_CHROMAKEY 0x0080
+/* Flags for the 'flags' field. */
+#define V4L2_FBUF_FLAG_PRIMARY 0x0001
+#define V4L2_FBUF_FLAG_OVERLAY 0x0002
+#define V4L2_FBUF_FLAG_CHROMAKEY 0x0004
+#define V4L2_FBUF_FLAG_LOCAL_ALPHA 0x0008
+#define V4L2_FBUF_FLAG_GLOBAL_ALPHA 0x0010
+#define V4L2_FBUF_FLAG_LOCAL_INV_ALPHA 0x0020
+#define V4L2_FBUF_FLAG_SRC_CHROMAKEY 0x0040
+
+struct v4l2_clip {
+ struct v4l2_rect c;
+ struct v4l2_clip __user *next;
+};
+
+struct v4l2_window {
+ struct v4l2_rect w;
+ u_int32_t field; /* enum v4l2_field */
+ u_int32_t chromakey;
+ struct v4l2_clip __user *clips;
+ u_int32_t clipcount;
+ void __user *bitmap;
+ u_int8_t global_alpha;
+};
+
+/*
+ * C A P T U R E P A R A M E T E R S
+ */
+struct v4l2_captureparm {
+ u_int32_t capability; /* Supported modes */
+ u_int32_t capturemode; /* Current mode */
+ struct v4l2_fract timeperframe; /* Time per frame in seconds */
+ u_int32_t extendedmode; /* Driver-specific extensions */
+ u_int32_t readbuffers; /* # of buffers for read */
+ u_int32_t reserved[4];
+};
+
+/* Flags for 'capability' and 'capturemode' fields */
+#define V4L2_MODE_HIGHQUALITY 0x0001 /* High quality imaging mode */
+#define V4L2_CAP_TIMEPERFRAME 0x1000 /* timeperframe field is supported */
+
+struct v4l2_outputparm {
+ u_int32_t capability; /* Supported modes */
+ u_int32_t outputmode; /* Current mode */
+ struct v4l2_fract timeperframe; /* Time per frame in seconds */
+ u_int32_t extendedmode; /* Driver-specific extensions */
+ u_int32_t writebuffers; /* # of buffers for write */
+ u_int32_t reserved[4];
+};
+
+/*
+ * I N P U T I M A G E C R O P P I N G
+ */
+struct v4l2_cropcap {
+ u_int32_t type; /* enum v4l2_buf_type */
+ struct v4l2_rect bounds;
+ struct v4l2_rect defrect;
+ struct v4l2_fract pixelaspect;
+};
+
+struct v4l2_crop {
+ u_int32_t type; /* enum v4l2_buf_type */
+ struct v4l2_rect c;
+};
+
+/**
+ * struct v4l2_selection - selection info
+ * @type: buffer type (do not use *_MPLANE types)
+ * @target: Selection target, used to choose one of possible rectangles;
+ * defined in v4l2-common.h; V4L2_SEL_TGT_* .
+ * @flags: constraints flags, defined in v4l2-common.h; V4L2_SEL_FLAG_*.
+ * @r: coordinates of selection window
+ * @reserved: for future use, rounds structure size to 64 bytes, set to zero
+ *
+ * Hardware may use multiple helper windows to process a video stream.
+ * The structure is used to exchange this selection areas between
+ * an application and a driver.
+ */
+struct v4l2_selection {
+ u_int32_t type;
+ u_int32_t target;
+ u_int32_t flags;
+ struct v4l2_rect r;
+ u_int32_t reserved[9];
+};
+
+
+/*
+ * A N A L O G V I D E O S T A N D A R D
+ */
+
+typedef u_int64_t v4l2_std_id;
+
+/* one bit for each */
+#define V4L2_STD_PAL_B ((v4l2_std_id)0x00000001)
+#define V4L2_STD_PAL_B1 ((v4l2_std_id)0x00000002)
+#define V4L2_STD_PAL_G ((v4l2_std_id)0x00000004)
+#define V4L2_STD_PAL_H ((v4l2_std_id)0x00000008)
+#define V4L2_STD_PAL_I ((v4l2_std_id)0x00000010)
+#define V4L2_STD_PAL_D ((v4l2_std_id)0x00000020)
+#define V4L2_STD_PAL_D1 ((v4l2_std_id)0x00000040)
+#define V4L2_STD_PAL_K ((v4l2_std_id)0x00000080)
+
+#define V4L2_STD_PAL_M ((v4l2_std_id)0x00000100)
+#define V4L2_STD_PAL_N ((v4l2_std_id)0x00000200)
+#define V4L2_STD_PAL_Nc ((v4l2_std_id)0x00000400)
+#define V4L2_STD_PAL_60 ((v4l2_std_id)0x00000800)
+
+#define V4L2_STD_NTSC_M ((v4l2_std_id)0x00001000) /* BTSC */
+#define V4L2_STD_NTSC_M_JP ((v4l2_std_id)0x00002000) /* EIA-J */
+#define V4L2_STD_NTSC_443 ((v4l2_std_id)0x00004000)
+#define V4L2_STD_NTSC_M_KR ((v4l2_std_id)0x00008000) /* FM A2 */
+
+#define V4L2_STD_SECAM_B ((v4l2_std_id)0x00010000)
+#define V4L2_STD_SECAM_D ((v4l2_std_id)0x00020000)
+#define V4L2_STD_SECAM_G ((v4l2_std_id)0x00040000)
+#define V4L2_STD_SECAM_H ((v4l2_std_id)0x00080000)
+#define V4L2_STD_SECAM_K ((v4l2_std_id)0x00100000)
+#define V4L2_STD_SECAM_K1 ((v4l2_std_id)0x00200000)
+#define V4L2_STD_SECAM_L ((v4l2_std_id)0x00400000)
+#define V4L2_STD_SECAM_LC ((v4l2_std_id)0x00800000)
+
+/* ATSC/HDTV */
+#define V4L2_STD_ATSC_8_VSB ((v4l2_std_id)0x01000000)
+#define V4L2_STD_ATSC_16_VSB ((v4l2_std_id)0x02000000)
+
+/* FIXME:
+ Although std_id is 64 bits, there is an issue on PPC32 architecture that
+ makes switch(u_int64_t) to break. So, there's a hack on v4l2-common.c rounding
+ this value to 32 bits.
+ As, currently, the max value is for V4L2_STD_ATSC_16_VSB (30 bits wide),
+ it should work fine. However, if needed to add more than two standards,
+ v4l2-common.c should be fixed.
+ */
+
+/*
+ * Some macros to merge video standards in order to make live easier for the
+ * drivers and V4L2 applications
+ */
+
+/*
+ * "Common" NTSC/M - It should be noticed that V4L2_STD_NTSC_443 is
+ * Missing here.
+ */
+#define V4L2_STD_NTSC (V4L2_STD_NTSC_M |\
+ V4L2_STD_NTSC_M_JP |\
+ V4L2_STD_NTSC_M_KR)
+/* Secam macros */
+#define V4L2_STD_SECAM_DK (V4L2_STD_SECAM_D |\
+ V4L2_STD_SECAM_K |\
+ V4L2_STD_SECAM_K1)
+/* All Secam Standards */
+#define V4L2_STD_SECAM (V4L2_STD_SECAM_B |\
+ V4L2_STD_SECAM_G |\
+ V4L2_STD_SECAM_H |\
+ V4L2_STD_SECAM_DK |\
+ V4L2_STD_SECAM_L |\
+ V4L2_STD_SECAM_LC)
+/* PAL macros */
+#define V4L2_STD_PAL_BG (V4L2_STD_PAL_B |\
+ V4L2_STD_PAL_B1 |\
+ V4L2_STD_PAL_G)
+#define V4L2_STD_PAL_DK (V4L2_STD_PAL_D |\
+ V4L2_STD_PAL_D1 |\
+ V4L2_STD_PAL_K)
+/*
+ * "Common" PAL - This macro is there to be compatible with the old
+ * V4L1 concept of "PAL": /BGDKHI.
+ * Several PAL standards are missing here: /M, /N and /Nc
+ */
+#define V4L2_STD_PAL (V4L2_STD_PAL_BG |\
+ V4L2_STD_PAL_DK |\
+ V4L2_STD_PAL_H |\
+ V4L2_STD_PAL_I)
+/* Chroma "agnostic" standards */
+#define V4L2_STD_B (V4L2_STD_PAL_B |\
+ V4L2_STD_PAL_B1 |\
+ V4L2_STD_SECAM_B)
+#define V4L2_STD_G (V4L2_STD_PAL_G |\
+ V4L2_STD_SECAM_G)
+#define V4L2_STD_H (V4L2_STD_PAL_H |\
+ V4L2_STD_SECAM_H)
+#define V4L2_STD_L (V4L2_STD_SECAM_L |\
+ V4L2_STD_SECAM_LC)
+#define V4L2_STD_GH (V4L2_STD_G |\
+ V4L2_STD_H)
+#define V4L2_STD_DK (V4L2_STD_PAL_DK |\
+ V4L2_STD_SECAM_DK)
+#define V4L2_STD_BG (V4L2_STD_B |\
+ V4L2_STD_G)
+#define V4L2_STD_MN (V4L2_STD_PAL_M |\
+ V4L2_STD_PAL_N |\
+ V4L2_STD_PAL_Nc |\
+ V4L2_STD_NTSC)
+
+/* Standards where MTS/BTSC stereo could be found */
+#define V4L2_STD_MTS (V4L2_STD_NTSC_M |\
+ V4L2_STD_PAL_M |\
+ V4L2_STD_PAL_N |\
+ V4L2_STD_PAL_Nc)
+
+/* Standards for Countries with 60Hz Line frequency */
+#define V4L2_STD_525_60 (V4L2_STD_PAL_M |\
+ V4L2_STD_PAL_60 |\
+ V4L2_STD_NTSC |\
+ V4L2_STD_NTSC_443)
+/* Standards for Countries with 50Hz Line frequency */
+#define V4L2_STD_625_50 (V4L2_STD_PAL |\
+ V4L2_STD_PAL_N |\
+ V4L2_STD_PAL_Nc |\
+ V4L2_STD_SECAM)
+
+#define V4L2_STD_ATSC (V4L2_STD_ATSC_8_VSB |\
+ V4L2_STD_ATSC_16_VSB)
+/* Macros with none and all analog standards */
+#define V4L2_STD_UNKNOWN 0
+#define V4L2_STD_ALL (V4L2_STD_525_60 |\
+ V4L2_STD_625_50)
+
+struct v4l2_standard {
+ u_int32_t index;
+ v4l2_std_id id;
+ u_int8_t name[24];
+ struct v4l2_fract frameperiod; /* Frames, not fields */
+ u_int32_t framelines;
+ u_int32_t reserved[4];
+};
+
+/*
+ * D V B T T I M I N G S
+ */
+
+/** struct v4l2_bt_timings - BT.656/BT.1120 timing data
+ * @width: total width of the active video in pixels
+ * @height: total height of the active video in lines
+ * @interlaced: Interlaced or progressive
+ * @polarities: Positive or negative polarities
+ * @pixelclock: Pixel clock in HZ. Ex. 74.25MHz->74250000
+ * @hfrontporch:Horizontal front porch in pixels
+ * @hsync: Horizontal Sync length in pixels
+ * @hbackporch: Horizontal back porch in pixels
+ * @vfrontporch:Vertical front porch in lines
+ * @vsync: Vertical Sync length in lines
+ * @vbackporch: Vertical back porch in lines
+ * @il_vfrontporch:Vertical front porch for the even field
+ * (aka field 2) of interlaced field formats
+ * @il_vsync: Vertical Sync length for the even field
+ * (aka field 2) of interlaced field formats
+ * @il_vbackporch:Vertical back porch for the even field
+ * (aka field 2) of interlaced field formats
+ * @standards: Standards the timing belongs to
+ * @flags: Flags
+ * @picture_aspect: The picture aspect ratio (hor/vert).
+ * @cea861_vic: VIC code as per the CEA-861 standard.
+ * @hdmi_vic: VIC code as per the HDMI standard.
+ * @reserved: Reserved fields, must be zeroed.
+ *
+ * A note regarding vertical interlaced timings: height refers to the total
+ * height of the active video frame (= two fields). The blanking timings refer
+ * to the blanking of each field. So the height of the total frame is
+ * calculated as follows:
+ *
+ * tot_height = height + vfrontporch + vsync + vbackporch +
+ * il_vfrontporch + il_vsync + il_vbackporch
+ *
+ * The active height of each field is height / 2.
+ */
+struct v4l2_bt_timings {
+ u_int32_t width;
+ u_int32_t height;
+ u_int32_t interlaced;
+ u_int32_t polarities;
+ u_int64_t pixelclock;
+ u_int32_t hfrontporch;
+ u_int32_t hsync;
+ u_int32_t hbackporch;
+ u_int32_t vfrontporch;
+ u_int32_t vsync;
+ u_int32_t vbackporch;
+ u_int32_t il_vfrontporch;
+ u_int32_t il_vsync;
+ u_int32_t il_vbackporch;
+ u_int32_t standards;
+ u_int32_t flags;
+ struct v4l2_fract picture_aspect;
+ u_int8_t cea861_vic;
+ u_int8_t hdmi_vic;
+ u_int8_t reserved[46];
+} __attribute__ ((packed));
+
+/* Interlaced or progressive format */
+#define V4L2_DV_PROGRESSIVE 0
+#define V4L2_DV_INTERLACED 1
+
+/* Polarities. If bit is not set, it is assumed to be negative polarity */
+#define V4L2_DV_VSYNC_POS_POL 0x00000001
+#define V4L2_DV_HSYNC_POS_POL 0x00000002
+
+/* Timings standards */
+#define V4L2_DV_BT_STD_CEA861 (1 << 0) /* CEA-861 Digital TV Profile */
+#define V4L2_DV_BT_STD_DMT (1 << 1) /* VESA Discrete Monitor Timings */
+#define V4L2_DV_BT_STD_CVT (1 << 2) /* VESA Coordinated Video Timings */
+#define V4L2_DV_BT_STD_GTF (1 << 3) /* VESA Generalized Timings Formula */
+#define V4L2_DV_BT_STD_SDI (1 << 4) /* SDI Timings */
+
+/* Flags */
+
+/*
+ * CVT/GTF specific: timing uses reduced blanking (CVT) or the 'Secondary
+ * GTF' curve (GTF). In both cases the horizontal and/or vertical blanking
+ * intervals are reduced, allowing a higher resolution over the same
+ * bandwidth. This is a read-only flag.
+ */
+#define V4L2_DV_FL_REDUCED_BLANKING (1 << 0)
+/*
+ * CEA-861 specific: set for CEA-861 formats with a framerate of a multiple
+ * of six. These formats can be optionally played at 1 / 1.001 speed.
+ * This is a read-only flag.
+ */
+#define V4L2_DV_FL_CAN_REDUCE_FPS (1 << 1)
+/*
+ * CEA-861 specific: only valid for video transmitters, the flag is cleared
+ * by receivers.
+ * If the framerate of the format is a multiple of six, then the pixelclock
+ * used to set up the transmitter is divided by 1.001 to make it compatible
+ * with 60 Hz based standards such as NTSC and PAL-M that use a framerate of
+ * 29.97 Hz. Otherwise this flag is cleared. If the transmitter can't generate
+ * such frequencies, then the flag will also be cleared.
+ */
+#define V4L2_DV_FL_REDUCED_FPS (1 << 2)
+/*
+ * Specific to interlaced formats: if set, then field 1 is really one half-line
+ * longer and field 2 is really one half-line shorter, so each field has
+ * exactly the same number of half-lines. Whether half-lines can be detected
+ * or used depends on the hardware.
+ */
+#define V4L2_DV_FL_HALF_LINE (1 << 3)
+/*
+ * If set, then this is a Consumer Electronics (CE) video format. Such formats
+ * differ from other formats (commonly called IT formats) in that if RGB
+ * encoding is used then by default the RGB values use limited range (i.e.
+ * use the range 16-235) as opposed to 0-255. All formats defined in CEA-861
+ * except for the 640x480 format are CE formats.
+ */
+#define V4L2_DV_FL_IS_CE_VIDEO (1 << 4)
+/* Some formats like SMPTE-125M have an interlaced signal with a odd
+ * total height. For these formats, if this flag is set, the first
+ * field has the extra line. If not, it is the second field.
+ */
+#define V4L2_DV_FL_FIRST_FIELD_EXTRA_LINE (1 << 5)
+/*
+ * If set, then the picture_aspect field is valid. Otherwise assume that the
+ * pixels are square, so the picture aspect ratio is the same as the width to
+ * height ratio.
+ */
+#define V4L2_DV_FL_HAS_PICTURE_ASPECT (1 << 6)
+/*
+ * If set, then the cea861_vic field is valid and contains the Video
+ * Identification Code as per the CEA-861 standard.
+ */
+#define V4L2_DV_FL_HAS_CEA861_VIC (1 << 7)
+/*
+ * If set, then the hdmi_vic field is valid and contains the Video
+ * Identification Code as per the HDMI standard (HDMI Vendor Specific
+ * InfoFrame).
+ */
+#define V4L2_DV_FL_HAS_HDMI_VIC (1 << 8)
+
+/* A few useful defines to calculate the total blanking and frame sizes */
+#define V4L2_DV_BT_BLANKING_WIDTH(bt) \
+ ((bt)->hfrontporch + (bt)->hsync + (bt)->hbackporch)
+#define V4L2_DV_BT_FRAME_WIDTH(bt) \
+ ((bt)->width + V4L2_DV_BT_BLANKING_WIDTH(bt))
+#define V4L2_DV_BT_BLANKING_HEIGHT(bt) \
+ ((bt)->vfrontporch + (bt)->vsync + (bt)->vbackporch + \
+ (bt)->il_vfrontporch + (bt)->il_vsync + (bt)->il_vbackporch)
+#define V4L2_DV_BT_FRAME_HEIGHT(bt) \
+ ((bt)->height + V4L2_DV_BT_BLANKING_HEIGHT(bt))
+
+/** struct v4l2_dv_timings - DV timings
+ * @type: the type of the timings
+ * @bt: BT656/1120 timings
+ */
+struct v4l2_dv_timings {
+ u_int32_t type;
+ union {
+ struct v4l2_bt_timings bt;
+ u_int32_t reserved[32];
+ };
+} __attribute__ ((packed));
+
+/* Values for the type field */
+#define V4L2_DV_BT_656_1120 0 /* BT.656/1120 timing type */
+
+
+/** struct v4l2_enum_dv_timings - DV timings enumeration
+ * @index: enumeration index
+ * @pad: the pad number for which to enumerate timings (used with
+ * v4l-subdev nodes only)
+ * @reserved: must be zeroed
+ * @timings: the timings for the given index
+ */
+struct v4l2_enum_dv_timings {
+ u_int32_t index;
+ u_int32_t pad;
+ u_int32_t reserved[2];
+ struct v4l2_dv_timings timings;
+};
+
+/** struct v4l2_bt_timings_cap - BT.656/BT.1120 timing capabilities
+ * @min_width: width in pixels
+ * @max_width: width in pixels
+ * @min_height: height in lines
+ * @max_height: height in lines
+ * @min_pixelclock: Pixel clock in HZ. Ex. 74.25MHz->74250000
+ * @max_pixelclock: Pixel clock in HZ. Ex. 74.25MHz->74250000
+ * @standards: Supported standards
+ * @capabilities: Supported capabilities
+ * @reserved: Must be zeroed
+ */
+struct v4l2_bt_timings_cap {
+ u_int32_t min_width;
+ u_int32_t max_width;
+ u_int32_t min_height;
+ u_int32_t max_height;
+ u_int64_t min_pixelclock;
+ u_int64_t max_pixelclock;
+ u_int32_t standards;
+ u_int32_t capabilities;
+ u_int32_t reserved[16];
+} __attribute__ ((packed));
+
+/* Supports interlaced formats */
+#define V4L2_DV_BT_CAP_INTERLACED (1 << 0)
+/* Supports progressive formats */
+#define V4L2_DV_BT_CAP_PROGRESSIVE (1 << 1)
+/* Supports CVT/GTF reduced blanking */
+#define V4L2_DV_BT_CAP_REDUCED_BLANKING (1 << 2)
+/* Supports custom formats */
+#define V4L2_DV_BT_CAP_CUSTOM (1 << 3)
+
+/** struct v4l2_dv_timings_cap - DV timings capabilities
+ * @type: the type of the timings (same as in struct v4l2_dv_timings)
+ * @pad: the pad number for which to query capabilities (used with
+ * v4l-subdev nodes only)
+ * @bt: the BT656/1120 timings capabilities
+ */
+struct v4l2_dv_timings_cap {
+ u_int32_t type;
+ u_int32_t pad;
+ u_int32_t reserved[2];
+ union {
+ struct v4l2_bt_timings_cap bt;
+ u_int32_t raw_data[32];
+ };
+};
+
+
+/*
+ * V I D E O I N P U T S
+ */
+struct v4l2_input {
+ u_int32_t index; /* Which input */
+ u_int8_t name[32]; /* Label */
+ u_int32_t type; /* Type of input */
+ u_int32_t audioset; /* Associated audios (bitfield) */
+ u_int32_t tuner; /* enum v4l2_tuner_type */
+ v4l2_std_id std;
+ u_int32_t status;
+ u_int32_t capabilities;
+ u_int32_t reserved[3];
+};
+
+/* Values for the 'type' field */
+#define V4L2_INPUT_TYPE_TUNER 1
+#define V4L2_INPUT_TYPE_CAMERA 2
+#define V4L2_INPUT_TYPE_TOUCH 3
+
+/* field 'status' - general */
+#define V4L2_IN_ST_NO_POWER 0x00000001 /* Attached device is off */
+#define V4L2_IN_ST_NO_SIGNAL 0x00000002
+#define V4L2_IN_ST_NO_COLOR 0x00000004
+
+/* field 'status' - sensor orientation */
+/* If sensor is mounted upside down set both bits */
+#define V4L2_IN_ST_HFLIP 0x00000010 /* Frames are flipped horizontally */
+#define V4L2_IN_ST_VFLIP 0x00000020 /* Frames are flipped vertically */
+
+/* field 'status' - analog */
+#define V4L2_IN_ST_NO_H_LOCK 0x00000100 /* No horizontal sync lock */
+#define V4L2_IN_ST_COLOR_KILL 0x00000200 /* Color killer is active */
+#define V4L2_IN_ST_NO_V_LOCK 0x00000400 /* No vertical sync lock */
+#define V4L2_IN_ST_NO_STD_LOCK 0x00000800 /* No standard format lock */
+
+/* field 'status' - digital */
+#define V4L2_IN_ST_NO_SYNC 0x00010000 /* No synchronization lock */
+#define V4L2_IN_ST_NO_EQU 0x00020000 /* No equalizer lock */
+#define V4L2_IN_ST_NO_CARRIER 0x00040000 /* Carrier recovery failed */
+
+/* field 'status' - VCR and set-top box */
+#define V4L2_IN_ST_MACROVISION 0x01000000 /* Macrovision detected */
+#define V4L2_IN_ST_NO_ACCESS 0x02000000 /* Conditional access denied */
+#define V4L2_IN_ST_VTR 0x04000000 /* VTR time constant */
+
+/* capabilities flags */
+#define V4L2_IN_CAP_DV_TIMINGS 0x00000002 /* Supports S_DV_TIMINGS */
+#define V4L2_IN_CAP_CUSTOM_TIMINGS V4L2_IN_CAP_DV_TIMINGS /* For compatibility */
+#define V4L2_IN_CAP_STD 0x00000004 /* Supports S_STD */
+#define V4L2_IN_CAP_NATIVE_SIZE 0x00000008 /* Supports setting native size */
+
+/*
+ * V I D E O O U T P U T S
+ */
+struct v4l2_output {
+ u_int32_t index; /* Which output */
+ u_int8_t name[32]; /* Label */
+ u_int32_t type; /* Type of output */
+ u_int32_t audioset; /* Associated audios (bitfield) */
+ u_int32_t modulator; /* Associated modulator */
+ v4l2_std_id std;
+ u_int32_t capabilities;
+ u_int32_t reserved[3];
+};
+/* Values for the 'type' field */
+#define V4L2_OUTPUT_TYPE_MODULATOR 1
+#define V4L2_OUTPUT_TYPE_ANALOG 2
+#define V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY 3
+
+/* capabilities flags */
+#define V4L2_OUT_CAP_DV_TIMINGS 0x00000002 /* Supports S_DV_TIMINGS */
+#define V4L2_OUT_CAP_CUSTOM_TIMINGS V4L2_OUT_CAP_DV_TIMINGS /* For compatibility */
+#define V4L2_OUT_CAP_STD 0x00000004 /* Supports S_STD */
+#define V4L2_OUT_CAP_NATIVE_SIZE 0x00000008 /* Supports setting native size */
+
+/*
+ * C O N T R O L S
+ */
+struct v4l2_control {
+ u_int32_t id;
+ int32_t value;
+};
+
+struct v4l2_ext_control {
+ u_int32_t id;
+ u_int32_t size;
+ u_int32_t reserved2[1];
+ union {
+ int32_t value;
+ int64_t value64;
+ char __user *string;
+ u_int8_t __user *p_u8;
+ u_int16_t __user *p_u16;
+ u_int32_t __user *p_u32;
+ void __user *ptr;
+ };
+} __attribute__ ((packed));
+
+struct v4l2_ext_controls {
+ union {
+#ifndef __KERNEL__
+ u_int32_t ctrl_class;
+#endif
+ u_int32_t which;
+ };
+ u_int32_t count;
+ u_int32_t error_idx;
+ u_int32_t reserved[2];
+ struct v4l2_ext_control *controls;
+};
+
+#define V4L2_CTRL_ID_MASK (0x0fffffff)
+#ifndef __KERNEL__
+#define V4L2_CTRL_ID2CLASS(id) ((id) & 0x0fff0000UL)
+#endif
+#define V4L2_CTRL_ID2WHICH(id) ((id) & 0x0fff0000UL)
+#define V4L2_CTRL_DRIVER_PRIV(id) (((id) & 0xffff) >= 0x1000)
+#define V4L2_CTRL_MAX_DIMS (4)
+#define V4L2_CTRL_WHICH_CUR_VAL 0
+#define V4L2_CTRL_WHICH_DEF_VAL 0x0f000000
+
+enum v4l2_ctrl_type {
+ V4L2_CTRL_TYPE_INTEGER = 1,
+ V4L2_CTRL_TYPE_BOOLEAN = 2,
+ V4L2_CTRL_TYPE_MENU = 3,
+ V4L2_CTRL_TYPE_BUTTON = 4,
+ V4L2_CTRL_TYPE_INTEGER64 = 5,
+ V4L2_CTRL_TYPE_CTRL_CLASS = 6,
+ V4L2_CTRL_TYPE_STRING = 7,
+ V4L2_CTRL_TYPE_BITMASK = 8,
+ V4L2_CTRL_TYPE_INTEGER_MENU = 9,
+
+ /* Compound types are >= 0x0100 */
+ V4L2_CTRL_COMPOUND_TYPES = 0x0100,
+ V4L2_CTRL_TYPE_U8 = 0x0100,
+ V4L2_CTRL_TYPE_U16 = 0x0101,
+ V4L2_CTRL_TYPE_U32 = 0x0102,
+};
+
+/* Used in the VIDIOC_QUERYCTRL ioctl for querying controls */
+struct v4l2_queryctrl {
+ u_int32_t id;
+ u_int32_t type; /* enum v4l2_ctrl_type */
+ u_int8_t name[32]; /* Whatever */
+ int32_t minimum; /* Note signedness */
+ int32_t maximum;
+ int32_t step;
+ int32_t default_value;
+ u_int32_t flags;
+ u_int32_t reserved[2];
+};
+
+/* Used in the VIDIOC_QUERY_EXT_CTRL ioctl for querying extended controls */
+struct v4l2_query_ext_ctrl {
+ u_int32_t id;
+ u_int32_t type;
+ char name[32];
+ int64_t minimum;
+ int64_t maximum;
+ u_int64_t step;
+ int64_t default_value;
+ u_int32_t flags;
+ u_int32_t elem_size;
+ u_int32_t elems;
+ u_int32_t nr_of_dims;
+ u_int32_t dims[V4L2_CTRL_MAX_DIMS];
+ u_int32_t reserved[32];
+};
+
+/* Used in the VIDIOC_QUERYMENU ioctl for querying menu items */
+struct v4l2_querymenu {
+ u_int32_t id;
+ u_int32_t index;
+ union {
+ u_int8_t name[32]; /* Whatever */
+ int64_t value;
+ };
+ u_int32_t reserved;
+} __attribute__ ((packed));
+
+/* Control flags */
+#define V4L2_CTRL_FLAG_DISABLED 0x0001
+#define V4L2_CTRL_FLAG_GRABBED 0x0002
+#define V4L2_CTRL_FLAG_READ_ONLY 0x0004
+#define V4L2_CTRL_FLAG_UPDATE 0x0008
+#define V4L2_CTRL_FLAG_INACTIVE 0x0010
+#define V4L2_CTRL_FLAG_SLIDER 0x0020
+#define V4L2_CTRL_FLAG_WRITE_ONLY 0x0040
+#define V4L2_CTRL_FLAG_VOLATILE 0x0080
+#define V4L2_CTRL_FLAG_HAS_PAYLOAD 0x0100
+#define V4L2_CTRL_FLAG_EXECUTE_ON_WRITE 0x0200
+
+/* Query flags, to be ORed with the control ID */
+#define V4L2_CTRL_FLAG_NEXT_CTRL 0x80000000
+#define V4L2_CTRL_FLAG_NEXT_COMPOUND 0x40000000
+
+/* User-class control IDs defined by V4L2 */
+#define V4L2_CID_MAX_CTRLS 1024
+/* IDs reserved for driver specific controls */
+#define V4L2_CID_PRIVATE_BASE 0x08000000
+
+
+/*
+ * T U N I N G
+ */
+struct v4l2_tuner {
+ u_int32_t index;
+ u_int8_t name[32];
+ u_int32_t type; /* enum v4l2_tuner_type */
+ u_int32_t capability;
+ u_int32_t rangelow;
+ u_int32_t rangehigh;
+ u_int32_t rxsubchans;
+ u_int32_t audmode;
+ int32_t signal;
+ int32_t afc;
+ u_int32_t reserved[4];
+};
+
+struct v4l2_modulator {
+ u_int32_t index;
+ u_int8_t name[32];
+ u_int32_t capability;
+ u_int32_t rangelow;
+ u_int32_t rangehigh;
+ u_int32_t txsubchans;
+ u_int32_t type; /* enum v4l2_tuner_type */
+ u_int32_t reserved[3];
+};
+
+/* Flags for the 'capability' field */
+#define V4L2_TUNER_CAP_LOW 0x0001
+#define V4L2_TUNER_CAP_NORM 0x0002
+#define V4L2_TUNER_CAP_HWSEEK_BOUNDED 0x0004
+#define V4L2_TUNER_CAP_HWSEEK_WRAP 0x0008
+#define V4L2_TUNER_CAP_STEREO 0x0010
+#define V4L2_TUNER_CAP_LANG2 0x0020
+#define V4L2_TUNER_CAP_SAP 0x0020
+#define V4L2_TUNER_CAP_LANG1 0x0040
+#define V4L2_TUNER_CAP_RDS 0x0080
+#define V4L2_TUNER_CAP_RDS_BLOCK_IO 0x0100
+#define V4L2_TUNER_CAP_RDS_CONTROLS 0x0200
+#define V4L2_TUNER_CAP_FREQ_BANDS 0x0400
+#define V4L2_TUNER_CAP_HWSEEK_PROG_LIM 0x0800
+#define V4L2_TUNER_CAP_1HZ 0x1000
+
+/* Flags for the 'rxsubchans' field */
+#define V4L2_TUNER_SUB_MONO 0x0001
+#define V4L2_TUNER_SUB_STEREO 0x0002
+#define V4L2_TUNER_SUB_LANG2 0x0004
+#define V4L2_TUNER_SUB_SAP 0x0004
+#define V4L2_TUNER_SUB_LANG1 0x0008
+#define V4L2_TUNER_SUB_RDS 0x0010
+
+/* Values for the 'audmode' field */
+#define V4L2_TUNER_MODE_MONO 0x0000
+#define V4L2_TUNER_MODE_STEREO 0x0001
+#define V4L2_TUNER_MODE_LANG2 0x0002
+#define V4L2_TUNER_MODE_SAP 0x0002
+#define V4L2_TUNER_MODE_LANG1 0x0003
+#define V4L2_TUNER_MODE_LANG1_LANG2 0x0004
+
+struct v4l2_frequency {
+ u_int32_t tuner;
+ u_int32_t type; /* enum v4l2_tuner_type */
+ u_int32_t frequency;
+ u_int32_t reserved[8];
+};
+
+#define V4L2_BAND_MODULATION_VSB (1 << 1)
+#define V4L2_BAND_MODULATION_FM (1 << 2)
+#define V4L2_BAND_MODULATION_AM (1 << 3)
+
+struct v4l2_frequency_band {
+ u_int32_t tuner;
+ u_int32_t type; /* enum v4l2_tuner_type */
+ u_int32_t index;
+ u_int32_t capability;
+ u_int32_t rangelow;
+ u_int32_t rangehigh;
+ u_int32_t modulation;
+ u_int32_t reserved[9];
+};
+
+struct v4l2_hw_freq_seek {
+ u_int32_t tuner;
+ u_int32_t type; /* enum v4l2_tuner_type */
+ u_int32_t seek_upward;
+ u_int32_t wrap_around;
+ u_int32_t spacing;
+ u_int32_t rangelow;
+ u_int32_t rangehigh;
+ u_int32_t reserved[5];
+};
+
+/*
+ * R D S
+ */
+
+struct v4l2_rds_data {
+ u_int8_t lsb;
+ u_int8_t msb;
+ u_int8_t block;
+} __attribute__ ((packed));
+
+#define V4L2_RDS_BLOCK_MSK 0x7
+#define V4L2_RDS_BLOCK_A 0
+#define V4L2_RDS_BLOCK_B 1
+#define V4L2_RDS_BLOCK_C 2
+#define V4L2_RDS_BLOCK_D 3
+#define V4L2_RDS_BLOCK_C_ALT 4
+#define V4L2_RDS_BLOCK_INVALID 7
+
+#define V4L2_RDS_BLOCK_CORRECTED 0x40
+#define V4L2_RDS_BLOCK_ERROR 0x80
+
+/*
+ * A U D I O
+ */
+struct v4l2_audio {
+ u_int32_t index;
+ u_int8_t name[32];
+ u_int32_t capability;
+ u_int32_t mode;
+ u_int32_t reserved[2];
+};
+
+/* Flags for the 'capability' field */
+#define V4L2_AUDCAP_STEREO 0x00001
+#define V4L2_AUDCAP_AVL 0x00002
+
+/* Flags for the 'mode' field */
+#define V4L2_AUDMODE_AVL 0x00001
+
+struct v4l2_audioout {
+ u_int32_t index;
+ u_int8_t name[32];
+ u_int32_t capability;
+ u_int32_t mode;
+ u_int32_t reserved[2];
+};
+
+/*
+ * M P E G S E R V I C E S
+ */
+#if 1
+#define V4L2_ENC_IDX_FRAME_I (0)
+#define V4L2_ENC_IDX_FRAME_P (1)
+#define V4L2_ENC_IDX_FRAME_B (2)
+#define V4L2_ENC_IDX_FRAME_MASK (0xf)
+
+struct v4l2_enc_idx_entry {
+ u_int64_t offset;
+ u_int64_t pts;
+ u_int32_t length;
+ u_int32_t flags;
+ u_int32_t reserved[2];
+};
+
+#define V4L2_ENC_IDX_ENTRIES (64)
+struct v4l2_enc_idx {
+ u_int32_t entries;
+ u_int32_t entries_cap;
+ u_int32_t reserved[4];
+ struct v4l2_enc_idx_entry entry[V4L2_ENC_IDX_ENTRIES];
+};
+
+
+#define V4L2_ENC_CMD_START (0)
+#define V4L2_ENC_CMD_STOP (1)
+#define V4L2_ENC_CMD_PAUSE (2)
+#define V4L2_ENC_CMD_RESUME (3)
+
+/* Flags for V4L2_ENC_CMD_STOP */
+#define V4L2_ENC_CMD_STOP_AT_GOP_END (1 << 0)
+
+struct v4l2_encoder_cmd {
+ u_int32_t cmd;
+ u_int32_t flags;
+ union {
+ struct {
+ u_int32_t data[8];
+ } raw;
+ };
+};
+
+/* Decoder commands */
+#define V4L2_DEC_CMD_START (0)
+#define V4L2_DEC_CMD_STOP (1)
+#define V4L2_DEC_CMD_PAUSE (2)
+#define V4L2_DEC_CMD_RESUME (3)
+
+/* Flags for V4L2_DEC_CMD_START */
+#define V4L2_DEC_CMD_START_MUTE_AUDIO (1 << 0)
+
+/* Flags for V4L2_DEC_CMD_PAUSE */
+#define V4L2_DEC_CMD_PAUSE_TO_BLACK (1 << 0)
+
+/* Flags for V4L2_DEC_CMD_STOP */
+#define V4L2_DEC_CMD_STOP_TO_BLACK (1 << 0)
+#define V4L2_DEC_CMD_STOP_IMMEDIATELY (1 << 1)
+
+/* Play format requirements (returned by the driver): */
+
+/* The decoder has no special format requirements */
+#define V4L2_DEC_START_FMT_NONE (0)
+/* The decoder requires full GOPs */
+#define V4L2_DEC_START_FMT_GOP (1)
+
+/* The structure must be zeroed before use by the application
+ This ensures it can be extended safely in the future. */
+struct v4l2_decoder_cmd {
+ u_int32_t cmd;
+ u_int32_t flags;
+ union {
+ struct {
+ u_int64_t pts;
+ } stop;
+
+ struct {
+ /* 0 or 1000 specifies normal speed,
+ 1 specifies forward single stepping,
+ -1 specifies backward single stepping,
+ >1: playback at speed/1000 of the normal speed,
+ <-1: reverse playback at (-speed/1000) of the normal speed. */
+ int32_t speed;
+ u_int32_t format;
+ } start;
+
+ struct {
+ u_int32_t data[16];
+ } raw;
+ };
+};
+#endif
+
+
+/*
+ * D A T A S E R V I C E S ( V B I )
+ *
+ * Data services API by Michael Schimek
+ */
+
+/* Raw VBI */
+struct v4l2_vbi_format {
+ u_int32_t sampling_rate; /* in 1 Hz */
+ u_int32_t offset;
+ u_int32_t samples_per_line;
+ u_int32_t sample_format; /* V4L2_PIX_FMT_* */
+ int32_t start[2];
+ u_int32_t count[2];
+ u_int32_t flags; /* V4L2_VBI_* */
+ u_int32_t reserved[2]; /* must be zero */
+};
+
+/* VBI flags */
+#define V4L2_VBI_UNSYNC (1 << 0)
+#define V4L2_VBI_INTERLACED (1 << 1)
+
+/* ITU-R start lines for each field */
+#define V4L2_VBI_ITU_525_F1_START (1)
+#define V4L2_VBI_ITU_525_F2_START (264)
+#define V4L2_VBI_ITU_625_F1_START (1)
+#define V4L2_VBI_ITU_625_F2_START (314)
+
+/* Sliced VBI
+ *
+ * This implements is a proposal V4L2 API to allow SLICED VBI
+ * required for some hardware encoders. It should change without
+ * notice in the definitive implementation.
+ */
+
+struct v4l2_sliced_vbi_format {
+ u_int16_t service_set;
+ /* service_lines[0][...] specifies lines 0-23 (1-23 used) of the first field
+ service_lines[1][...] specifies lines 0-23 (1-23 used) of the second field
+ (equals frame lines 313-336 for 625 line video
+ standards, 263-286 for 525 line standards) */
+ u_int16_t service_lines[2][24];
+ u_int32_t io_size;
+ u_int32_t reserved[2]; /* must be zero */
+};
+
+/* Teletext World System Teletext
+ (WST), defined on ITU-R BT.653-2 */
+#define V4L2_SLICED_TELETEXT_B (0x0001)
+/* Video Program System, defined on ETS 300 231*/
+#define V4L2_SLICED_VPS (0x0400)
+/* Closed Caption, defined on EIA-608 */
+#define V4L2_SLICED_CAPTION_525 (0x1000)
+/* Wide Screen System, defined on ITU-R BT1119.1 */
+#define V4L2_SLICED_WSS_625 (0x4000)
+
+#define V4L2_SLICED_VBI_525 (V4L2_SLICED_CAPTION_525)
+#define V4L2_SLICED_VBI_625 (V4L2_SLICED_TELETEXT_B | V4L2_SLICED_VPS | V4L2_SLICED_WSS_625)
+
+struct v4l2_sliced_vbi_cap {
+ u_int16_t service_set;
+ /* service_lines[0][...] specifies lines 0-23 (1-23 used) of the first field
+ service_lines[1][...] specifies lines 0-23 (1-23 used) of the second field
+ (equals frame lines 313-336 for 625 line video
+ standards, 263-286 for 525 line standards) */
+ u_int16_t service_lines[2][24];
+ u_int32_t type; /* enum v4l2_buf_type */
+ u_int32_t reserved[3]; /* must be 0 */
+};
+
+struct v4l2_sliced_vbi_data {
+ u_int32_t id;
+ u_int32_t field; /* 0: first field, 1: second field */
+ u_int32_t line; /* 1-23 */
+ u_int32_t reserved; /* must be 0 */
+ u_int8_t data[48];
+};
+
+/*
+ * Sliced VBI data inserted into MPEG Streams
+ */
+
+/*
+ * V4L2_MPEG_STREAM_VBI_FMT_IVTV:
+ *
+ * Structure of payload contained in an MPEG 2 Private Stream 1 PES Packet in an
+ * MPEG-2 Program Pack that contains V4L2_MPEG_STREAM_VBI_FMT_IVTV Sliced VBI
+ * data
+ *
+ * Note, the MPEG-2 Program Pack and Private Stream 1 PES packet header
+ * definitions are not included here. See the MPEG-2 specifications for details
+ * on these headers.
+ */
+
+/* Line type IDs */
+#define V4L2_MPEG_VBI_IVTV_TELETEXT_B (1)
+#define V4L2_MPEG_VBI_IVTV_CAPTION_525 (4)
+#define V4L2_MPEG_VBI_IVTV_WSS_625 (5)
+#define V4L2_MPEG_VBI_IVTV_VPS (7)
+
+struct v4l2_mpeg_vbi_itv0_line {
+ u_int8_t id; /* One of V4L2_MPEG_VBI_IVTV_* above */
+ u_int8_t data[42]; /* Sliced VBI data for the line */
+} __attribute__ ((packed));
+
+struct v4l2_mpeg_vbi_itv0 {
+ u_int32_t linemask[2]; /* Bitmasks of VBI service lines present */
+ struct v4l2_mpeg_vbi_itv0_line line[35];
+} __attribute__ ((packed));
+
+struct v4l2_mpeg_vbi_ITV0 {
+ struct v4l2_mpeg_vbi_itv0_line line[36];
+} __attribute__ ((packed));
+
+#define V4L2_MPEG_VBI_IVTV_MAGIC0 "itv0"
+#define V4L2_MPEG_VBI_IVTV_MAGIC1 "ITV0"
+
+struct v4l2_mpeg_vbi_fmt_ivtv {
+ u_int8_t magic[4];
+ union {
+ struct v4l2_mpeg_vbi_itv0 itv0;
+ struct v4l2_mpeg_vbi_ITV0 ITV0;
+ };
+} __attribute__ ((packed));
+
+/*
+ * A G G R E G A T E S T R U C T U R E S
+ */
+
+/**
+ * struct v4l2_plane_pix_format - additional, per-plane format definition
+ * @sizeimage: maximum size in bytes required for data, for which
+ * this plane will be used
+ * @bytesperline: distance in bytes between the leftmost pixels in two
+ * adjacent lines
+ */
+struct v4l2_plane_pix_format {
+ u_int32_t sizeimage;
+ u_int32_t bytesperline;
+ u_int16_t reserved[6];
+} __attribute__ ((packed));
+
+/**
+ * struct v4l2_pix_format_mplane - multiplanar format definition
+ * @width: image width in pixels
+ * @height: image height in pixels
+ * @pixelformat: little endian four character code (fourcc)
+ * @field: enum v4l2_field; field order (for interlaced video)
+ * @colorspace: enum v4l2_colorspace; supplemental to pixelformat
+ * @plane_fmt: per-plane information
+ * @num_planes: number of planes for this format
+ * @flags: format flags (V4L2_PIX_FMT_FLAG_*)
+ * @ycbcr_enc: enum v4l2_ycbcr_encoding, Y'CbCr encoding
+ * @quantization: enum v4l2_quantization, colorspace quantization
+ * @xfer_func: enum v4l2_xfer_func, colorspace transfer function
+ */
+struct v4l2_pix_format_mplane {
+ u_int32_t width;
+ u_int32_t height;
+ u_int32_t pixelformat;
+ u_int32_t field;
+ u_int32_t colorspace;
+
+ struct v4l2_plane_pix_format plane_fmt[VIDEO_MAX_PLANES];
+ u_int8_t num_planes;
+ u_int8_t flags;
+ union {
+ u_int8_t ycbcr_enc;
+ u_int8_t hsv_enc;
+ };
+ u_int8_t quantization;
+ u_int8_t xfer_func;
+ u_int8_t reserved[7];
+} __attribute__ ((packed));
+
+/**
+ * struct v4l2_sdr_format - SDR format definition
+ * @pixelformat: little endian four character code (fourcc)
+ * @buffersize: maximum size in bytes required for data
+ */
+struct v4l2_sdr_format {
+ u_int32_t pixelformat;
+ u_int32_t buffersize;
+ u_int8_t reserved[24];
+} __attribute__ ((packed));
+
+/**
+ * struct v4l2_format - stream data format
+ * @type: enum v4l2_buf_type; type of the data stream
+ * @pix: definition of an image format
+ * @pix_mp: definition of a multiplanar image format
+ * @win: definition of an overlaid image
+ * @vbi: raw VBI capture or output parameters
+ * @sliced: sliced VBI capture or output parameters
+ * @raw_data: placeholder for future extensions and custom formats
+ */
+struct v4l2_format {
+ u_int32_t type;
+ union {
+ struct v4l2_pix_format pix; /* V4L2_BUF_TYPE_VIDEO_CAPTURE */
+ struct v4l2_pix_format_mplane pix_mp; /* V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE */
+ struct v4l2_window win; /* V4L2_BUF_TYPE_VIDEO_OVERLAY */
+ struct v4l2_vbi_format vbi; /* V4L2_BUF_TYPE_VBI_CAPTURE */
+ struct v4l2_sliced_vbi_format sliced; /* V4L2_BUF_TYPE_SLICED_VBI_CAPTURE */
+ struct v4l2_sdr_format sdr; /* V4L2_BUF_TYPE_SDR_CAPTURE */
+ u_int8_t raw_data[200]; /* user-defined */
+ } fmt;
+};
+
+/* Stream type-dependent parameters
+ */
+struct v4l2_streamparm {
+ u_int32_t type; /* enum v4l2_buf_type */
+ union {
+ struct v4l2_captureparm capture;
+ struct v4l2_outputparm output;
+ u_int8_t raw_data[200]; /* user-defined */
+ } parm;
+};
+
+/*
+ * E V E N T S
+ */
+
+#define V4L2_EVENT_ALL 0
+#define V4L2_EVENT_VSYNC 1
+#define V4L2_EVENT_EOS 2
+#define V4L2_EVENT_CTRL 3
+#define V4L2_EVENT_FRAME_SYNC 4
+#define V4L2_EVENT_SOURCE_CHANGE 5
+#define V4L2_EVENT_MOTION_DET 6
+#define V4L2_EVENT_PRIVATE_START 0x08000000
+
+/* Payload for V4L2_EVENT_VSYNC */
+struct v4l2_event_vsync {
+ /* Can be V4L2_FIELD_ANY, _NONE, _TOP or _BOTTOM */
+ u_int8_t field;
+} __attribute__ ((packed));
+
+/* Payload for V4L2_EVENT_CTRL */
+#define V4L2_EVENT_CTRL_CH_VALUE (1 << 0)
+#define V4L2_EVENT_CTRL_CH_FLAGS (1 << 1)
+#define V4L2_EVENT_CTRL_CH_RANGE (1 << 2)
+
+struct v4l2_event_ctrl {
+ u_int32_t changes;
+ u_int32_t type;
+ union {
+ int32_t value;
+ int64_t value64;
+ };
+ u_int32_t flags;
+ int32_t minimum;
+ int32_t maximum;
+ int32_t step;
+ int32_t default_value;
+};
+
+struct v4l2_event_frame_sync {
+ u_int32_t frame_sequence;
+};
+
+#define V4L2_EVENT_SRC_CH_RESOLUTION (1 << 0)
+
+struct v4l2_event_src_change {
+ u_int32_t changes;
+};
+
+#define V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ (1 << 0)
+
+/**
+ * struct v4l2_event_motion_det - motion detection event
+ * @flags: if V4L2_EVENT_MD_FL_HAVE_FRAME_SEQ is set, then the
+ * frame_sequence field is valid.
+ * @frame_sequence: the frame sequence number associated with this event.
+ * @region_mask: which regions detected motion.
+ */
+struct v4l2_event_motion_det {
+ u_int32_t flags;
+ u_int32_t frame_sequence;
+ u_int32_t region_mask;
+};
+
+struct v4l2_event {
+ u_int32_t type;
+ union {
+ struct v4l2_event_vsync vsync;
+ struct v4l2_event_ctrl ctrl;
+ struct v4l2_event_frame_sync frame_sync;
+ struct v4l2_event_src_change src_change;
+ struct v4l2_event_motion_det motion_det;
+ u_int8_t data[64];
+ } u;
+ u_int32_t pending;
+ u_int32_t sequence;
+ struct timespec timestamp;
+ u_int32_t id;
+ u_int32_t reserved[8];
+};
+
+#define V4L2_EVENT_SUB_FL_SEND_INITIAL (1 << 0)
+#define V4L2_EVENT_SUB_FL_ALLOW_FEEDBACK (1 << 1)
+
+struct v4l2_event_subscription {
+ u_int32_t type;
+ u_int32_t id;
+ u_int32_t flags;
+ u_int32_t reserved[5];
+};
+
+/*
+ * A D V A N C E D D E B U G G I N G
+ *
+ * NOTE: EXPERIMENTAL API, NEVER RELY ON THIS IN APPLICATIONS!
+ * FOR DEBUGGING, TESTING AND INTERNAL USE ONLY!
+ */
+
+/* VIDIOC_DBG_G_REGISTER and VIDIOC_DBG_S_REGISTER */
+
+#define V4L2_CHIP_MATCH_BRIDGE 0 /* Match against chip ID on the bridge (0 for the bridge) */
+#define V4L2_CHIP_MATCH_SUBDEV 4 /* Match against subdev index */
+
+/* The following four defines are no longer in use */
+#define V4L2_CHIP_MATCH_HOST V4L2_CHIP_MATCH_BRIDGE
+#define V4L2_CHIP_MATCH_I2C_DRIVER 1 /* Match against I2C driver name */
+#define V4L2_CHIP_MATCH_I2C_ADDR 2 /* Match against I2C 7-bit address */
+#define V4L2_CHIP_MATCH_AC97 3 /* Match against ancillary AC97 chip */
+
+struct v4l2_dbg_match {
+ u_int32_t type; /* Match type */
+ union { /* Match this chip, meaning determined by type */
+ u_int32_t addr;
+ char name[32];
+ };
+} __attribute__ ((packed));
+
+struct v4l2_dbg_register {
+ struct v4l2_dbg_match match;
+ u_int32_t size; /* register size in bytes */
+ u_int64_t reg;
+ u_int64_t val;
+} __attribute__ ((packed));
+
+#define V4L2_CHIP_FL_READABLE (1 << 0)
+#define V4L2_CHIP_FL_WRITABLE (1 << 1)
+
+/* VIDIOC_DBG_G_CHIP_INFO */
+struct v4l2_dbg_chip_info {
+ struct v4l2_dbg_match match;
+ char name[32];
+ u_int32_t flags;
+ u_int32_t reserved[32];
+} __attribute__ ((packed));
+
+/**
+ * struct v4l2_create_buffers - VIDIOC_CREATE_BUFS argument
+ * @index: on return, index of the first created buffer
+ * @count: entry: number of requested buffers,
+ * return: number of created buffers
+ * @memory: enum v4l2_memory; buffer memory type
+ * @format: frame format, for which buffers are requested
+ * @reserved: future extensions
+ */
+struct v4l2_create_buffers {
+ u_int32_t index;
+ u_int32_t count;
+ u_int32_t memory;
+ struct v4l2_format format;
+ u_int32_t reserved[8];
+};
+
+/*
+ * I O C T L C O D E S F O R V I D E O D E V I C E S
+ *
+ */
+#define VIDIOC_QUERYCAP _IOR('V', 0, struct v4l2_capability)
+#define VIDIOC_RESERVED _IO('V', 1)
+#define VIDIOC_ENUM_FMT _IOWR('V', 2, struct v4l2_fmtdesc)
+#define VIDIOC_G_FMT _IOWR('V', 4, struct v4l2_format)
+#define VIDIOC_S_FMT _IOWR('V', 5, struct v4l2_format)
+#define VIDIOC_REQBUFS _IOWR('V', 8, struct v4l2_requestbuffers)
+#define VIDIOC_QUERYBUF _IOWR('V', 9, struct v4l2_buffer)
+#define VIDIOC_G_FBUF _IOR('V', 10, struct v4l2_framebuffer)
+#define VIDIOC_S_FBUF _IOW('V', 11, struct v4l2_framebuffer)
+#define VIDIOC_OVERLAY _IOW('V', 14, int)
+#define VIDIOC_QBUF _IOWR('V', 15, struct v4l2_buffer)
+#define VIDIOC_EXPBUF _IOWR('V', 16, struct v4l2_exportbuffer)
+#define VIDIOC_DQBUF _IOWR('V', 17, struct v4l2_buffer)
+#define VIDIOC_STREAMON _IOW('V', 18, int)
+#define VIDIOC_STREAMOFF _IOW('V', 19, int)
+#define VIDIOC_G_PARM _IOWR('V', 21, struct v4l2_streamparm)
+#define VIDIOC_S_PARM _IOWR('V', 22, struct v4l2_streamparm)
+#define VIDIOC_G_STD _IOR('V', 23, v4l2_std_id)
+#define VIDIOC_S_STD _IOW('V', 24, v4l2_std_id)
+#define VIDIOC_ENUMSTD _IOWR('V', 25, struct v4l2_standard)
+#define VIDIOC_ENUMINPUT _IOWR('V', 26, struct v4l2_input)
+#define VIDIOC_G_CTRL _IOWR('V', 27, struct v4l2_control)
+#define VIDIOC_S_CTRL _IOWR('V', 28, struct v4l2_control)
+#define VIDIOC_G_TUNER _IOWR('V', 29, struct v4l2_tuner)
+#define VIDIOC_S_TUNER _IOW('V', 30, struct v4l2_tuner)
+#define VIDIOC_G_AUDIO _IOR('V', 33, struct v4l2_audio)
+#define VIDIOC_S_AUDIO _IOW('V', 34, struct v4l2_audio)
+#define VIDIOC_QUERYCTRL _IOWR('V', 36, struct v4l2_queryctrl)
+#define VIDIOC_QUERYMENU _IOWR('V', 37, struct v4l2_querymenu)
+#define VIDIOC_G_INPUT _IOR('V', 38, int)
+#define VIDIOC_S_INPUT _IOWR('V', 39, int)
+#define VIDIOC_G_EDID _IOWR('V', 40, struct v4l2_edid)
+#define VIDIOC_S_EDID _IOWR('V', 41, struct v4l2_edid)
+#define VIDIOC_G_OUTPUT _IOR('V', 46, int)
+#define VIDIOC_S_OUTPUT _IOWR('V', 47, int)
+#define VIDIOC_ENUMOUTPUT _IOWR('V', 48, struct v4l2_output)
+#define VIDIOC_G_AUDOUT _IOR('V', 49, struct v4l2_audioout)
+#define VIDIOC_S_AUDOUT _IOW('V', 50, struct v4l2_audioout)
+#define VIDIOC_G_MODULATOR _IOWR('V', 54, struct v4l2_modulator)
+#define VIDIOC_S_MODULATOR _IOW('V', 55, struct v4l2_modulator)
+#define VIDIOC_G_FREQUENCY _IOWR('V', 56, struct v4l2_frequency)
+#define VIDIOC_S_FREQUENCY _IOW('V', 57, struct v4l2_frequency)
+#define VIDIOC_CROPCAP _IOWR('V', 58, struct v4l2_cropcap)
+#define VIDIOC_G_CROP _IOWR('V', 59, struct v4l2_crop)
+#define VIDIOC_S_CROP _IOW('V', 60, struct v4l2_crop)
+#define VIDIOC_G_JPEGCOMP _IOR('V', 61, struct v4l2_jpegcompression)
+#define VIDIOC_S_JPEGCOMP _IOW('V', 62, struct v4l2_jpegcompression)
+#define VIDIOC_QUERYSTD _IOR('V', 63, v4l2_std_id)
+#define VIDIOC_TRY_FMT _IOWR('V', 64, struct v4l2_format)
+#define VIDIOC_ENUMAUDIO _IOWR('V', 65, struct v4l2_audio)
+#define VIDIOC_ENUMAUDOUT _IOWR('V', 66, struct v4l2_audioout)
+#define VIDIOC_G_PRIORITY _IOR('V', 67, u_int32_t) /* enum v4l2_priority */
+#define VIDIOC_S_PRIORITY _IOW('V', 68, u_int32_t) /* enum v4l2_priority */
+#define VIDIOC_G_SLICED_VBI_CAP _IOWR('V', 69, struct v4l2_sliced_vbi_cap)
+#define VIDIOC_LOG_STATUS _IO('V', 70)
+#define VIDIOC_G_EXT_CTRLS _IOWR('V', 71, struct v4l2_ext_controls)
+#define VIDIOC_S_EXT_CTRLS _IOWR('V', 72, struct v4l2_ext_controls)
+#define VIDIOC_TRY_EXT_CTRLS _IOWR('V', 73, struct v4l2_ext_controls)
+#define VIDIOC_ENUM_FRAMESIZES _IOWR('V', 74, struct v4l2_frmsizeenum)
+#define VIDIOC_ENUM_FRAMEINTERVALS _IOWR('V', 75, struct v4l2_frmivalenum)
+#define VIDIOC_G_ENC_INDEX _IOR('V', 76, struct v4l2_enc_idx)
+#define VIDIOC_ENCODER_CMD _IOWR('V', 77, struct v4l2_encoder_cmd)
+#define VIDIOC_TRY_ENCODER_CMD _IOWR('V', 78, struct v4l2_encoder_cmd)
+
+/*
+ * Experimental, meant for debugging, testing and internal use.
+ * Only implemented if CONFIG_VIDEO_ADV_DEBUG is defined.
+ * You must be root to use these ioctls. Never use these in applications!
+ */
+#define VIDIOC_DBG_S_REGISTER _IOW('V', 79, struct v4l2_dbg_register)
+#define VIDIOC_DBG_G_REGISTER _IOWR('V', 80, struct v4l2_dbg_register)
+
+#define VIDIOC_S_HW_FREQ_SEEK _IOW('V', 82, struct v4l2_hw_freq_seek)
+#define VIDIOC_S_DV_TIMINGS _IOWR('V', 87, struct v4l2_dv_timings)
+#define VIDIOC_G_DV_TIMINGS _IOWR('V', 88, struct v4l2_dv_timings)
+#define VIDIOC_DQEVENT _IOR('V', 89, struct v4l2_event)
+#define VIDIOC_SUBSCRIBE_EVENT _IOW('V', 90, struct v4l2_event_subscription)
+#define VIDIOC_UNSUBSCRIBE_EVENT _IOW('V', 91, struct v4l2_event_subscription)
+#define VIDIOC_CREATE_BUFS _IOWR('V', 92, struct v4l2_create_buffers)
+#define VIDIOC_PREPARE_BUF _IOWR('V', 93, struct v4l2_buffer)
+#define VIDIOC_G_SELECTION _IOWR('V', 94, struct v4l2_selection)
+#define VIDIOC_S_SELECTION _IOWR('V', 95, struct v4l2_selection)
+#define VIDIOC_DECODER_CMD _IOWR('V', 96, struct v4l2_decoder_cmd)
+#define VIDIOC_TRY_DECODER_CMD _IOWR('V', 97, struct v4l2_decoder_cmd)
+#define VIDIOC_ENUM_DV_TIMINGS _IOWR('V', 98, struct v4l2_enum_dv_timings)
+#define VIDIOC_QUERY_DV_TIMINGS _IOR('V', 99, struct v4l2_dv_timings)
+#define VIDIOC_DV_TIMINGS_CAP _IOWR('V', 100, struct v4l2_dv_timings_cap)
+#define VIDIOC_ENUM_FREQ_BANDS _IOWR('V', 101, struct v4l2_frequency_band)
+
+/*
+ * Experimental, meant for debugging, testing and internal use.
+ * Never use this in applications!
+ */
+#define VIDIOC_DBG_G_CHIP_INFO _IOWR('V', 102, struct v4l2_dbg_chip_info)
+
+#define VIDIOC_QUERY_EXT_CTRL _IOWR('V', 103, struct v4l2_query_ext_ctrl)
+
+/* Reminder: when adding new ioctls please add support for them to
+ drivers/media/v4l2-core/v4l2-compat-ioctl32.c as well! */
+
+#define BASE_VIDIOC_PRIVATE 192 /* 192-255 are private */
+
+#endif /* _SYS_VIDEOIO_H */
diff --git a/sys/sys/vmmeter.h b/sys/sys/vmmeter.h
new file mode 100644
index 0000000..2da0836
--- /dev/null
+++ b/sys/sys/vmmeter.h
@@ -0,0 +1,97 @@
+/* $OpenBSD: vmmeter.h,v 1.15 2016/07/27 14:44:59 tedu Exp $ */
+/* $NetBSD: vmmeter.h,v 1.9 1995/03/26 20:25:04 jtc 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.
+ * 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.
+ *
+ * @(#)vmmeter.h 8.2 (Berkeley) 7/10/94
+ */
+
+#ifndef __VMMETER_H__
+#define __VMMETER_H__
+
+/*
+ * System wide statistics counters. Look in <uvm/uvm_extern.h> for the
+ * UVM equivalent.
+ */
+
+/* systemwide totals computed every five seconds */
+struct vmtotal {
+ u_int16_t t_rq; /* length of the run queue */
+ u_int16_t t_dw; /* jobs in ``disk wait'' (neg priority) */
+ u_int16_t t_pw; /* jobs in page wait */
+ u_int16_t t_sl; /* jobs sleeping in core */
+ u_int16_t t_sw; /* swapped out runnable/short block jobs */
+ u_int32_t t_vm; /* total virtual memory */
+ u_int32_t t_avm; /* active virtual memory */
+ u_int32_t t_rm; /* total real memory in use */
+ u_int32_t t_arm; /* active real memory */
+ u_int32_t t_vmshr; /* shared virtual memory */
+ u_int32_t t_avmshr; /* active shared virtual memory */
+ u_int32_t t_rmshr; /* shared real memory */
+ u_int32_t t_armshr; /* active shared real memory */
+ u_int32_t t_free; /* free memory pages */
+};
+
+/*
+ * Fork/vfork/__tfork accounting.
+ */
+struct forkstat {
+ uint32_t cntfork; /* number of fork() calls */
+ uint32_t cntvfork; /* number of vfork() calls */
+ uint32_t cnttfork; /* number of __tfork() calls */
+ uint32_t cntkthread; /* number of kernel threads created */
+ uint64_t sizfork; /* VM pages affected by fork() */
+ uint64_t sizvfork; /* VM pages affected by vfork() */
+ uint64_t siztfork; /* VM pages affected by __tfork() */
+ uint64_t sizkthread; /* VM pages affected by kernel threads */
+};
+
+/* These sysctl names are only really used by sysctl(8) */
+#define KERN_FORKSTAT_FORK 1
+#define KERN_FORKSTAT_VFORK 2
+#define KERN_FORKSTAT_TFORK 3
+#define KERN_FORKSTAT_KTHREAD 4
+#define KERN_FORKSTAT_SIZFORK 5
+#define KERN_FORKSTAT_SIZVFORK 6
+#define KERN_FORKSTAT_SIZTFORK 7
+#define KERN_FORKSTAT_SIZKTHREAD 8
+#define KERN_FORKSTAT_MAXID 9
+
+#define CTL_KERN_FORKSTAT_NAMES { \
+ { 0, 0 }, \
+ { "forks", CTLTYPE_INT }, \
+ { "vforks", CTLTYPE_INT }, \
+ { "tforks", CTLTYPE_INT }, \
+ { "kthreads", CTLTYPE_INT }, \
+ { "fork_pages", CTLTYPE_INT }, \
+ { "vfork_pages", CTLTYPE_INT }, \
+ { "tfork_pages", CTLTYPE_INT }, \
+ { "kthread_pages", CTLTYPE_INT }, \
+}
+#endif /* __VMMETER_H__ */
diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h
new file mode 100644
index 0000000..0899340
--- /dev/null
+++ b/sys/sys/vnode.h
@@ -0,0 +1,665 @@
+/* $OpenBSD: vnode.h,v 1.156 2020/04/08 08:07:52 mpi Exp $ */
+/* $NetBSD: vnode.h,v 1.38 1996/02/29 20:59:05 cgd Exp $ */
+
+/*
+ * 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.
+ * 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.
+ *
+ * @(#)vnode.h 8.11 (Berkeley) 11/21/94
+ */
+
+#ifndef _SYS_VNODE_H_
+#define _SYS_VNODE_H_
+
+#include <sys/buf.h>
+#include <sys/types.h>
+#include <sys/queue.h>
+#include <sys/selinfo.h>
+#include <sys/tree.h>
+
+/*
+ * The vnode is the focus of all file activity in UNIX. There is a
+ * unique vnode allocated for each active file, each current directory,
+ * each mounted-on file, text file, and the root.
+ */
+
+/*
+ * Vnode types. VNON means no type.
+ */
+enum vtype { VNON, VREG, VDIR, VBLK, VCHR, VLNK, VSOCK, VFIFO, VBAD };
+
+#define VTYPE_NAMES \
+ "VNON", "VREG", "VDIR", "VBLK", "VCHR", "VLNK", "VSOCK", "VFIFO", "VBAD"
+
+/*
+ * Vnode tag types.
+ * These are for the benefit of external programs only (e.g., pstat)
+ * and should NEVER be inspected by the kernel.
+ *
+ * Note that v_tag is actually used to tell MFS from FFS, and EXT2FS from
+ * the rest, so don't believe the above comment!
+ */
+enum vtagtype {
+ VT_NON, VT_UFS, VT_NFS, VT_MFS, VT_MSDOSFS,
+ VT_PORTAL, VT_PROCFS, VT_AFS, VT_ISOFS, VT_ADOSFS,
+ VT_EXT2FS, VT_VFS, VT_NTFS, VT_UDF, VT_FUSEFS, VT_TMPFS,
+};
+
+#define VTAG_NAMES \
+ "NON", "UFS", "NFS", "MFS", "MSDOSFS", \
+ "unused", "unused", "unused", "ISOFS", "unused", \
+ "EXT2FS", "VFS", "NTFS", "UDF", "FUSEFS", "TMPFS"
+
+/*
+ * Each underlying filesystem allocates its own private area and hangs
+ * it from v_data. If non-null, this area is freed in getnewvnode().
+ */
+LIST_HEAD(buflists, buf);
+
+RBT_HEAD(buf_rb_bufs, buf);
+
+struct namecache;
+RBT_HEAD(namecache_rb_cache, namecache);
+
+struct uvm_vnode;
+struct vnode {
+ struct uvm_vnode *v_uvm; /* uvm data */
+ const struct vops *v_op; /* vnode operations vector */
+ enum vtype v_type; /* vnode type */
+ enum vtagtype v_tag; /* type of underlying data */
+ u_int v_flag; /* vnode flags (see below) */
+ u_int v_usecount; /* reference count of users */
+ u_int v_uvcount; /* unveil references */
+ /* reference count of writers */
+ u_int v_writecount;
+ u_int v_lockcount; /* # threads waiting on lock */
+ /* Flags that can be read/written in interrupts */
+ u_int v_bioflag;
+ u_int v_holdcnt; /* buffer references */
+ u_int v_id; /* capability identifier */
+ u_int v_inflight;
+ struct mount *v_mount; /* ptr to vfs we are in */
+ TAILQ_ENTRY(vnode) v_freelist; /* vnode freelist */
+ TAILQ_ENTRY(vnode) v_mntvnodes; /* vnodes for mount point */
+ struct buf_rb_bufs v_bufs_tree; /* lookup of all bufs */
+ struct buflists v_cleanblkhd; /* clean blocklist head */
+ struct buflists v_dirtyblkhd; /* dirty blocklist head */
+ u_int v_numoutput; /* num of writes in progress */
+ LIST_ENTRY(vnode) v_synclist; /* vnode with dirty buffers */
+ union {
+ struct mount *vu_mountedhere;/* ptr to mounted vfs (VDIR) */
+ struct socket *vu_socket; /* unix ipc (VSOCK) */
+ struct specinfo *vu_specinfo; /* device (VCHR, VBLK) */
+ struct fifoinfo *vu_fifoinfo; /* fifo (VFIFO) */
+ } v_un;
+
+ /* VFS namecache */
+ struct namecache_rb_cache v_nc_tree;
+ TAILQ_HEAD(, namecache) v_cache_dst; /* cache entries to us */
+
+ void *v_data; /* private data for fs */
+ struct selinfo v_selectinfo; /* identity of poller(s) */
+};
+#define v_mountedhere v_un.vu_mountedhere
+#define v_socket v_un.vu_socket
+#define v_specinfo v_un.vu_specinfo
+#define v_fifoinfo v_un.vu_fifoinfo
+
+/*
+ * Vnode flags.
+ */
+#define VROOT 0x0001 /* root of its file system */
+#define VTEXT 0x0002 /* vnode is a pure text prototype */
+#define VSYSTEM 0x0004 /* vnode being used by kernel */
+#define VISTTY 0x0008 /* vnode represents a tty */
+#define VXLOCK 0x0100 /* vnode is locked to change underlying type */
+#define VXWANT 0x0200 /* process is waiting for vnode */
+#define VCLONED 0x0400 /* vnode was cloned */
+#define VALIASED 0x0800 /* vnode has an alias */
+#define VLARVAL 0x1000 /* vnode data not yet set up by higher level */
+#define VLOCKSWORK 0x4000 /* FS supports locking discipline */
+#define VCLONE 0x8000 /* vnode is a clone */
+
+/*
+ * (v_bioflag) Flags that may be manipulated by interrupt handlers
+ */
+#define VBIOWAIT 0x0001 /* waiting for output to complete */
+#define VBIOONSYNCLIST 0x0002 /* Vnode is on syncer worklist */
+#define VBIOONFREELIST 0x0004 /* Vnode is on a free list */
+#define VBIOERROR 0x0008 /* A write failed */
+
+/*
+ * Vnode attributes. A field value of VNOVAL represents a field whose value
+ * is unavailable (getattr) or which is not to be changed (setattr). For
+ * the timespec fields, only the tv_nsec member needs to be set to VNOVAL:
+ * if tv_nsec != VNOVAL then both tv_sec and tv_nsec are valid.
+ */
+struct vattr {
+ enum vtype va_type; /* vnode type (for create) */
+ mode_t va_mode; /* files access mode and type */
+ nlink_t va_nlink; /* number of references to file */
+ uid_t va_uid; /* owner user id */
+ gid_t va_gid; /* owner group id */
+ long va_fsid; /* file system id (dev for now) */
+ u_quad_t va_fileid; /* file id */
+ u_quad_t va_size; /* file size in bytes */
+ long va_blocksize; /* blocksize preferred for i/o */
+ struct timespec va_atime; /* time of last access */
+ struct timespec va_mtime; /* time of last modification */
+ struct timespec va_ctime; /* time file changed */
+ u_long va_gen; /* generation number of file */
+ u_long va_flags; /* flags defined for file */
+ dev_t va_rdev; /* device the special file represents */
+ u_quad_t va_bytes; /* bytes of disk space held by file */
+ u_quad_t va_filerev; /* file modification number */
+ u_int va_vaflags; /* operations flags, see below */
+ long va_spare; /* remain quad aligned */
+};
+
+/*
+ * Flags for va_vaflags.
+ */
+#define VA_UTIMES_NULL 0x01 /* utimes argument was NULL */
+#define VA_EXCLUSIVE 0x02 /* exclusive create request */
+#define VA_UTIMES_CHANGE 0x04 /* ctime should be updated */
+/*
+ * Flags for ioflag.
+ */
+#define IO_UNIT 0x01 /* do I/O as atomic unit */
+#define IO_APPEND 0x02 /* append write to end */
+#define IO_SYNC 0x04 /* do I/O synchronously */
+#define IO_NODELOCKED 0x08 /* underlying node already locked */
+#define IO_NDELAY 0x10 /* FNDELAY flag set in file table */
+#define IO_NOLIMIT 0x20 /* don't enforce limits on i/o */
+#define IO_NOCACHE 0x40 /* don't cache result of this i/o */
+
+/*
+ * Modes. Some values same as Ixxx entries from inode.h for now.
+ */
+#define VSUID 04000 /* set user id on execution */
+#define VSGID 02000 /* set group id on execution */
+#define VSVTX 01000 /* save swapped text even after use */
+#define VREAD 00400 /* read, write, execute permissions */
+#define VWRITE 00200
+#define VEXEC 00100
+
+/*
+ * Token indicating no attribute value yet assigned.
+ */
+#define VNOVAL (-1)
+
+#ifdef _KERNEL
+RBT_PROTOTYPE(buf_rb_bufs, buf, b_rbbufs, rb_buf_compare);
+/*
+ * Convert between vnode types and inode formats (since POSIX.1
+ * defines mode word of stat structure in terms of inode formats).
+ */
+extern enum vtype iftovt_tab[];
+extern int vttoif_tab[];
+#define IFTOVT(mode) (iftovt_tab[((mode) & S_IFMT) >> 12])
+#define VTTOIF(indx) (vttoif_tab[(int)(indx)])
+#define MAKEIMODE(indx, mode) (int)(VTTOIF(indx) | (mode))
+
+/*
+ * Flags to various vnode functions.
+ */
+#define SKIPSYSTEM 0x0001 /* vflush: skip vnodes marked VSYSTEM */
+#define FORCECLOSE 0x0002 /* vflush: force file closeure */
+#define WRITECLOSE 0x0004 /* vflush: only close writeable files */
+#define DOCLOSE 0x0008 /* vclean: close active files */
+#define IGNORECLEAN 0x0010 /* vflush: ignore clean vnodes */
+#define V_SAVE 0x0001 /* vinvalbuf: sync file first */
+#define V_SAVEMETA 0x0002 /* vinvalbuf: leave indirect blocks */
+
+#define REVOKEALL 0x0001 /* vop_revoke: revoke all aliases */
+
+
+TAILQ_HEAD(freelst, vnode);
+extern struct freelst vnode_hold_list; /* free vnodes referencing buffers */
+extern struct freelst vnode_free_list; /* vnode free list */
+
+#define VATTR_NULL(vap) vattr_null(vap)
+#define NULLVP ((struct vnode *)NULL)
+#define VN_KNOTE(vp, b) \
+ KNOTE(&vp->v_selectinfo.si_note, (b))
+
+/*
+ * Global vnode data.
+ */
+extern struct vnode *rootvnode; /* root (i.e. "/") vnode */
+extern int initialvnodes; /* XXX number of vnodes to start */
+extern int maxvnodes; /* XXX number of vnodes to allocate */
+extern int syncdelay; /* seconds to delay syncing vnodes */
+extern int rushjob; /* # of slots syncer should run ASAP */
+extern void vhold(struct vnode *);
+extern void vdrop(struct vnode *);
+
+/* vnode operations */
+struct vops {
+ int (*vop_lock)(void *);
+ int (*vop_unlock)(void *);
+ int (*vop_islocked)(void *);
+ int (*vop_abortop)(void *);
+ int (*vop_access)(void *);
+ int (*vop_advlock)(void *);
+ int (*vop_bmap)(void *);
+ int (*vop_bwrite)(void *);
+ int (*vop_close)(void *);
+ int (*vop_create)(void *);
+ int (*vop_fsync)(void *);
+ int (*vop_getattr)(void *);
+ int (*vop_inactive)(void *);
+ int (*vop_ioctl)(void *);
+ int (*vop_link)(void *);
+ int (*vop_lookup)(void *);
+ int (*vop_mknod)(void *);
+ int (*vop_open)(void *);
+ int (*vop_pathconf)(void *);
+ int (*vop_poll)(void *);
+ int (*vop_print)(void *);
+ int (*vop_read)(void *);
+ int (*vop_readdir)(void *);
+ int (*vop_readlink)(void *);
+ int (*vop_reclaim)(void *);
+ int (*vop_remove)(void *);
+ int (*vop_rename)(void *);
+ int (*vop_revoke)(void *);
+ int (*vop_mkdir)(void *);
+ int (*vop_rmdir)(void *);
+ int (*vop_setattr)(void *);
+ int (*vop_strategy)(void *);
+ int (*vop_symlink)(void *);
+ int (*vop_write)(void *);
+ int (*vop_kqfilter)(void *);
+};
+
+extern const struct vops dead_vops;
+extern const struct vops spec_vops;
+
+struct vop_generic_args {
+ void *a_garbage;
+ /* Other data probably follows; */
+};
+
+struct vop_islocked_args {
+ struct vnode *a_vp;
+};
+int VOP_ISLOCKED(struct vnode *);
+
+struct vop_lookup_args {
+ struct vnode *a_dvp;
+ struct vnode **a_vpp;
+ struct componentname *a_cnp;
+};
+int VOP_LOOKUP(struct vnode *, struct vnode **, struct componentname *);
+
+struct vop_create_args {
+ struct vnode *a_dvp;
+ struct vnode **a_vpp;
+ struct componentname *a_cnp;
+ struct vattr *a_vap;
+};
+int VOP_CREATE(struct vnode *, struct vnode **, struct componentname *,
+ struct vattr *);
+
+struct vop_mknod_args {
+ struct vnode *a_dvp;
+ struct vnode **a_vpp;
+ struct componentname *a_cnp;
+ struct vattr *a_vap;
+};
+int VOP_MKNOD(struct vnode *, struct vnode **, struct componentname *,
+ struct vattr *);
+
+struct vop_open_args {
+ struct vnode *a_vp;
+ int a_mode;
+ struct ucred *a_cred;
+ struct proc *a_p;
+};
+int VOP_OPEN(struct vnode *, int, struct ucred *, struct proc *);
+
+struct vop_close_args {
+ struct vnode *a_vp;
+ int a_fflag;
+ struct ucred *a_cred;
+ struct proc *a_p;
+};
+int VOP_CLOSE(struct vnode *, int, struct ucred *, struct proc *);
+
+struct vop_access_args {
+ struct vnode *a_vp;
+ int a_mode;
+ struct ucred *a_cred;
+ struct proc *a_p;
+};
+int VOP_ACCESS(struct vnode *, int, struct ucred *, struct proc *);
+
+struct vop_getattr_args {
+ struct vnode *a_vp;
+ struct vattr *a_vap;
+ struct ucred *a_cred;
+ struct proc *a_p;
+};
+int VOP_GETATTR(struct vnode *, struct vattr *, struct ucred *, struct proc *);
+
+struct vop_setattr_args {
+ struct vnode *a_vp;
+ struct vattr *a_vap;
+ struct ucred *a_cred;
+ struct proc *a_p;
+};
+int VOP_SETATTR(struct vnode *, struct vattr *, struct ucred *, struct proc *);
+
+struct vop_read_args {
+ struct vnode *a_vp;
+ struct uio *a_uio;
+ int a_ioflag;
+ struct ucred *a_cred;
+};
+int VOP_READ(struct vnode *, struct uio *, int, struct ucred *);
+
+struct vop_write_args {
+ struct vnode *a_vp;
+ struct uio *a_uio;
+ int a_ioflag;
+ struct ucred *a_cred;
+};
+int VOP_WRITE(struct vnode *, struct uio *, int, struct ucred *);
+
+struct vop_ioctl_args {
+ struct vnode *a_vp;
+ u_long a_command;
+ void *a_data;
+ int a_fflag;
+ struct ucred *a_cred;
+ struct proc *a_p;
+};
+int VOP_IOCTL(struct vnode *, u_long, void *, int, struct ucred *,
+ struct proc *);
+
+struct vop_poll_args {
+ struct vnode *a_vp;
+ int a_fflag;
+ int a_events;
+ struct proc *a_p;
+};
+int VOP_POLL(struct vnode *, int, int, struct proc *);
+
+struct vop_kqfilter_args {
+ struct vnode *a_vp;
+ int a_fflag;
+ struct knote *a_kn;
+};
+int VOP_KQFILTER(struct vnode *, int, struct knote *);
+
+struct vop_revoke_args {
+ struct vnode *a_vp;
+ int a_flags;
+};
+int VOP_REVOKE(struct vnode *, int);
+
+struct vop_fsync_args {
+ struct vnode *a_vp;
+ struct ucred *a_cred;
+ int a_waitfor;
+ struct proc *a_p;
+};
+int VOP_FSYNC(struct vnode *, struct ucred *, int, struct proc *);
+
+struct vop_remove_args {
+ struct vnode *a_dvp;
+ struct vnode *a_vp;
+ struct componentname *a_cnp;
+};
+int VOP_REMOVE(struct vnode *, struct vnode *, struct componentname *);
+
+struct vop_link_args {
+ struct vnode *a_dvp;
+ struct vnode *a_vp;
+ struct componentname *a_cnp;
+};
+int VOP_LINK(struct vnode *, struct vnode *, struct componentname *);
+
+struct vop_rename_args {
+ struct vnode *a_fdvp;
+ struct vnode *a_fvp;
+ struct componentname *a_fcnp;
+ struct vnode *a_tdvp;
+ struct vnode *a_tvp;
+ struct componentname *a_tcnp;
+};
+int VOP_RENAME(struct vnode *, struct vnode *, struct componentname *,
+ struct vnode *, struct vnode *, struct componentname *);
+
+struct vop_mkdir_args {
+ struct vnode *a_dvp;
+ struct vnode **a_vpp;
+ struct componentname *a_cnp;
+ struct vattr *a_vap;
+};
+int VOP_MKDIR(struct vnode *, struct vnode **, struct componentname *,
+ struct vattr *);
+
+struct vop_rmdir_args {
+ struct vnode *a_dvp;
+ struct vnode *a_vp;
+ struct componentname *a_cnp;
+};
+int VOP_RMDIR(struct vnode *, struct vnode *, struct componentname *);
+
+struct vop_symlink_args {
+ struct vnode *a_dvp;
+ struct vnode **a_vpp;
+ struct componentname *a_cnp;
+ struct vattr *a_vap;
+ char *a_target;
+};
+int VOP_SYMLINK(struct vnode *, struct vnode **, struct componentname *,
+ struct vattr *, char *);
+
+struct vop_readdir_args {
+ struct vnode *a_vp;
+ struct uio *a_uio;
+ struct ucred *a_cred;
+ int *a_eofflag;
+};
+int VOP_READDIR(struct vnode *, struct uio *, struct ucred *, int *);
+
+struct vop_readlink_args {
+ struct vnode *a_vp;
+ struct uio *a_uio;
+ struct ucred *a_cred;
+};
+int VOP_READLINK(struct vnode *, struct uio *, struct ucred *);
+
+struct vop_abortop_args {
+ struct vnode *a_dvp;
+ struct componentname *a_cnp;
+};
+int VOP_ABORTOP(struct vnode *, struct componentname *);
+
+struct vop_inactive_args {
+ struct vnode *a_vp;
+ struct proc *a_p;
+};
+int VOP_INACTIVE(struct vnode *, struct proc *);
+
+struct vop_reclaim_args {
+ struct vnode *a_vp;
+ struct proc *a_p;
+};
+int VOP_RECLAIM(struct vnode *, struct proc *);
+
+struct vop_lock_args {
+ struct vnode *a_vp;
+ int a_flags;
+};
+int VOP_LOCK(struct vnode *, int);
+
+struct vop_unlock_args {
+ struct vnode *a_vp;
+};
+int VOP_UNLOCK(struct vnode *);
+
+struct vop_bmap_args {
+ struct vnode *a_vp;
+ daddr_t a_bn;
+ struct vnode **a_vpp;
+ daddr_t *a_bnp;
+ int *a_runp;
+};
+int VOP_BMAP(struct vnode *, daddr_t, struct vnode **, daddr_t *, int *);
+
+struct vop_print_args {
+ struct vnode *a_vp;
+};
+int VOP_PRINT(struct vnode *);
+
+struct vop_pathconf_args {
+ struct vnode *a_vp;
+ int a_name;
+ register_t *a_retval;
+};
+int VOP_PATHCONF(struct vnode *, int, register_t *);
+
+struct vop_advlock_args {
+ struct vnode *a_vp;
+ void *a_id;
+ int a_op;
+ struct flock *a_fl;
+ int a_flags;
+};
+int VOP_ADVLOCK(struct vnode *, void *, int, struct flock *, int);
+
+/* Special cases: */
+struct vop_strategy_args {
+ struct buf *a_bp;
+};
+int VOP_STRATEGY(struct buf *);
+
+struct vop_bwrite_args {
+ struct buf *a_bp;
+};
+int VOP_BWRITE(struct buf *);
+/* End of special cases. */
+
+
+/* Public vnode manipulation functions. */
+struct file;
+struct filedesc;
+struct mount;
+struct nameidata;
+struct proc;
+struct stat;
+struct statfs;
+struct ucred;
+struct uio;
+struct vattr;
+struct vnode;
+
+/* vfs_subr */
+int bdevvp(dev_t, struct vnode **);
+int cdevvp(dev_t, struct vnode **);
+struct vnode *checkalias(struct vnode *, dev_t, struct mount *);
+int getnewvnode(enum vtagtype, struct mount *, const struct vops *,
+ struct vnode **);
+int vaccess(enum vtype, mode_t, uid_t, gid_t, mode_t, struct ucred *);
+int vnoperm(struct vnode *);
+void vattr_null(struct vattr *);
+void vdevgone(int, int, int, enum vtype);
+int vcount(struct vnode *);
+int vfinddev(dev_t, enum vtype, struct vnode **);
+void vflushbuf(struct vnode *, int);
+int vflush(struct mount *, struct vnode *, int);
+int vget(struct vnode *, int);
+void vgone(struct vnode *);
+void vgonel(struct vnode *, struct proc *);
+int vinvalbuf(struct vnode *, int, struct ucred *, struct proc *,
+ int, uint64_t);
+void vntblinit(void);
+int vwaitforio(struct vnode *, int, char *, uint64_t);
+void vwakeup(struct vnode *);
+void vput(struct vnode *);
+int vrecycle(struct vnode *, struct proc *);
+int vrele(struct vnode *);
+void vref(struct vnode *);
+void vprint(char *, struct vnode *);
+void copy_statfs_info(struct statfs *, const struct mount *);
+
+/* vfs_getcwd.c */
+#define GETCWD_CHECK_ACCESS 0x0001
+int vfs_getcwd_scandir(struct vnode **, struct vnode **, char **, char *,
+ struct proc *);
+int vfs_getcwd_common(struct vnode *, struct vnode *, char **, char *, int,
+ int, struct proc *);
+int vfs_getcwd_getcache(struct vnode **, struct vnode **, char **, char *);
+
+/* vfs_default.c */
+int vop_generic_abortop(void *);
+int vop_generic_bmap(void *);
+int vop_generic_bwrite(void *);
+int vop_generic_islocked(void *);
+int vop_generic_lock(void *);
+int vop_generic_unlock(void *);
+int vop_generic_revoke(void *);
+int vop_generic_kqfilter(void *);
+int vop_generic_lookup(void *);
+
+/* vfs_vnops.c */
+int vn_isunder(struct vnode *, struct vnode *, struct proc *);
+int vn_close(struct vnode *, int, struct ucred *, struct proc *);
+int vn_open(struct nameidata *, int, int);
+int vn_rdwr(enum uio_rw, struct vnode *, caddr_t, int, off_t,
+ enum uio_seg, int, struct ucred *, size_t *, struct proc *);
+int vn_stat(struct vnode *, struct stat *, struct proc *);
+int vn_statfile(struct file *, struct stat *, struct proc *);
+int vn_lock(struct vnode *, int);
+int vn_writechk(struct vnode *);
+int vn_fsizechk(struct vnode *, struct uio *, int, ssize_t *);
+int vn_ioctl(struct file *, u_long, caddr_t, struct proc *);
+void vn_marktext(struct vnode *);
+
+/* vfs_sync.c */
+void syncer_thread(void *);
+void vn_initialize_syncerd(void);
+void vn_syncer_add_to_worklist(struct vnode *, int);
+
+/* misc */
+int vn_isdisk(struct vnode *, int *);
+int softdep_fsync(struct vnode *);
+int getvnode(struct proc *, int, struct file **);
+
+/* uvm */
+void uvm_vnp_setsize(struct vnode *, off_t);
+void uvm_vnp_sync(struct mount *);
+void uvm_vnp_terminate(struct vnode *);
+int uvm_vnp_uncache(struct vnode *);
+
+
+#endif /* _KERNEL */
+#endif /* _SYS_VNODE_H_ */
diff --git a/sys/sys/wait.h b/sys/sys/wait.h
new file mode 100644
index 0000000..0e85f40
--- /dev/null
+++ b/sys/sys/wait.h
@@ -0,0 +1,103 @@
+/* $OpenBSD: wait.h,v 1.17 2014/06/13 22:40:31 matthew Exp $ */
+/* $NetBSD: wait.h,v 1.11 1996/04/09 20:55:51 cgd Exp $ */
+
+/*
+ * Copyright (c) 1982, 1986, 1989, 1993, 1994
+ * 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.
+ *
+ * @(#)wait.h 8.2 (Berkeley) 7/10/94
+ */
+
+#ifndef _SYS_WAIT_H_
+#define _SYS_WAIT_H_
+
+#include <sys/cdefs.h>
+
+/*
+ * This file holds definitions relevent to the wait4 system call
+ * and the alternate interfaces that use it (wait, wait3, waitpid).
+ */
+
+/*
+ * Macros to test the exit status returned by wait
+ * and extract the relevant values.
+ */
+#define _WSTATUS(x) ((x) & 0177)
+#define _WSTOPPED 0177 /* _WSTATUS if process is stopped */
+#define _WCONTINUED 0177777 /* process has continued */
+#define WIFSTOPPED(x) (((x) & 0xff) == _WSTOPPED)
+#define WSTOPSIG(x) (int)(((unsigned)(x) >> 8) & 0xff)
+#define WIFSIGNALED(x) (_WSTATUS(x) != _WSTOPPED && _WSTATUS(x) != 0)
+#define WTERMSIG(x) (_WSTATUS(x))
+#define WIFEXITED(x) (_WSTATUS(x) == 0)
+#define WEXITSTATUS(x) (int)(((unsigned)(x) >> 8) & 0xff)
+#define WIFCONTINUED(x) (((x) & _WCONTINUED) == _WCONTINUED)
+#if __XPG_VISIBLE
+#define WCOREFLAG 0200
+#define WCOREDUMP(x) ((x) & WCOREFLAG)
+
+#define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
+#define W_STOPCODE(sig) ((sig) << 8 | _WSTOPPED)
+#endif
+
+/*
+ * Option bits for the third argument of wait4. WNOHANG causes the
+ * wait to not hang if there are no stopped or terminated processes, rather
+ * returning an error indication in this case (pid==0). WUNTRACED
+ * indicates that the caller should receive status about untraced children
+ * which stop due to signals. If children are stopped and a wait without
+ * this option is done, it is as though they were still running... nothing
+ * about them is returned.
+ */
+#define WNOHANG 1 /* don't hang in wait */
+#define WUNTRACED 2 /* tell about stopped, untraced children */
+#define WCONTINUED 8 /* report a job control continued process */
+
+#if __BSD_VISIBLE
+/*
+ * Tokens for special values of the "pid" parameter to wait4.
+ */
+#define WAIT_ANY (-1) /* any process */
+#define WAIT_MYPGRP 0 /* any process in my process group */
+#endif /* __BSD_VISIBLE */
+
+#ifndef _KERNEL
+#include <sys/types.h>
+
+__BEGIN_DECLS
+struct rusage; /* forward declaration */
+
+pid_t wait(int *);
+pid_t waitpid(pid_t, int *, int);
+#if __BSD_VISIBLE
+pid_t wait3(int *, int, struct rusage *);
+pid_t wait4(pid_t, int *, int, struct rusage *);
+#endif /* __BSD_VISIBLE */
+__END_DECLS
+#endif /* !_KERNEL */
+
+#endif /* !_SYS_WAIT_H_ */
diff --git a/sys/sys/witness.h b/sys/sys/witness.h
new file mode 100644
index 0000000..c7d318b
--- /dev/null
+++ b/sys/sys/witness.h
@@ -0,0 +1,156 @@
+/* $OpenBSD: witness.h,v 1.5 2019/04/23 13:35:12 visa Exp $ */
+
+/*-
+ * Copyright (c) 1997 Berkeley Software Design, 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.
+ * 3. Berkeley Software Design Inc's name may not be used to endorse or
+ * promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN 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 BERKELEY SOFTWARE DESIGN INC 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 BSDI Id: mutex.h,v 2.7.2.35 2000/04/27 03:10:26 cp
+ * $FreeBSD: head/sys/sys/lock.h 313908 2017-02-18 01:52:10Z mjg $
+ */
+
+#ifndef _SYS_WITNESS_H_
+#define _SYS_WITNESS_H_
+
+#include <sys/_lock.h>
+
+/*
+ * Lock classes are statically assigned an index into the global lock_classes
+ * array. Debugging code looks up the lock class for a given lock object
+ * by indexing the array.
+ */
+#define LO_CLASSINDEX(lock) \
+ ((((lock)->lo_flags) & LO_CLASSMASK) >> LO_CLASSSHIFT)
+#define LOCK_CLASS(lock) \
+ (lock_classes[LO_CLASSINDEX((lock))])
+#define LOCK_CLASS_MAX \
+ (LO_CLASSMASK >> LO_CLASSSHIFT)
+
+/*
+ * Option flags passed to lock operations that witness also needs to know
+ * about or that are generic across all locks.
+ */
+#define LOP_NEWORDER 0x00000001 /* Define a new lock order. */
+#define LOP_QUIET 0x00000002 /* Don't log locking operations. */
+#define LOP_TRYLOCK 0x00000004 /* Don't check lock order. */
+#define LOP_EXCLUSIVE 0x00000008 /* Exclusive lock. */
+#define LOP_DUPOK 0x00000010 /* Don't check for duplicate acquires */
+
+/* Flags passed to witness_assert. */
+#define LA_MASKASSERT 0x000000ff /* Mask for witness defined asserts. */
+#define LA_UNLOCKED 0x00000000 /* Lock is unlocked. */
+#define LA_LOCKED 0x00000001 /* Lock is at least share locked. */
+#define LA_SLOCKED 0x00000002 /* Lock is exactly share locked. */
+#define LA_XLOCKED 0x00000004 /* Lock is exclusively locked. */
+#define LA_RECURSED 0x00000008 /* Lock is recursed. */
+#define LA_NOTRECURSED 0x00000010 /* Lock is not recursed. */
+
+#ifdef _KERNEL
+
+void witness_initialize(void);
+void witness_init(struct lock_object *, const struct lock_type *);
+int witness_defineorder(struct lock_object *, struct lock_object *);
+void witness_checkorder(struct lock_object *, int, struct lock_object *);
+void witness_lock(struct lock_object *, int);
+void witness_upgrade(struct lock_object *, int);
+void witness_downgrade(struct lock_object *, int);
+void witness_unlock(struct lock_object *, int);
+int witness_warn(int, struct lock_object *, const char *, ...);
+void witness_assert(const struct lock_object *, int);
+void witness_display_spinlock(struct lock_object *, struct proc *,
+ int (*)(const char *, ...));
+int witness_line(struct lock_object *);
+void witness_norelease(struct lock_object *);
+void witness_releaseok(struct lock_object *);
+const char *witness_file(struct lock_object *);
+void witness_thread_exit(struct proc *);
+int witness_sysctl(int *, u_int, void *, size_t *, void *, size_t);
+int witness_sysctl_watch(void *, size_t *, void *, size_t);
+
+#ifdef WITNESS
+
+/* Flags for witness_warn(). */
+#define WARN_KERNELOK 0x01 /* Kernel lock is exempt from this check. */
+#define WARN_PANIC 0x02 /* Panic if check fails. */
+#define WARN_SLEEPOK 0x04 /* Sleepable locks are exempt from check. */
+
+#define WITNESS_INITIALIZE() \
+ witness_initialize()
+
+#define WITNESS_INIT(lock, type) \
+ witness_init((lock), (type))
+
+#define WITNESS_CHECKORDER(lock, flags, interlock) \
+ witness_checkorder((lock), (flags), (interlock))
+
+#define WITNESS_DEFINEORDER(lock1, lock2) \
+ witness_defineorder((struct lock_object *)(lock1), \
+ (struct lock_object *)(lock2))
+
+#define WITNESS_LOCK(lock, flags) \
+ witness_lock((lock), (flags))
+
+#define WITNESS_UPGRADE(lock, flags) \
+ witness_upgrade((lock), (flags))
+
+#define WITNESS_DOWNGRADE(lock, flags) \
+ witness_downgrade((lock), (flags))
+
+#define WITNESS_UNLOCK(lock, flags) \
+ witness_unlock((lock), (flags))
+
+#define WITNESS_CHECK(flags, lock, fmt, ...) \
+ witness_warn((flags), (lock), (fmt), ## __VA_ARGS__)
+
+#define WITNESS_WARN(flags, lock, fmt, ...) \
+ witness_warn((flags), (lock), (fmt), ## __VA_ARGS__)
+
+#define WITNESS_NORELEASE(lock) \
+ witness_norelease(&(lock)->lock_object)
+
+#define WITNESS_RELEASEOK(lock) \
+ witness_releaseok(&(lock)->lock_object)
+
+#define WITNESS_THREAD_EXIT(p) \
+ witness_thread_exit((p))
+
+#else /* WITNESS */
+#define WITNESS_INITIALIZE() (void)0
+#define WITNESS_INIT(lock, type) (void)0
+#define WITNESS_DEFINEORDER(lock1, lock2) 0
+#define WITNESS_CHECKORDER(lock, flagsi, interlock) (void)0
+#define WITNESS_LOCK(lock, flags) (void)0
+#define WITNESS_UPGRADE(lock, flags) (void)0
+#define WITNESS_DOWNGRADE(lock, flags) (void)0
+#define WITNESS_UNLOCK(lock, flags) (void)0
+#define WITNESS_CHECK(flags, lock, fmt, ...) 0
+#define WITNESS_WARN(flags, lock, fmt, ...) (void)0
+#define WITNESS_NORELEASE(lock) (void)0
+#define WITNESS_RELEASEOK(lock) (void)0
+#define WITNESS_THREAD_EXIT(p) (void)0
+#endif /* WITNESS */
+
+#endif /* _KERNEL */
+#endif /* _SYS_WITNESS_H_ */